-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathso_func_instr_tracer.js
68 lines (59 loc) · 2.3 KB
/
so_func_instr_tracer.js
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
function getModuleByAddressSafe(address) {
try {
// 尝试获取模块
var module = Process.getModuleByAddress(address);
// 如果模块存在,返回模块
if (module) {
return module;
} else {
// 如果没有找到模块,返回 null
return null;
}
} catch (e) {
// 捕获异常,返回 null
return null;
}
}
function main(soName, offset) {
var baseAddress = Module.findBaseAddress(soName);
var targetAddr = baseAddress.add(offset);
Interceptor.attach(targetAddr, {
onEnter: function (args) {
console.log(`Entering function at: ${targetAddr}`);
Stalker.follow(Process.getCurrentThreadId(), {
events: {
exec: true
},
onReceive: function (events) {
var parsedEvents = Stalker.parse(events);
parsedEvents.forEach(event => {
if (event[0] === 'exec') {
const address = ptr(event[1]);
const instruction = Instruction.parse(address);
const module = getModuleByAddressSafe(address);
const offset = module ? address.sub(module.base) : null;
// 判断地址是否属于目标 so
if (module && module.name === soName) {
if (module) {
const logMessage = `${address} | ${module.name} + 0x${offset.toString(16)} | ${instruction}`;
console.log(logMessage)
} else {
const logMessage = `${address} | Unknown | ${instruction}`;
console.log(logMessage)
}
}
}
});
}
});
},
onLeave: function (retval) {
console.log("Leaving function");
Stalker.unfollow(Process.getCurrentThreadId());
}
});
}
setImmediate(function () {
main("libnative-lib.so", 0x26058)
});
// frida -H 127.0.0.1:1234 -F -l so_func_instr_tracer.js