在Linux下使用intel Pin ,并编译自己的pintools

Intel Pin

下载linux版。
我下载的是Pin3.13
在这里插入图片描述

准备pintools代码

这里使用选择指令攻击的其中一个代码做展示。

准备make文件

  1. 先解压IntelPin

    $ tar -zxvf pin-3.13-98189-g60a6ef199-gcc-linux.tar.gz
    
  2. pin-3.13-98189-g60a6ef199-gcc-linux/source/tools/Config目录下的makefile.rules.tmplmakefile.tmpl拷贝到CIA-toolchain/pintools目录下。并重命名为makefile.rules和makefile。

  3. 修改CIA-toolchain/pintools/makefile
    增添一行PIN_ROOT := <Intel Pin的路径>

    ##############################################################
    #
    #                   DO NOT EDIT THIS FILE!
    #
    ##############################################################
    
    # If the tool is built out of the kit, PIN_ROOT must be specified in the make invocation and point to the kit root.
    PIN_ROOT :=/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux
    ifdef PIN_ROOT
    CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config
    else
    CONFIG_ROOT := ../Config
    endif
    include $(CONFIG_ROOT)/makefile.config
    include makefile.rules
    include $(TOOLS_ROOT)/Config/makefile.default.rules
    
    ##############################################################
    #
    #                   DO NOT EDIT THIS FILE!
    #
    ##############################################################
    
    
  4. 修改CIA-toolchain/pintools/makefile.rules
    在 TEST_TOOL_ROOTS := 后写需要编译的pintool代码的名字。这里我选择编译instracelog.cpp,所以这里填instracelog。
    再添加编译规则。

    ...
    ###### Place all generic definitions here ######
    
    # This defines tests which run tools of the same name.  This is simply for convenience to avoid
    # defining the test name twice (once in TOOL_ROOTS and again in TEST_ROOTS).
    # Tests defined here should not be defined in TOOL_ROOTS and TEST_ROOTS.
    TEST_TOOL_ROOTS := instracelog
    ...
    	
    ###### Special tools' build rules ######
    $(OBJDIR)instracelog$(PINTOOL_SUFFIX): $(OBJDIR)instracelog$(OBJ_SUFFIX) $(CONTROLLERLIB)
    	$(LINKER) $(TOOL_LDFLAGS) $(LINK_EXE)$@ $^ $(TOOL_LPATHS) $(TOOL_LIBS)
    ...
    
  5. 修改pin-3.13-98189-g60a6ef199-gcc-linux/source/tools/Config/makefile.unix.config,将-Wall 和 -Werror删除。否则会将警告当成错误导致编译不过去。

    ...
    #TOOL_CXXFLAGS_NOOPT := -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1
    TOOL_CXXFLAGS_NOOPT := -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1
    ...
    

编译

回到CIA-toolchain/pintools目录下。
执行:

$ make all TARGET=intel64

一般都没什么问题。会有一些警告,不用理会。Linux上需要安装gcc。我使用的环境是wsl20.04. gcc 版本是9.4.0。

make objects
make[1]: Entering directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make[1]: Nothing to be done for 'objects'.
make[1]: Leaving directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make libs
make[1]: Entering directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make[1]: Nothing to be done for 'libs'.
make[1]: Leaving directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make dlls
make[1]: Entering directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make[1]: Nothing to be done for 'dlls'.
make[1]: Leaving directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make apps
make[1]: Entering directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make[1]: Nothing to be done for 'apps'.
make[1]: Leaving directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
make tools
make[1]: Entering directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'
g++ -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fasynchronous-unwind-tables -fno-rtti -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX -fabi-version=2 -faligned-new  -I/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/source/include/pin -I/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/source/include/pin/gen -isystem /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/stlport/include -isystem /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/libstdc++/include -isystem /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/crt/include -isystem /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/crt/include/arch-x86_64 -isystem /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/crt/include/kernel/uapi -isystem /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/crt/include/kernel/uapi/asm-x86 -I/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/components/include -I/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/xed-intel64/include/xed -I/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/source/tools/Utils -I/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing   -c -o obj-intel64/instracelog.o instracelog.cpp
instracelog.cpp: In function ‘void getctx(ADDRINT, ADDRINT, LEVEL_VM::CONTEXT*, ADDRINT, ADDRINT)’:
instracelog.cpp:98:21: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                    ~^                                                                           ~~~~
      |                     |                                                                           |
      |                     unsigned int                                                                ADDRINT {aka long unsigned int}
      |                    %lx
instracelog.cpp:98:25: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 4 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                        ~^                                                                             ~~~~~~~
      |                         |                                                                             |
      |                         unsigned int                                                                  ADDRINT {aka long unsigned int}
      |                        %lu
instracelog.cpp:98:31: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 5 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                              ~^
      |                               |
      |                               unsigned int
      |                              %lx
   99 |             PIN_GetContextReg(fromctx, REG_EAX),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:37: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 6 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                    ~^
      |                                     |
      |                                     unsigned int
      |                                    %lx
   99 |             PIN_GetContextReg(fromctx, REG_EAX),
  100 |             PIN_GetContextReg(fromctx, REG_EBX),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:43: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 7 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                          ~^
      |                                           |
      |                                           unsigned int
      |                                          %lx
......
  101 |             PIN_GetContextReg(fromctx, REG_ECX),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:49: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 8 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                ~^
      |                                                 |
      |                                                 unsigned int
      |                                                %lx
......
  102 |             PIN_GetContextReg(fromctx, REG_EDX),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:55: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 9 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                      ~^
      |                                                       |
      |                                                       unsigned int
      |                                                      %lx
......
  103 |             PIN_GetContextReg(fromctx, REG_ESI),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:61: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 10 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                            ~^
      |                                                             |
      |                                                             unsigned int
      |                                                            %lx
......
  104 |             PIN_GetContextReg(fromctx, REG_EDI),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~              
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:67: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 11 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                                  ~^
      |                                                                   |
      |                                                                   unsigned int
      |                                                                  %lx
......
  105 |             PIN_GetContextReg(fromctx, REG_ESP),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                    
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:73: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 12 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                                        ~^
      |                                                                         |
      |                                                                         unsigned int
      |                                                                        %lx
......
  106 |             PIN_GetContextReg(fromctx, REG_EBP),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                          
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:79: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 13 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                                              ~^
      |                                                                               |
      |                                                                               unsigned int
      |                                                                              %lx
......
  107 |             PIN_GetContextReg(fromctx, REG_EFLAGS),
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                             
      |                              |
      |                              ADDRINT {aka long unsigned int}
instracelog.cpp:98:85: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 14 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                                                    ~^
      |                                                                                     |
      |                                                                                     unsigned int
      |                                                                                    %lx
......
  108 |             raddr, waddr);
      |             ~~~~~                                                                    
      |             |
      |             ADDRINT {aka long unsigned int}
instracelog.cpp:98:91: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 15 has type ‘ADDRINT’ {aka ‘long unsigned int’} [-Wformat=]
   98 |     fprintf(fp, "0x%x; %u; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; 0x%x; ", addr, inssize,
      |                                                                                          ~^
      |                                                                                           |
      |                                                                                           unsigned int
      |                                                                                          %lx
......
  108 |             raddr, waddr);
      |                    ~~~~~                                                                   
      |                    |
      |                    ADDRINT {aka long unsigned int}
g++ -shared -Wl,--hash-style=sysv /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/intel64/runtime/pincrt/crtbeginS.o -Wl,-Bsymbolic -Wl,--version-script=/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/source/include/pin/pintool.ver -fabi-version=2    -o obj-intel64/instracelog.so obj-intel64/instracelog.o /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/source/tools/InstLib/obj-intel64/controller.a  -L/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/intel64/runtime/pincrt -L/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/intel64/lib -L/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/intel64/lib-ext -L/home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/extras/xed-intel64/lib -lpin -lxed /home/nisl812/download/pin-3.13-98189-g60a6ef199-gcc-linux/intel64/runtime/pincrt/crtendS.o -lpin3dwarf  -ldl-dynamic -nostdlib -lstlport-dynamic -lm-dynamic -lc-dynamic -lunwind-dynamic
make[1]: Leaving directory '/home/nisl812/project/CIA/CIA-toolchain/pintools'

输出的.so文件在CIA-toolchain/pintools/obj-intel64目录下。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值