diff --git a/scripts/eslint.config.js b/scripts/eslint.config.js index 604cca4..5dc4e47 100644 --- a/scripts/eslint.config.js +++ b/scripts/eslint.config.js @@ -9,9 +9,6 @@ export default tseslint.config( parserOptions: { project: true } - }, - rules: { - "@typescript-eslint/no-unused-vars": "off" } }, { diff --git a/scripts/utils.ts b/scripts/utils.ts index db1a3d5..c0c9ebc 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -1,6 +1,6 @@ -function allocString(str: string): NativePointer { +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); @@ -18,7 +18,7 @@ global.pauseAt = function pauseAt(name: string): void { Thread.sleep(1); } resume = false; - console.log("Resumed"); + console.debug("Resumed"); } }); }; @@ -33,7 +33,7 @@ global.backtraceAt = function backtraceAt(name: string): void { const symbols = backtrace.map(address => { return DebugSymbol.fromAddress(address); }); - console.log(JSON.stringify(symbols, null, 4)); + console.debug(JSON.stringify(symbols, null, 4)); } }); }; @@ -42,6 +42,35 @@ global.getFunc = function getFunc(name: string, ret: NativeFunctionReturnType, a 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; @@ -50,4 +79,6 @@ declare global { function backtraceAt(name: string): void; function getFunc(name: string, ret: NativeFunctionReturnType, args: NativeFunctionArgumentType[]): NativeFunction; function resumeBreakpoints(): void; + function readPointer(pointer: NativePointer, type: string): string; + function trace(name: string, ret_str: string, args_str: string[]): void; }