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
| function hook_gettimeofday() {
var addr_gettimeofday = Module.findExportByName(null, "gettimeofday");
var gettimeofday = new NativeFunction(addr_gettimeofday, "int", ["pointer", "pointer"]);
var source = [
'struct timeval {',
' int tv_sec;',
' int tv_usec;',
'};',
'void modify_time(struct timeval* tv, int tv_sec, int tv_usec) {',
' tv->tv_sec = tv_sec;',
' tv->tv_usec = tv_usec;',
'}',
].join('\n');
var cm = new CModule(source);
var modify_time = new NativeFunction(cm.modify_time, 'void', ["pointer", "int", "int"]);
Interceptor.replace(addr_gettimeofday, new NativeCallback(function (ptr_tz, ptr_tzp) {
var result = gettimeofday(ptr_tz, ptr_tzp);
if (result == 0) {
console.log("hook gettimeofday:", ptr_tz, ptr_tzp, result);
//modify_time(ptr_tz, 0xAAAA, 0xBBBB);
var t = new Int32Array(ArrayBuffer.wrap(ptr_tz, 8));
t[0] = 0xAAAA;
t[1] = 0xBBBB;
console.log(hexdump(ptr_tz));
}
return result;
}, "int", ["pointer", "pointer"]));
}
|