-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gumjs: Add findSymbolByName()/getSymbolByName()
Provide direct, native lookups for symbols by name instead of enumerating all symbols and filtering them in JavaScript. On ELF-based backends, we can potentially leverage binary search for faster performance.
- Loading branch information
Showing
4 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2020-2023 Ole André Vadla Ravnås <[email protected]> | ||
* Copyright (C) 2020-2024 Ole André Vadla Ravnås <[email protected]> | ||
* | ||
* Licence: wxWindows Library Licence, Version 3.1 | ||
*/ | ||
|
@@ -51,6 +51,7 @@ static gboolean gum_emit_dependency (const GumDependencyDetails * details, | |
GumQuickMatchContext * mc); | ||
GUMJS_DECLARE_FUNCTION (gumjs_module_find_base_address) | ||
GUMJS_DECLARE_FUNCTION (gumjs_module_find_export_by_name) | ||
GUMJS_DECLARE_FUNCTION (gumjs_module_find_symbol_by_name) | ||
|
||
GUMJS_DECLARE_CONSTRUCTOR (gumjs_module_map_construct) | ||
GUMJS_DECLARE_FINALIZER (gumjs_module_map_finalize) | ||
|
@@ -84,6 +85,7 @@ static const JSCFunctionListEntry gumjs_module_entries[] = | |
gumjs_module_enumerate_dependencies), | ||
JS_CFUNC_DEF ("findBaseAddress", 0, gumjs_module_find_base_address), | ||
JS_CFUNC_DEF ("findExportByName", 0, gumjs_module_find_export_by_name), | ||
JS_CFUNC_DEF ("findSymbolByName", 0, gumjs_module_find_symbol_by_name), | ||
}; | ||
|
||
static const JSClassDef gumjs_module_map_def = | ||
|
@@ -599,6 +601,27 @@ GUMJS_DEFINE_FUNCTION (gumjs_module_find_export_by_name) | |
return _gum_quick_native_pointer_new (ctx, GSIZE_TO_POINTER (address), core); | ||
} | ||
|
||
GUMJS_DEFINE_FUNCTION (gumjs_module_find_symbol_by_name) | ||
{ | ||
const gchar * module_name, * symbol_name; | ||
GumQuickScope scope = GUM_QUICK_SCOPE_INIT (core); | ||
GumAddress address; | ||
|
||
if (!_gum_quick_args_parse (args, "s?s", &module_name, &symbol_name)) | ||
return JS_EXCEPTION; | ||
|
||
_gum_quick_scope_suspend (&scope); | ||
|
||
address = gum_module_find_symbol_by_name (module_name, symbol_name); | ||
|
||
_gum_quick_scope_resume (&scope); | ||
|
||
if (address == 0) | ||
return JS_NULL; | ||
|
||
return _gum_quick_native_pointer_new (ctx, GSIZE_TO_POINTER (address), core); | ||
} | ||
|
||
static gboolean | ||
gum_quick_module_map_get (JSContext * ctx, | ||
JSValueConst val, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2010-2023 Ole André Vadla Ravnås <[email protected]> | ||
* Copyright (C) 2010-2024 Ole André Vadla Ravnås <[email protected]> | ||
* | ||
* Licence: wxWindows Library Licence, Version 3.1 | ||
*/ | ||
|
@@ -85,6 +85,7 @@ static gboolean gum_emit_dependency (const GumDependencyDetails * details, | |
GumV8MatchContext<GumV8Module> * mc); | ||
GUMJS_DECLARE_FUNCTION (gumjs_module_find_base_address) | ||
GUMJS_DECLARE_FUNCTION (gumjs_module_find_export_by_name) | ||
GUMJS_DECLARE_FUNCTION (gumjs_module_find_symbol_by_name) | ||
|
||
GUMJS_DECLARE_CONSTRUCTOR (gumjs_module_map_construct) | ||
GUMJS_DECLARE_GETTER (gumjs_module_map_get_handle) | ||
|
@@ -117,6 +118,7 @@ static const GumV8Function gumjs_module_static_functions[] = | |
{ "_enumerateDependencies", gumjs_module_enumerate_dependencies }, | ||
{ "findBaseAddress", gumjs_module_find_base_address }, | ||
{ "findExportByName", gumjs_module_find_export_by_name }, | ||
{ "findSymbolByName", gumjs_module_find_symbol_by_name }, | ||
|
||
{ NULL, NULL } | ||
}; | ||
|
@@ -630,6 +632,33 @@ GUMJS_DEFINE_FUNCTION (gumjs_module_find_export_by_name) | |
g_free (symbol_name); | ||
} | ||
|
||
GUMJS_DEFINE_FUNCTION (gumjs_module_find_symbol_by_name) | ||
{ | ||
gchar * module_name, * symbol_name; | ||
if (!_gum_v8_args_parse (args, "s?s", &module_name, &symbol_name)) | ||
return; | ||
|
||
GumAddress address; | ||
{ | ||
ScriptUnlocker unlocker (core); | ||
|
||
address = gum_module_find_symbol_by_name (module_name, symbol_name); | ||
} | ||
|
||
if (address != 0) | ||
{ | ||
info.GetReturnValue ().Set ( | ||
_gum_v8_native_pointer_new (GSIZE_TO_POINTER (address), core)); | ||
} | ||
else | ||
{ | ||
info.GetReturnValue ().SetNull (); | ||
} | ||
|
||
g_free (module_name); | ||
g_free (symbol_name); | ||
} | ||
|
||
GUMJS_DEFINE_CONSTRUCTOR (gumjs_module_map_construct) | ||
{ | ||
if (!info.IsConstructCall ()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters