-
Notifications
You must be signed in to change notification settings - Fork 10
/
params_process_hook.js
112 lines (106 loc) · 3.51 KB
/
params_process_hook.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
String.prototype.format = function () {
var values = arguments;
return this.replace(/\{(\d+)\}/g, function (match, index) {
if (values.length > index) {
return values[index];
} else {
return "";
}
});
}
// Memory.readUtf8String
var mru8s = function(addr) {return Memory.readUtf8String(addr)}
// Memory.readPointer
var mrp = function(addr) {return Memory.readPointer(addr)}
// Memory.allocUtf8String
var mau8s = function(addr) {return Memory.allocUtf8String(addr)}
// read process memory
var rpm = function(addr, size) {
var buf = Memory.readByteArray(ptr('0x' + addr), size);
console.log(hexdump(buf, {
offset: 0,
length: size,
header: true,
ansi: false
}));
}
var getAddr = function(fa) { // fa是要获取的方法的地址
var JNI_OnLoad;
var exports = Module.enumerateExportsSync("libuserinfo.so");
for (var i = 0; i < exports.length; i++) {
var name = exports[i].name;
var addr = exports[i].address;
if (name == 'JNI_OnLoad') {
JNI_OnLoad = addr;
}
}
var BASE_ADDR = parseInt(JNI_OnLoad) - parseInt("0x14504");
var addr = '0x' + parseInt(BASE_ADDR + parseInt(fa)).toString(16);
return addr;
}
var sout = function(msg, color) {
if (color instanceof Number) {
console.log(msg);
} else {
switch (color) {
default:
case 'b':
msg = '\x1b[38;01m' + msg + '\x1b[0m';
break;
case 'hei':
msg = '\x1b[30;01m' + msg + '\x1b[0m';
break;
case 'lv':
msg = '\x1b[32;01m' + msg + '\x1b[0m';
break;
case 'h':
msg = '\x1b[31;01m' + msg + '\x1b[0m';
break;
}
console.log(msg);
}
}
//==================================================================
//
const STALKED = 12345;
var threads = [];
var count = 0;
Interceptor.attach(new NativePointer(getAddr("0x3F36C")), {
onEnter: function(args) {
count ++;
sout('=============== ' + count + ' ===============', 'h');
// console.log('参数1 > ', args[0]);
// console.log('参数2 > ', mru8s(mrp(args[1])));
// var trace = Thread.backtrace(this.context, Backtracer.ACCURATE).map(DebugSymbol.fromAddress);
// for (var j in trace)
// console.log(trace[j], '\n');
var tid = Process.getCurrentThreadId();
if (threads[tid] == STALKED)
return;
Stalker.follow(tid, {
events: {
call: true, // CALL instructions: yes please
ret: false, // RET instructions: no thanks
exec: false // all instructions: no thanks
},
onCallSummary: function (summary) {
var log = []
for (i in summary) {
var addr = idaAddress(base, '0x0', i);
if (addr.compare(ptr(STARTING_ADDRESS)) >= 0 && addr.compare(ptr(ENDING_ADDRESS)) <= 0)
log.push(addr);
}
console.log(JSON.stringify(log));
}
});
threads[tid] = STALKED;
},
onLeave: function(retval) {
var tid = Process.getCurrentThreadId();
if (threads[tid] == STALKED)
return;
Stalker.unfollow(tid);
Stalker.garbageCollect();
console.log('\n');
}
});