Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional support for bitcode, symbol prefixing, and cmodule. #820

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions bindings/gumjs/gumcmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
*
* Licence: wxWindows Library Licence, Version 3.1
*/

#include "gumcmodule.h"

gboolean gum_cmodule_api_is_available(void) {
#ifdef HAVE_CMODULE
return TRUE;
#else
return FALSE;
#endif
}

#include <stdio.h>
#include <string.h>
#include <gio/gio.h>
Expand Down Expand Up @@ -1825,4 +1832,4 @@ gum_append_error (GString ** messages,
g_string_append_c (*messages, '\n');
g_string_append (*messages, msg);
}
}
}
2 changes: 2 additions & 0 deletions bindings/gumjs/gumcmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ GUM_API gpointer gum_cmodule_find_symbol_by_name (GumCModule * self,

GUM_API void gum_cmodule_drop_metadata (GumCModule * self);

GUM_API gboolean gum_cmodule_api_is_available (void);

G_END_DECLS

#endif
29 changes: 29 additions & 0 deletions bindings/gumjs/gumquickcmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Licence: wxWindows Library Licence, Version 3.1
*/


#include "gumquickcmodule.h"

#include "gumcmodule.h"
Expand All @@ -26,11 +27,15 @@ struct _GumAddCSymbolsOperation
GumQuickCore * core;
};

GUMJS_DECLARE_GETTER (gumjs_cmodule_get_available)
GUMJS_DECLARE_GETTER (gumjs_cmodule_get_builtins)
static void gum_store_builtin_define (const GumCDefineDetails * details,
GumGetBuiltinsOperation * op);
static void gum_store_builtin_header (const GumCHeaderDetails * details,
GumGetBuiltinsOperation * op);
static gboolean
gum_quick_cmodule_check_api_available (JSContext * ctx);


GUMJS_DECLARE_CONSTRUCTOR (gumjs_cmodule_construct)
static gboolean gum_parse_cmodule_options (JSContext * ctx, JSValue options_val,
Expand All @@ -44,6 +49,7 @@ GUMJS_DECLARE_FUNCTION (gumjs_cmodule_dispose)

static const JSCFunctionListEntry gumjs_cmodule_module_entries[] =
{
JS_CGETSET_DEF ("available", gumjs_cmodule_get_available, NULL),
JS_CGETSET_DEF ("builtins", gumjs_cmodule_get_builtins, NULL),
};

Expand Down Expand Up @@ -116,6 +122,8 @@ gum_quick_cmodule_get (JSContext * ctx,

GUMJS_DEFINE_GETTER (gumjs_cmodule_get_builtins)
{
if (!gum_quick_cmodule_check_api_available(ctx))
return JS_EXCEPTION;
JSValue result;
GumGetBuiltinsOperation op;

Expand All @@ -138,6 +146,11 @@ GUMJS_DEFINE_GETTER (gumjs_cmodule_get_builtins)
return result;
}

GUMJS_DEFINE_GETTER (gumjs_cmodule_get_available)
{
return JS_NewBool (ctx, gum_cmodule_api_is_available ());
}

static void
gum_store_builtin_define (const GumCDefineDetails * details,
GumGetBuiltinsOperation * op)
Expand Down Expand Up @@ -165,6 +178,9 @@ gum_store_builtin_header (const GumCHeaderDetails * details,

GUMJS_DEFINE_CONSTRUCTOR (gumjs_cmodule_construct)
{
if (!gum_quick_cmodule_check_api_available(ctx))
return JS_EXCEPTION;

JSValue result;
GumQuickCModule * parent;
const gchar * source;
Expand Down Expand Up @@ -416,3 +432,16 @@ GUMJS_DEFINE_FUNCTION (gumjs_cmodule_dispose)

return JS_UNDEFINED;
}

static gboolean
gum_quick_cmodule_check_api_available (JSContext * ctx)
{
if (!gum_cmodule_api_is_available ())
{
_gum_quick_throw_literal (ctx,
"CModule API is not available on this system");
return FALSE;
}

return TRUE;
}
8 changes: 8 additions & 0 deletions bindings/gumjs/gumquickscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ gum_quick_script_destroy_context (GumQuickScript * self)
_gum_quick_code_relocator_dispose (&self->code_relocator);
_gum_quick_code_writer_dispose (&self->code_writer);
_gum_quick_instruction_dispose (&self->instruction);
#ifdef HAVE_CMODULE
_gum_quick_cmodule_dispose (&self->cmodule);
#endif /* HAVE_CMODULE */
_gum_quick_symbol_dispose (&self->symbol);
_gum_quick_api_resolver_dispose (&self->api_resolver);
_gum_quick_interceptor_dispose (&self->interceptor);
Expand Down Expand Up @@ -581,7 +583,9 @@ gum_quick_script_destroy_context (GumQuickScript * self)
_gum_quick_code_relocator_finalize (&self->code_relocator);
_gum_quick_code_writer_finalize (&self->code_writer);
_gum_quick_instruction_finalize (&self->instruction);
#ifdef HAVE_CMODULE
_gum_quick_cmodule_finalize (&self->cmodule);
#endif /* HAVE_CMODULE */
_gum_quick_symbol_finalize (&self->symbol);
_gum_quick_api_resolver_finalize (&self->api_resolver);
_gum_quick_interceptor_finalize (&self->interceptor);
Expand Down Expand Up @@ -1260,7 +1264,9 @@ _gum_quick_worker_unref (GumQuickWorker * worker)
_gum_quick_code_relocator_dispose (&worker->code_relocator);
_gum_quick_code_writer_dispose (&worker->code_writer);
_gum_quick_instruction_dispose (&worker->instruction);
#ifdef HAVE_CMODULE
_gum_quick_cmodule_dispose (&worker->cmodule);
#endif /* HAVE_CMODULE */
_gum_quick_symbol_dispose (&worker->symbol);
_gum_quick_api_resolver_dispose (&worker->api_resolver);
#ifdef HAVE_SQLITE
Expand Down Expand Up @@ -1296,7 +1302,9 @@ _gum_quick_worker_unref (GumQuickWorker * worker)
_gum_quick_code_relocator_finalize (&worker->code_relocator);
_gum_quick_code_writer_finalize (&worker->code_writer);
_gum_quick_instruction_finalize (&worker->instruction);
#ifdef HAVE_CMODULE
_gum_quick_cmodule_finalize (&worker->cmodule);
#endif /* HAVE_CMODULE */
_gum_quick_symbol_finalize (&worker->symbol);
_gum_quick_api_resolver_finalize (&worker->api_resolver);
#ifdef HAVE_SQLITE
Expand Down
2 changes: 1 addition & 1 deletion bindings/gumjs/gumv8cmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ gum_cmodule_entry_on_weak_notify (
HandleScope handle_scope (info.GetIsolate ());
auto self = info.GetParameter ();
g_hash_table_remove (self->module->cmodules, self);
}
}
1 change: 1 addition & 0 deletions bindings/gumjs/gumv8cmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "gumv8core.h"


struct GumV8CModule
{
GumV8Core * core;
Expand Down
2 changes: 2 additions & 0 deletions bindings/gumjs/gumv8script-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ struct _GumV8Script
GumV8Interceptor interceptor;
GumV8ApiResolver api_resolver;
GumV8Symbol symbol;
#ifdef HAVE_CMODULE
GumV8CModule cmodule;
#endif /* HAVE_CMODULE */
GumV8Instruction instruction;
GumV8CodeWriter code_writer;
GumV8CodeRelocator code_relocator;
Expand Down
14 changes: 11 additions & 3 deletions bindings/gumjs/gumv8script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,9 @@ gum_v8_script_create_context (GumV8Script * self,
global_templ);
_gum_v8_api_resolver_init (&self->api_resolver, &self->core, global_templ);
_gum_v8_symbol_init (&self->symbol, &self->core, global_templ);
#ifdef HAVE_CMODULE
_gum_v8_cmodule_init (&self->cmodule, &self->core, global_templ);
#endif /* HAVE_CMODULE */
_gum_v8_instruction_init (&self->instruction, &self->core, global_templ);
_gum_v8_code_writer_init (&self->code_writer, &self->core, global_templ);
_gum_v8_code_relocator_init (&self->code_relocator, &self->code_writer,
Expand Down Expand Up @@ -567,7 +569,9 @@ gum_v8_script_create_context (GumV8Script * self,
_gum_v8_interceptor_realize (&self->interceptor);
_gum_v8_api_resolver_realize (&self->api_resolver);
_gum_v8_symbol_realize (&self->symbol);
_gum_v8_cmodule_realize (&self->cmodule);
#ifdef HAVE_CMODULE
_gum_v8_cmodule_realize (&self->cmodule);
#endif /* HAVE_CMODULE */
_gum_v8_instruction_realize (&self->instruction);
_gum_v8_code_writer_realize (&self->code_writer);
_gum_v8_code_relocator_realize (&self->code_relocator);
Expand Down Expand Up @@ -1108,7 +1112,9 @@ gum_v8_script_destroy_context (GumV8Script * self)
_gum_v8_code_relocator_dispose (&self->code_relocator);
_gum_v8_code_writer_dispose (&self->code_writer);
_gum_v8_instruction_dispose (&self->instruction);
_gum_v8_cmodule_dispose (&self->cmodule);
#ifdef HAVE_CMODULE
_gum_v8_cmodule_dispose (&self->cmodule);
#endif /* HAVE_CMODULE */
_gum_v8_symbol_dispose (&self->symbol);
_gum_v8_api_resolver_dispose (&self->api_resolver);
_gum_v8_interceptor_dispose (&self->interceptor);
Expand Down Expand Up @@ -1141,7 +1147,9 @@ gum_v8_script_destroy_context (GumV8Script * self)
_gum_v8_code_relocator_finalize (&self->code_relocator);
_gum_v8_code_writer_finalize (&self->code_writer);
_gum_v8_instruction_finalize (&self->instruction);
_gum_v8_cmodule_finalize (&self->cmodule);
#ifdef HAVE_CMODULE
_gum_v8_cmodule_finalize (&self->cmodule);
#endif /* HAVE_CMODULE */
_gum_v8_symbol_finalize (&self->symbol);
_gum_v8_api_resolver_finalize (&self->api_resolver);
_gum_v8_interceptor_finalize (&self->interceptor);
Expand Down
58 changes: 35 additions & 23 deletions bindings/gumjs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -164,28 +164,33 @@ gumjs_runtime_sources = [
'runtime' / 'objc.js',
'runtime' / 'swift.js',
'runtime' / 'java.js',
'runtime' / 'cmodule-tcc' / 'inttypes.h',
'runtime' / 'cmodule-tcc' / 'stdint.h',
'runtime' / 'cmodule-tcc' / 'stdio.h',
'runtime' / 'cmodule-tcc' / 'stdlib.h',
'runtime' / 'cmodule-tcc' / 'string.h',
'runtime' / 'cmodule' / 'glib.h',
'runtime' / 'cmodule' / 'gum' / 'gumdefs.h',
'runtime' / 'cmodule' / 'gum' / 'gumprocess.h',
'runtime' / 'cmodule' / 'gum' / 'gummodulemap.h',
'runtime' / 'cmodule' / 'gum' / 'gummemory.h',
'runtime' / 'cmodule' / 'gum' / 'guminterceptor.h',
'runtime' / 'cmodule' / 'gum' / 'gumstalker.h',
'runtime' / 'cmodule' / 'gum' / 'gummetalarray.h',
'runtime' / 'cmodule' / 'gum' / 'gummetalhash.h',
'runtime' / 'cmodule' / 'gum' / 'gumspinlock.h',
'runtime' / 'cmodule' / 'gum' / 'gumtls.h',
'runtime' / 'cmodule' / 'json-glib' / 'json-glib.h',
]
gumjs_runtime_outputs = [
'runtime.bundle',
'gumcmodule-runtime.h',
]

if get_option('cmodule').allowed()
gumjs_runtime_sources += [
'runtime' / 'cmodule-tcc' / 'inttypes.h',
'runtime' / 'cmodule-tcc' / 'stdint.h',
'runtime' / 'cmodule-tcc' / 'stdio.h',
'runtime' / 'cmodule-tcc' / 'stdlib.h',
'runtime' / 'cmodule-tcc' / 'string.h',
'runtime' / 'cmodule' / 'glib.h',
'runtime' / 'cmodule' / 'gum' / 'gumdefs.h',
'runtime' / 'cmodule' / 'gum' / 'gumprocess.h',
'runtime' / 'cmodule' / 'gum' / 'gummodulemap.h',
'runtime' / 'cmodule' / 'gum' / 'gummemory.h',
'runtime' / 'cmodule' / 'gum' / 'guminterceptor.h',
'runtime' / 'cmodule' / 'gum' / 'gumstalker.h',
'runtime' / 'cmodule' / 'gum' / 'gummetalarray.h',
'runtime' / 'cmodule' / 'gum' / 'gummetalhash.h',
'runtime' / 'cmodule' / 'gum' / 'gumspinlock.h',
'runtime' / 'cmodule' / 'gum' / 'gumtls.h',
'runtime' / 'cmodule' / 'json-glib' / 'json-glib.h',
]
gumjs_runtime_outputs += ['gumcmodule-runtime.h']
endif
if quickjs_dep.found()
gumjs_runtime_outputs += [
'gumquickscript-runtime.h',
Expand Down Expand Up @@ -215,11 +220,15 @@ gumjs_generated_bindings = custom_target('gumjs-generated-bindings',
)
gumjs_sources += [gumjs_generated_bindings]

if libtcc_dep.found()
if libtcc_dep.type_name() == 'internal'
libtcc_incdir = meson.project_source_root() / 'subprojects' / 'tinycc' / 'include'
if get_option('cmodule').allowed()
if libtcc_dep.found()
if libtcc_dep.type_name() == 'internal'
libtcc_incdir = meson.project_source_root() / 'subprojects' / 'tinycc' / 'include'
else
libtcc_incdir = libtcc_dep.get_variable('libdir') / 'tcc' / 'include'
endif
else
libtcc_incdir = libtcc_dep.get_variable('libdir') / 'tcc' / 'include'
libtcc_incdir = ''
endif
else
libtcc_incdir = ''
Expand Down Expand Up @@ -264,10 +273,13 @@ gumjs_deps = [
gio_os_package_dep,
json_glib_dep,
ffi_dep,
libtcc_dep,
sqlite_dep,
]

if get_option('cmodule').allowed()
gumjs_deps += libtcc_dep
endif

gumjs = library('frida-gumjs-' + api_version, gumjs_sources,
c_args: frida_component_cflags,
override_options: [
Expand Down
Loading
Loading