forked from lidongyooo/GumTrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_ios.js
More file actions
82 lines (63 loc) · 2.32 KB
/
Copy pathexample_ios.js
File metadata and controls
82 lines (63 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
let traceSoName = 'libGumTrace.dylib'
let targetSo = 'libtarget.dylib'
let gumtrace_init = null
let gumtrace_run = null
let gumtrace_unrun = null
function loadGumTrace() {
let dlopen = new NativeFunction(Module.findGlobalExportByName('dlopen'), 'pointer', ['pointer', 'int'])
let dlsym = new NativeFunction(Module.findGlobalExportByName('dlsym'), 'pointer', ['pointer', 'pointer'])
let soHandle = dlopen(Memory.allocUtf8String('/var/jb/var/root/' + traceSoName), 2)
console.log('GumTrace loaded:', soHandle)
gumtrace_init = new NativeFunction(dlsym(soHandle, Memory.allocUtf8String('init')), 'void', ['pointer', 'pointer', 'int', 'pointer'])
gumtrace_run = new NativeFunction(dlsym(soHandle, Memory.allocUtf8String('run')), 'void', [])
gumtrace_unrun = new NativeFunction(dlsym(soHandle, Memory.allocUtf8String('unrun')), 'void', [])
}
function getSandboxPath(filename) {
try {
const homePath = ObjC.classes.NSString.stringWithString_("~").stringByExpandingTildeInPath().toString();
console.log('trace file:', homePath + '/Documents/' + filename);
return homePath + '/Documents/' + filename;
} catch (e) {
console.log('获取沙盒路径失败:', e);
return '/tmp/' + filename
}
}
function startTrace() {
loadGumTrace()
let moduleNames = Memory.allocUtf8String(targetSo)
let outputPath = Memory.allocUtf8String(getSandboxPath('trace.log'))
let threadId = 0 // 0 = 当前线程
let options = Memory.alloc(8)
// 0 = Stand 模式
// 1 = DEBUG 模式
// 2 = Stable 模式
options.writeU64(0)
console.log('start trace')
gumtrace_init(moduleNames, outputPath, threadId, options)
gumtrace_run()
}
function stopTrace() {
console.log('stop trace')
gumtrace_unrun()
}
// Warning: All apis from Frida 17
let isTrace = false
function hook() {
// 示例:hook 目标函数,在其执行期间进行追踪
let targetModule = Process.findModuleByName(targetSo)
Interceptor.attach(targetModule.base.add(0x1234), {
onEnter() {
if (isTrace === false) {
isTrace = true
startTrace()
this.tracing = true
}
},
onLeave() {
if (this.tracing) {
stopTrace()
}
}
})
}
setImmediate(hook)