84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
global.allocString = function allocString(str: string): NativePointer {
|
|
return Memory.allocUtf8String(str);
|
|
};
|
|
global.backtrace = function backtrace(): DebugSymbol[] {
|
|
const context = Process.enumerateThreads()[0].context;
|
|
const backtrace = Thread.backtrace(context);
|
|
const symbols = backtrace.map(address => {
|
|
return DebugSymbol.fromAddress(address);
|
|
});
|
|
return symbols;
|
|
};
|
|
let resume = false;
|
|
global.pauseAt = function pauseAt(name: string): void {
|
|
const addr = DebugSymbol.getFunctionByName(name);
|
|
Interceptor.attach(addr, {
|
|
onEnter() {
|
|
while (!resume) {
|
|
Thread.sleep(1);
|
|
}
|
|
resume = false;
|
|
console.debug("Resumed");
|
|
}
|
|
});
|
|
};
|
|
global.resumeBreakpoints = function resumeBreakpoints(): void {
|
|
resume = true;
|
|
};
|
|
global.backtraceAt = function backtraceAt(name: string): void {
|
|
const addr = DebugSymbol.getFunctionByName(name);
|
|
Interceptor.attach(addr, {
|
|
onEnter() {
|
|
const backtrace = Thread.backtrace(this.context);
|
|
const symbols = backtrace.map(address => {
|
|
return DebugSymbol.fromAddress(address);
|
|
});
|
|
console.debug(JSON.stringify(symbols, null, 4));
|
|
}
|
|
});
|
|
};
|
|
global.getFunc = function getFunc(name: string, ret: NativeFunctionReturnType, args: NativeFunctionArgumentType[]): NativeFunction<NativeFunctionReturnValue, NativeFunctionArgumentValue[]> {
|
|
const addr = DebugSymbol.getFunctionByName(name);
|
|
return new NativeFunction(addr, ret, args);
|
|
};
|
|
|
|
global.readPointer = function readPointer(pointer: NativePointer, type: string): string {
|
|
switch (type) {
|
|
case "void":
|
|
return "void";
|
|
case "int":
|
|
return pointer.readInt().toString();
|
|
case "pointer":
|
|
return "\"" + pointer.readUtf8String()! + "\"";
|
|
default:
|
|
return "undefined";
|
|
}
|
|
};
|
|
global.trace = function trace(name: string, ret_type: string, args_type: string[]): void {
|
|
const addr = DebugSymbol.getFunctionByName(name);
|
|
Interceptor.attach(addr, {
|
|
onEnter(args: InvocationArguments) {
|
|
const args_str: string[] = [];
|
|
for (let i = 0; i < args_type.length; i++) {
|
|
args_str.push(readPointer(args[i], args_type[i]));
|
|
}
|
|
console.debug(`-> ${name}(${args_str.join(" ")})`);
|
|
},
|
|
onLeave(retval: InvocationReturnValue) {
|
|
console.debug(`<- ${name} = ${readPointer(retval, ret_type)}`);
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
export { };
|
|
declare global {
|
|
function allocString(str: string): NativePointer;
|
|
function backtrace(): DebugSymbol[];
|
|
function pauseAt(name: string): void;
|
|
function backtraceAt(name: string): void;
|
|
function getFunc(name: string, ret: NativeFunctionReturnType, args: NativeFunctionArgumentType[]): NativeFunction<NativeFunctionReturnValue, NativeFunctionArgumentValue[]>;
|
|
function resumeBreakpoints(): void;
|
|
function readPointer(pointer: NativePointer, type: string): string;
|
|
function trace(name: string, ret_str: string, args_str: string[]): void;
|
|
}
|