Skip to content

Commit

Permalink
darwin: Fix sysroot on simulator
Browse files Browse the repository at this point in the history
the assumtion that dyld_sim is the first loaded image is no longer true
fix by one more pass before indexing loaded images
  • Loading branch information
ChiChou committed Jul 14, 2024
1 parent 452a1b8 commit 15a65b4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions gum/backend-darwin/gumdarwinmoduleresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static void gum_darwin_module_resolver_get_property (GObject * object,
static void gum_darwin_module_resolver_set_property (GObject * object,
guint property_id, const GValue * value, GParamSpec * pspec);

static gboolean gum_find_sysroot (const GumModuleDetails * details,
gpointer user_data);
static gboolean gum_store_module (const GumModuleDetails * details,
gpointer user_data);

Expand Down Expand Up @@ -165,6 +167,7 @@ gum_darwin_module_resolver_load (GumDarwinModuleResolver * self,
ctx.sysroot = NULL;
ctx.sysroot_length = 0;

gum_darwin_enumerate_modules (self->task, gum_find_sysroot, &ctx);
gum_darwin_enumerate_modules (self->task, gum_store_module, &ctx);
if (ctx.index == 0)
goto invalid_task;
Expand Down Expand Up @@ -382,19 +385,29 @@ gum_darwin_module_resolver_find_dynamic_address (GumDarwinModuleResolver * self,
}

static gboolean
gum_store_module (const GumModuleDetails * details,
gum_find_sysroot (const GumModuleDetails * details,
gpointer user_data)
{
GumCollectModulesContext * ctx = user_data;
GumDarwinModuleResolver * self = ctx->self;
GumDarwinModule * module;

if (ctx->index == 0 && g_str_has_suffix (details->path, "/usr/lib/dyld_sim"))
if (g_str_has_suffix (details->path, "/usr/lib/dyld_sim"))
{
ctx->sysroot_length = strlen (details->path) - 17;
ctx->sysroot = g_strndup (details->path, ctx->sysroot_length);
return FALSE;
}

return TRUE;
}

static gboolean
gum_store_module (const GumModuleDetails * details,
gpointer user_data)
{
GumCollectModulesContext * ctx = user_data;
GumDarwinModuleResolver * self = ctx->self;
GumDarwinModule * module;

module = gum_darwin_module_new_from_memory (details->path, self->task,
details->range->base_address, GUM_DARWIN_MODULE_FLAGS_NONE, NULL);
g_hash_table_insert (self->modules, g_strdup (details->name),
Expand Down

0 comments on commit 15a65b4

Please sign in to comment.