Skip to content

Commit

Permalink
darwin: Port to the new ModuleResolver API
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Feb 18, 2025
1 parent ba7d01f commit 460286d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/darwin/frida-helper-backend-glue.m
Original file line number Diff line number Diff line change
Expand Up @@ -4292,6 +4292,7 @@ static void frida_darwin_helper_backend_launch_using_lsaw (NSString * identifier
static gboolean
frida_agent_context_init_functions (FridaAgentContext * self, GumDarwinModuleResolver * resolver, GumDarwinMapper * mapper, GError ** error)
{
gboolean success = FALSE;
GumDarwinModule * module;

module = gum_darwin_module_resolver_find_module_by_name (resolver, "/usr/lib/system/libsystem_kernel.dylib");
Expand All @@ -4303,6 +4304,8 @@ static void frida_darwin_helper_backend_launch_using_lsaw (NSString * identifier
FRIDA_AGENT_CONTEXT_RESOLVE (mach_msg_receive);
FRIDA_AGENT_CONTEXT_RESOLVE (mach_port_destroy);
FRIDA_AGENT_CONTEXT_RESOLVE (thread_terminate);
g_object_unref (module);
module = NULL;

module = gum_darwin_module_resolver_find_module_by_name (resolver, "/usr/lib/system/libsystem_pthread.dylib");
if (module == NULL)
Expand All @@ -4315,6 +4318,8 @@ static void frida_darwin_helper_backend_launch_using_lsaw (NSString * identifier
FRIDA_AGENT_CONTEXT_TRY_RESOLVE (pthread_threadid_np);
FRIDA_AGENT_CONTEXT_RESOLVE (pthread_detach);
FRIDA_AGENT_CONTEXT_RESOLVE (pthread_self);
g_object_unref (module);
module = NULL;

if (mapper == NULL)
{
Expand All @@ -4324,29 +4329,34 @@ static void frida_darwin_helper_backend_launch_using_lsaw (NSString * identifier
FRIDA_AGENT_CONTEXT_RESOLVE (dlopen);
FRIDA_AGENT_CONTEXT_RESOLVE (dlsym);
FRIDA_AGENT_CONTEXT_RESOLVE (dlclose);
g_object_unref (module);
module = NULL;
}

return TRUE;
success = TRUE;
goto beach;

no_libc:
{
g_set_error (error,
FRIDA_ERROR,
FRIDA_ERROR_NOT_SUPPORTED,
"Unable to attach to processes without Apple's libc (for now)");
goto failure;
goto beach;
}
missing_symbol:
{
g_set_error (error,
FRIDA_ERROR,
FRIDA_ERROR_NOT_SUPPORTED,
"Unexpected error while resolving functions");
goto failure;
goto beach;
}
failure:
beach:
{
return FALSE;
g_clear_object (&module);

return success;
}
}

Expand Down

0 comments on commit 460286d

Please sign in to comment.