Skip to content

Commit

Permalink
darwin: Fix Module.load() with alias
Browse files Browse the repository at this point in the history
The provided name could be an alias, so we may not be able to resolve it
using the same name. When we're on macOS >= 13 or equivalent dyld
versions, we can use _dyld_get_dlopen_image_header() to resolve the
resulting module by address instead.
  • Loading branch information
oleavr committed Jan 16, 2025
1 parent 8d9722a commit b67f905
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion gum/backend-darwin/gummodule-darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,30 @@ gum_module_load (const gchar * module_name,
{
GumModule * module;
gpointer handle;
static gsize initialized = FALSE;
static const struct mach_header * (* get_dlopen_image_header) (void * handle);

handle = dlopen (module_name, RTLD_LAZY);
if (handle == NULL)
goto not_found;

module = gum_process_find_module_by_name (module_name);
if (g_once_init_enter (&initialized))
{
get_dlopen_image_header =
dlsym (RTLD_DEFAULT, "_dyld_get_dlopen_image_header");

g_once_init_leave (&initialized, TRUE);
}

if (get_dlopen_image_header != NULL)
{
module = gum_process_find_module_by_address (
GUM_ADDRESS (get_dlopen_image_header (handle)));
}
else
{
module = gum_process_find_module_by_name (module_name);
}
g_assert (module != NULL);

dlclose (handle);
Expand Down

0 comments on commit b67f905

Please sign in to comment.