Skip to content

Commit

Permalink
Fix style and start refining the API
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Feb 23, 2024
1 parent ee2610a commit f35efc0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 8 additions & 2 deletions bindings/gumjs/gumquickthread.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2020 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2024 DaVinci <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand All @@ -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),
};

Expand Down Expand Up @@ -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);

Expand Down
13 changes: 9 additions & 4 deletions bindings/gumjs/gumv8thread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010-2022 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2024 DaVinci <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand All @@ -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 }
Expand Down Expand Up @@ -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);
}

Expand Down
18 changes: 18 additions & 0 deletions bindings/gumjs/runtime/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,24 @@ if (Process.findRangeByAddress === undefined) {
});
}

Object.defineProperties(Thread, {
backtrace: {
enumerable: true,
value: function (cpuContext, selectorOrOptions = {}) {
const options = (typeof selectorOrOptions === 'object')
? selectorOrOptions
: { selector: selectorOrOptions };

const {
selector = Backtracer.ACCURATE,
limit = -1,
} = options;

return Thread._backtrace(cpuContext, selector, limit);
}
},
});

if (globalThis.Interceptor !== undefined) {
Object.defineProperties(Interceptor, {
attach: {
Expand Down

0 comments on commit f35efc0

Please sign in to comment.