frida调试工具构建

依赖

  1. 环境
  • frida: 15.0.2
  • node
  • vscode
  • root iphone
  1. 原理
    通过frida-compileTypeScript编译成js代码。可实现ts,js混写,文件内容更改,即时内存注入。

开始

  1. 初始化
mkdir fridatool && cd fridatool
mkdir dist src
# 初始化NPM
npm init -y

package.json介绍

package.json如下:

{
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "frida-compile src/index.ts -o dist/index.js -c",
    "watch": "frida-compile src/index.ts -o dist/index.js -w",
    "hook": "frida -U appName --debug --runtime=v8 --no-pause -l ./dist/index.js"
  },
  "devDependencies": {
    "@types/frida-gum": "^16.2.0",
    "@types/node": "^14.14.10",
    "frida-compile": "^10.0.0"
  }
}
  1. 安装TypeScript
npm install -g typescript
tsc --init

tsconfig.json介绍

修改tsconfig.json

"outDir": "./dist",
"rootDir": "./src",
  1. 依次建文件
tree #结构如下
.
├── dist
│   └── index.js
├── package-lock.json
├── package.json
├── src
│   ├── common
│   │   └── hooktools.js
│   ├── index.ts
│   ├── main.js
│   └── test
│       └── hooktest1.js
└── tsconfig.json
  1. 写代码
// index.ts
require("./main.js"); 
// main.js
require("./test/hooktest1")
/// hooktest.js
var tool = require("../common/hooktools")
console.log("begin");
tool.hook_ocMethod("-[CLLocation *]", args => { }, retval => { })
  1. npm install后运行,可以在vscode中package.json直接点
npm run watch
npm run hook

后记

  1. 配置完成后,每次修改文件都会重新运行,并进行hook。
  2. ts,js可混写。
  3. chrome DelTools附加调试。找开chrome://inspect下断即可,可按左下角{}按钮进行格式化。
  4. 利用webpack,可不用ts。