-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfridautilts.ts
45 lines (40 loc) · 1.46 KB
/
fridautilts.ts
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
export let frida_log_callback = new NativeCallback(function(sp:NativePointer){
let s = sp.readUtf8String();
console.log(s)
},'void', ['pointer'])
export let frida_log_cstring_callback = new NativeCallback(function(pString:NativePointer){
let s = pString.add(0x0).readPointer().readUtf8String(); // get string to a pointer to a std::string object
console.log(s)
},'void', ['pointer'])
export let frida_hexdump_callback = new NativeCallback(function(sp:NativePointer, size:number){
console.log('dump memory', sp, ' of size ', size)
console.log(hexdump(sp,{
offset: 0,
length: size,
header: true,
ansi: true
}))
},'void', ['pointer','int'])
//////////////////////////////////////////////////
// This function tries to TS code with exception handing
// augments:
// f -- typescript method to run
// cb -- user defined exception handle function
export let runFunWithExceptHandling = function(f:()=>void, cb?:(pe:Error)=>void){
try{
f();
}
catch(_e){
// show errors
let e:Error= _e as Error;
console.log('error occur')
console.log(JSON.stringify(e))
if ((e as any).context != undefined) {
let context = (e as any).context;
console.log('called from:\n' +
Thread.backtrace(context, Backtracer.ACCURATE)
.map(DebugSymbol.fromAddress).join('\n') + '\n');
}
if(cb!=undefined) cb(e)
}
}