安装和使用 Intel PIn

14 篇文章 0 订阅
转载自https://blog.csdn.net/fuxingwe/article/details/10176027

一、  安装

在官网http://www.pintool.org/下载压缩包然后解压就行了

Building the Example Tools for Linux

To build allexamples in a directory:

$ cd source/tools/ManualExamples
$ make all

To build and run a specific example (e.g., inscount0):

$ cd source/tools/ManualExamples
$ make inscount0.test

To build a specific example without running it (e.g., inscount0):

$ cd source/tools/ManualExamples
$ make obj-intel64/inscount0.so

The above applies to the Intel(R) 64 architecture. For the IA-32architecture, use “obj-ia32” instead of “obj-intel64”:

$ cd source/tools/ManualExamples
$ make obj-ia32/inscount0.so

二、在windows上安装并运行一个例子

1.     之前的Pin版本中,支持通过MicrosoftVisual Studio 2010的命令行运行nmake之类的批处理命令,从Pin 2.12版本开始,需要基于cygwin make来进行编译

2.     Cygwin安装的时候,默认不安装make工具,所以在安装Cygwin时要选择安装make工具

3.     安装好Cygwin之后,将其安装目录下的bin目录,如“D:\cygwin\bin”加入到环境变量path中(最好加在其他所有变量之前,这样保证可以先用Cygwin进行解析),之后就可以直接在cmd中使用Cygwin的命令。例如:tar, ls, grep,make等

4.     下载的Pin是个压缩包,解压即可。将Pin解压后的文件夹的位置(pin.exe上面一层文件夹)加入到path中,即可在命令行中使用Pin命令。

5.     进入到source/tools/ManualExamples中,用make命令(同linux)可以编译所有例子。编译好后进入对应的32位或64位平台的文件夹中可以看到生成文件,windows下大多数生成的都是dll文件。然后使用pin命令pin -t itrace.dll –“test.exe”即可运行itrace这个例子对test.exe(是自己编的一个exe放到相同目录下了,如果在其他地方要用完整的路径)进行分析,这个例子是会输出所有的test.exe的指令的地址到文件itrace.out中。运行完后可以查看该文件。

该例子代码是source/tools/ManualExamples/itrace.cpp:

  1. #include <stdio.h>  
  2. #include “pin.H”  
  3. FILE  trace;  
  4.   
  5. // This function is called before every instruction is executed  
  6. // and prints the IP  
  7. VOID printip(VOID *ip) { fprintf(trace, “%p\n”, ip); }  
  8.   
  9. // Pin calls this function every time a new instruction is encountered  
  10. VOID Instruction(INS ins, VOID *v)  
  11. {  
  12.     // Insert a call to printip before every instruction, and pass it the IP  
  13.     INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_INST_PTR, IARG_END);  
  14. }  
  15.   
  16. // This function is called when the application exits  
  17. VOID Fini(INT32 code, VOID *v)  
  18. {  
  19.     fprintf(trace, ”#eof\n”);  
  20.     fclose(trace);  
  21. }  
  22.   
  23. /*Print Help Message /  
  24.   
  25. INT32 Usage()  
  26. {  
  27.     PIN_ERROR(”This Pintool prints the IPs of every instruction executed\n” + KNOB_BASE::StringKnobSummary() + “\n”);  
  28.     return -1;  
  29. }  
  30.   
  31. int main(int argc, char * argv[])  
  32. {  
  33.     trace = fopen(”itrace.out”“w”);  
  34.       
  35.     // Initialize pin  
  36.     if (PIN_Init(argc, argv)) return Usage();  
  37.   
  38.     // Register Instruction to be called to instrument instructions  
  39.     INS_AddInstrumentFunction(Instruction, 0);  
  40.   
  41.     // Register Fini to be called when the application exits  
  42.     PIN_AddFiniFunction(Fini, 0);  
  43.       
  44.     // Start the program, never returns  
  45.     PIN_StartProgram();  
  46.       
  47.     return 0;  
  48. }  
#include <stdio.h>

include "pin.H"

FILE * trace;

// This function is called before every instruction is executed
// and prints the IP
VOID printip(VOID *ip) { fprintf(trace, "%p\n", ip); }

// Pin calls this function every time a new instruction is encountered
VOID Instruction(INS ins, VOID *v)
{
// Insert a call to printip before every instruction, and pass it the IP
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_INST_PTR, IARG_END);
}

// This function is called when the application exits
VOID Fini(INT32 code, VOID *v)
{
fprintf(trace, "#eof\n");
fclose(trace);
}

/Print Help Message /

INT32 Usage()
{
PIN_ERROR("This Pintool prints the IPs of every instruction executed\n" + KNOB_BASE::StringKnobSummary() + "\n");
return -1;
}

int main(int argc, char * argv[])
{
trace = fopen("itrace.out", "w");

// Initialize pin
if (PIN_Init(argc, argv)) return Usage();

// Register Instruction to be called to instrument instructions
INS_AddInstrumentFunction(Instruction, 0);

// Register Fini to be called when the application exits
PIN_AddFiniFunction(Fini, 0);

// Start the program, never returns
PIN_StartProgram();

return 0;

}

生成的结果文件:




    <div class="article-bar-bottom">
                    <div class="tags-box artic-tag-box">
        <span class="label">文章标签:</span>
                    <a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=Pin&amp;t=blog" target="_blank">Pin                       </a><a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=Intel&amp;t=blog" target="_blank">Intel                       </a><a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=A Dynamic Binary Ins&amp;t=blog" target="_blank">A Dynamic Binary Ins                     </a><a class="tag-link" href="http://so.csdn.net/so/search/s.do?q=安装&amp;t=blog" target="_blank">安装                     </a>
    </div>
                    <div class="tags-box">
        <span class="label">个人分类:</span>
                    <a class="tag-link" href="https://blog.csdn.net/fuxingwe/article/category/1378888" target="_blank">c++                      </a><a class="tag-link" href="https://blog.csdn.net/fuxingwe/article/category/1580727" target="_blank">Pin                      </a>
    </div>
                </div>

<!-- !empty($pre_next_article[0]) -->
    </div>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值