Skip to content

Commit

Permalink
Fix JS bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 21, 2024
1 parent 8672449 commit 85854ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 8 additions & 4 deletions bindings/gumjs/gumquickprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,22 +654,23 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread)
GumQuickScope scope = GUM_QUICK_SCOPE_INIT (core);
GumThreadId thread_id;
JSValue user_func;
GumQuickRunOnThreadContext context;
GumQuickRunOnThreadContext * context;
gboolean run;

if (!_gum_quick_args_parse (args, "ZF", &thread_id, &user_func))
return JS_EXCEPTION;

_gum_quick_scope_suspend (&scope);

context.core = core;
context.user_func = JS_DupValue (core->ctx, user_func);
context = g_slice_new (GumQuickRunOnThreadContext);
context->core = core;
context->user_func = JS_DupValue (core->ctx, user_func);

if (self->stalker == NULL)
self->stalker = gum_stalker_new ();

run = gum_stalker_run_on_thread (self->stalker, thread_id,
gum_js_process_run_cb, &context);
gum_js_process_run_cb, context);

_gum_quick_scope_resume (&scope);
gum_quick_flush_stalker (self, &scope);
Expand All @@ -680,6 +681,7 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread)
return JS_UNDEFINED;

error:
g_slice_free (GumQuickRunOnThreadContext, context);
_gum_quick_throw_literal (ctx, "failed to run on thread");
return JS_EXCEPTION;
}
Expand All @@ -701,6 +703,8 @@ gum_js_process_run_cb (const GumCpuContext * cpu_context,
JS_FreeValue (core->ctx, user_func);

_gum_quick_scope_leave (&scope);

g_slice_free (GumQuickRunOnThreadContext, context);
}

static void
Expand Down
18 changes: 11 additions & 7 deletions bindings/gumjs/gumv8process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct GumV8FindModuleByNameContext
struct GumV8RunOnThreadContext
{
GumV8Core * core;
Global<Function> user_func;
Global<Function> * user_func;
};

GUMJS_DECLARE_GETTER (gumjs_process_get_main_module)
Expand Down Expand Up @@ -536,8 +536,7 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread)
{
GumThreadId thread_id;
Local<Function> user_func;
GumV8RunOnThreadContext context;
gboolean run;
gboolean run;

auto isolate = core->isolate;

Expand All @@ -547,13 +546,14 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread)
if (module->stalker == NULL)
module->stalker = gum_stalker_new ();

context.core = core;
context.user_func = Global<Function> (isolate, user_func);
auto context = g_slice_new (GumV8RunOnThreadContext);
context->core = core;
context->user_func = new Global<Function> (isolate, user_func);

{
ScriptUnlocker unlocker (core);
run = gum_stalker_run_on_thread (module->stalker, thread_id,
gum_js_process_run_cb, &context);
gum_js_process_run_cb, context);
}

gum_v8_flush_stalker (module);
Expand All @@ -577,11 +577,15 @@ gum_js_process_run_cb (const GumCpuContext * cpu_context,
ScriptScope scope (core->script);

auto isolate = core->isolate;
auto user_func = Local<Function>::New (isolate, context->user_func);
auto user_func = Local<Function>::New (isolate, *context->user_func);
auto ctx = isolate->GetCurrentContext ();
auto recv = Undefined (isolate);
auto result = user_func->Call (ctx, recv, 0, nullptr);
(void) result;

delete context->user_func;

g_slice_free (GumV8RunOnThreadContext, context);
}

static void
Expand Down

0 comments on commit 85854ed

Please sign in to comment.