Skip to content

Commit

Permalink
Cache main module value in v8 too
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete committed Nov 27, 2023
1 parent 7bf30e9 commit 9dd7f9b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
25 changes: 13 additions & 12 deletions bindings/gumjs/gumquickprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void gum_quick_exception_handler_free (
static gboolean gum_quick_exception_handler_on_exception (
GumExceptionDetails * details, GumQuickExceptionHandler * handler);

static void gumjs_free_main_module (GumQuickProcess * self);
static void gumjs_free_main_module_value (GumQuickProcess * self);

static const JSCFunctionListEntry gumjs_process_entries[] =
{
Expand Down Expand Up @@ -146,7 +146,7 @@ _gum_quick_process_init (GumQuickProcess * self,

self->module = module;
self->core = core;
self->main_module = JS_UNINITIALIZED;
self->main_module_value = JS_UNINITIALIZED;

_gum_quick_core_store_module_data (core, "process", self);

Expand All @@ -167,25 +167,25 @@ _gum_quick_process_init (GumQuickProcess * self,
void
_gum_quick_process_flush (GumQuickProcess * self)
{
gumjs_free_main_module (self);
gumjs_free_main_module_value (self);
g_clear_pointer (&self->exception_handler, gum_quick_exception_handler_free);
}

void
_gum_quick_process_dispose (GumQuickProcess * self)
{
gumjs_free_main_module (self);
gumjs_free_main_module_value (self);
g_clear_pointer (&self->exception_handler, gum_quick_exception_handler_free);
}

static void
gumjs_free_main_module (GumQuickProcess * self)
gumjs_free_main_module_value (GumQuickProcess * self)
{
if (JS_IsUninitialized (self->main_module))
if (JS_IsUninitialized (self->main_module_value))
return;

JS_FreeValue (self->core->ctx, self->main_module);
self->main_module = JS_UNINITIALIZED;
JS_FreeValue (self->core->ctx, self->main_module_value);
self->main_module_value = JS_UNINITIALIZED;
}

void
Expand All @@ -205,13 +205,14 @@ GUMJS_DEFINE_GETTER (gumjs_process_get_main_module)

self = gumjs_get_parent_module (core);

if (JS_IsUninitialized (self->main_module))
if (JS_IsUninitialized (self->main_module_value))
{
const GumModuleDetails * main_details = gum_process_get_main_module ();
self->main_module = _gum_quick_module_new (ctx, main_details, self->module);
const GumModuleDetails * main_module = gum_process_get_main_module ();
self->main_module_value = _gum_quick_module_new (ctx, main_module,
self->module);
}

return JS_DupValue (ctx, self->main_module);
return JS_DupValue (ctx, self->main_module_value);
}

GUMJS_DEFINE_FUNCTION (gumjs_process_get_current_dir)
Expand Down
2 changes: 1 addition & 1 deletion bindings/gumjs/gumquickprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct _GumQuickProcess
GumQuickCore * core;

GumQuickExceptionHandler * exception_handler;
JSValue main_module;
JSValue main_module_value;
};

G_GNUC_INTERNAL void _gum_quick_process_init (GumQuickProcess * self,
Expand Down
21 changes: 17 additions & 4 deletions bindings/gumjs/gumv8process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ _gum_v8_process_realize (GumV8Process * self)
void
_gum_v8_process_flush (GumV8Process * self)
{
delete self->main_module_value;
self->main_module_value = nullptr;
g_clear_pointer (&self->exception_handler, gum_v8_exception_handler_free);
}

void
_gum_v8_process_dispose (GumV8Process * self)
{
delete self->main_module_value;
self->main_module_value = nullptr;
g_clear_pointer (&self->exception_handler, gum_v8_exception_handler_free);
}

Expand All @@ -177,12 +181,21 @@ _gum_v8_process_finalize (GumV8Process * self)
GUMJS_DEFINE_GETTER (gumjs_process_get_main_module)
{
auto self = module;
const GumModuleDetails * main_module;

main_module = gum_process_get_main_module ();
if (self->main_module_value == nullptr)
{
const GumModuleDetails * main_module = gum_process_get_main_module ();
auto main_module_value = _gum_v8_module_value_new (main_module,
self->module);
self->main_module_value = new Global<Object> (self->core->isolate,
main_module_value);
}

auto main_module_template_value = (Local<Object>::New (isolate,
*module->main_module_value));
auto main_module_value (main_module_template_value->Clone ());

info.GetReturnValue ().Set (_gum_v8_module_value_new (main_module,
self->module));
info.GetReturnValue ().Set (main_module_value);
}

GUMJS_DEFINE_FUNCTION (gumjs_process_get_current_dir)
Expand Down
1 change: 1 addition & 0 deletions bindings/gumjs/gumv8process.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct GumV8Process
GumV8Core * core;

GumV8ExceptionHandler * exception_handler;
v8::Global<v8::Object> * main_module_value;
};

G_GNUC_INTERNAL void _gum_v8_process_init (GumV8Process * self,
Expand Down

0 comments on commit 9dd7f9b

Please sign in to comment.