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

darwin: Fix sysroot on simulator #809

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
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
Loading