From fcd2541b4cf129a6b1a0f4899ef83f3584c93f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Fri, 23 Feb 2024 23:52:11 +0100 Subject: [PATCH] Fix style and start refining the API --- bindings/gumjs/gumquickthread.c | 10 ++++++++-- bindings/gumjs/gumv8thread.cpp | 13 +++++++++---- bindings/gumjs/runtime/core.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/bindings/gumjs/gumquickthread.c b/bindings/gumjs/gumquickthread.c index 494d1e2752..a852eba68f 100644 --- a/bindings/gumjs/gumquickthread.c +++ b/bindings/gumjs/gumquickthread.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 Ole André Vadla Ravnås + * Copyright (C) 2024 DaVinci * * Licence: wxWindows Library Licence, Version 3.1 */ @@ -19,7 +20,7 @@ GUMJS_DECLARE_FUNCTION (gumjs_thread_sleep) static const JSCFunctionListEntry gumjs_thread_entries[] = { - JS_CFUNC_DEF ("backtrace", 0, gumjs_thread_backtrace), + JS_CFUNC_DEF ("_backtrace", 0, gumjs_thread_backtrace), JS_CFUNC_DEF ("sleep", 0, gumjs_thread_sleep), }; @@ -105,9 +106,14 @@ GUMJS_DEFINE_FUNCTION (gumjs_thread_backtrace) goto not_available; if (limit > -1) - gum_backtracer_generate_with_limit (backtracer, cpu_context, &ret_addrs, limit); + { + gum_backtracer_generate_with_limit (backtracer, cpu_context, &ret_addrs, + limit); + } else + { gum_backtracer_generate (backtracer, cpu_context, &ret_addrs); + } result = JS_NewArray (ctx); diff --git a/bindings/gumjs/gumv8thread.cpp b/bindings/gumjs/gumv8thread.cpp index d13a595bd5..d0aadbeb24 100644 --- a/bindings/gumjs/gumv8thread.cpp +++ b/bindings/gumjs/gumv8thread.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010-2022 Ole André Vadla Ravnås + * Copyright (C) 2024 DaVinci * * Licence: wxWindows Library Licence, Version 3.1 */ @@ -17,7 +18,7 @@ GUMJS_DECLARE_FUNCTION (gumjs_thread_sleep) static const GumV8Function gumjs_thread_functions[] = { - { "backtrace", gumjs_thread_backtrace }, + { "_backtrace", gumjs_thread_backtrace }, { "sleep", gumjs_thread_sleep }, { NULL, NULL } @@ -131,9 +132,13 @@ GUMJS_DEFINE_FUNCTION (gumjs_thread_backtrace) GumReturnAddressArray ret_addrs; - if (!limit.IsEmpty () && limit->IsUint32 ()) { - gum_backtracer_generate_with_limit (backtracer, cpu_context, &ret_addrs, limit->Uint32Value(context).FromJust()); - } else { + if (!limit.IsEmpty () && limit->IsUint32 ()) + { + gum_backtracer_generate_with_limit (backtracer, cpu_context, &ret_addrs, + limit->Uint32Value (context).FromJust ()); + } + else + { gum_backtracer_generate (backtracer, cpu_context, &ret_addrs); } diff --git a/bindings/gumjs/runtime/core.js b/bindings/gumjs/runtime/core.js index caeb3fbc70..bd21da76f7 100644 --- a/bindings/gumjs/runtime/core.js +++ b/bindings/gumjs/runtime/core.js @@ -471,6 +471,22 @@ if (Process.findRangeByAddress === undefined) { }); } +Object.defineProperties(Thread, { + backtrace: { + enumerable: true, + value: function (cpuContext, selectorOrOptions = {}) { + const options = (typeof selectorOrOptions === 'object') ? selectorOrOptions : {}; + + const { + selector = Backtracer.ACCURATE, + limit = -1, + } = options; + + return Thread._backtrace(cpuContext, selector, limit); + } + }, +}); + if (globalThis.Interceptor !== undefined) { Object.defineProperties(Interceptor, { attach: {