其他分享
首页 > 其他分享> > VScode+docker创建一个Pin的开发环境

VScode+docker创建一个Pin的开发环境

作者:互联网

VScode+docker创建一个Pin的开发环境

由于我一直用Mac,但是一般用Pin都是在Linux下和Windows下,Windows下自然是很方便,直接VS打开,开发时不要太舒服。但是开发Linux时,我一直都是采用docker+挂载文件夹的方式进行同步开发,没补全,还得每次输指令,怪麻烦的。

工具

流程

  1. 下载vscode插件,准备镜像开容器
    我这里用pwndocker挂载文件夹的方式

    docker run -d \
        --rm \
        -h ctf \
        --name ctf \
        -v /CTF-0v0:/ctf/work \
        -p 23946:23946 \
        --cap-add=SYS_PTRACE \
        skysider/pwndocker
    
  2. 用插件 Attach to Running Container 选中你的容器

  3. 然后选择工作区即可,我这里选择Pin自带的MyPinTool文件夹作为工作区,等一会vscode自己进行初始化,就可以看到工作区文件夹了。

    初始是没有.vscode那个文件夹,我这边因为已经弄过了,上图只是参考。

  4. 我这边把MyPinTool拷贝出来一个副本叫做MyPinTool64,一个作为32位开发工作区一个作为64位开发工作区

  5. 接下来就是配置.vscode的配置文件了,这里主要配置两个文件,第一个是c_cpp_properties.json第二个是task.json文件。

    • 第一个c_cpp_properties主要是设置includePath和Define,Pin的头文件还是挺多的,我是观察在linux下make生成Pintool的时候,会有-I 包含头文件,Define也是观察命令行下的make得到。
      配置文件供参考x86_64

      {
          "configurations": [
              {
                  "name": "Linux",
                  "includePath": [
                      "${workspaceFolder}/**",
                      "../../include/pin",
                      "../../include/pin/gen",
                      "../InstLib",
                      "../../../extras/xed-intel64/include/xed",
                      "../../../extras/components/include",
                      "../../../extras/stlport/include",
                      "../../../extras",
                      "../../../extras/libstdc++/include",
                      "../../../extras/crt/include",
                      "../../../extras/crt",
                      "../../../extras/crt/include/arch-x86_64",
                      "../../../extras/crt/include/kernel/uapi",
                      "../../../extras/crt/include/kernel/uapi/asm-x86"
                  ],
                  "defines": [
                      "TARGET_IA32E", 
                      "HOST_IA32E", 
                      "TARGET_LINUX", 
                      "__PIN__=1", 
                      "PIN_CRT=1"
                  ],
                  "macFrameworkPath": [],
                  "compilerPath": "/usr/bin/g++",
                  "cStandard": "${default}",
                  "cppStandard": "${default}",
                  "intelliSenseMode": "${default}"
              }
          ],
          "version": 4
      }
      

      x86

      {
          "configurations": [
              {
                  "name": "Linux",
                  "includePath": [
                      "${workspaceFolder}/**",
                      "../../include/pin",
                      "../../include/pin/gen",
                      "../InstLib",
                      "../../../extras/xed-ia32/include/xed",
                      "../../../extras/components/include",
                      "../../../extras/stlport/include",
                      "../../../extras",
                      "../../../extras/libstdc++/include",
                      "../../../extras/crt/include",
                      "../../../extras/crt",
                      "../../../extras/crt/include/arch-x86",
                      "../../../extras/crt/include/kernel/uapi",
                      "../../../extras/crt/include/kernel/uapi/asm-x86"
                  ],
                  "defines": [
                      "TARGET_IA32", 
                      "HOST_IA32", 
                      "TARGET_LINUX", 
                      "__PIN__=1", 
                      "PIN_CRT=1"
                  ],
                  "macFrameworkPath": [],
                  "compilerPath": "/usr/bin/g++",
                  "cStandard": "${default}",
                  "cppStandard": "${default}",
                  "intelliSenseMode": "${default}"
              }
          ],
          "version": 4
      }
      
    • 第二个是task.json,我这里配置了两个任务,一个是编译,一个是插桩运行,这里没有配置launch文件的原因是觉得多此一举了,没有必要弄调试那些,Pin本来就是算是在调试原程序,关于Pintool的调试,打log工具不用打log调试?(滑稽)这里主要是插桩运行地方,开始尝试了vscode三种设置参数的方式去选择运行的程序,但是我觉得还不如直接改配置来的快速,也就没有配置参数传入方式。
      文件供参考x86_64

      {
          // See https://go.microsoft.com/fwlink/?LinkId=733558
          // for the documentation about the tasks.json format
          "version": "2.0.0",
          "tasks": [
              {
                  "label": "make",
                  "type": "shell",
                  "command": "make obj-intel64/MyPinTool.so TARGET=intel64 ",
                  "problemMatcher": [],
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  }
              },
              {
                  "label": "run",
                  "type": "shell",
                  "command": "../../../pin -t obj-intel64/MyPinTool.so -- ./xxxx",
                  "problemMatcher": [],
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  }
              }
          ]
      }
      

      x86

      {
          // See https://go.microsoft.com/fwlink/?LinkId=733558
          // for the documentation about the tasks.json format
          "version": "2.0.0",
          "tasks": [
              {
                  "label": "make",
                  "type": "shell",
                  "command": "make obj-ia32/MyPinTool.so TARGET=ia32 ",
                  "problemMatcher": [],
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  }
              },
              {
                  "label": "run",
                  "type": "shell",
                  "command": "../../../pin -t obj-intel64/MyPinTool.so -- ./flow",
                  "problemMatcher": [],
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  }
              }
          ]
      }
      
    • 然后就可以快乐的运行了commend + shift + B快乐运行

  6. 配置的感觉挺简陋的,不过有代码补全和纠错,还能一键运行,可以满足大多数要求了

后记

这是第一次用vscode,配置的略简陋。

标签:Pin,..,VScode,vscode,extras,docker,include,crt,x86
来源: https://www.cnblogs.com/wxcwxc/p/13931175.html