From 5c1e6cfaf6ae87946bf5037f7f3f4d2c8d8ae0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 19 Sep 2023 15:58:35 +0200 Subject: [PATCH] [WIP] Wire up some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Håvard Sørbø --- gum/gumswiftapiresolver.c | 53 +++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/gum/gumswiftapiresolver.c b/gum/gumswiftapiresolver.c index 55e8ec88a..928f83427 100644 --- a/gum/gumswiftapiresolver.c +++ b/gum/gumswiftapiresolver.c @@ -73,7 +73,6 @@ typedef struct _GumVTableDescriptorHeader GumVTableDescriptorHeader; typedef struct _GumMethodDescriptor GumMethodDescriptor; typedef struct _GumOverrideTableHeader GumOverrideTableHeader; typedef struct _GumMethodOverrideDescriptor GumMethodOverrideDescriptor; -typedef struct _GumMangledContextName GumMangledContextName; typedef gint32 GumRelativeDirectPtr; typedef gint32 GumRelativeIndirectablePtr; @@ -260,11 +259,6 @@ struct _GumMethodOverrideDescriptor GumRelativeDirectPtr impl; }; -struct _GumMangledContextName -{ - GumRelativeDirectPtr name; -}; - static void gum_swift_api_resolver_iface_init (gpointer g_iface, gpointer iface_data); static void gum_swift_api_resolver_finalize (GObject * object); @@ -285,14 +279,14 @@ static gboolean gum_module_metadata_collect_export ( const GumExportDetails * details, gpointer user_data); static void gum_module_metadata_maybe_ingest_thunk (GumModuleMetadata * self, const gchar * name, GumAddress address); +#ifdef HAVE_ARM64 static gchar * gum_extract_class_name (const gchar * full_name); static const gchar * gum_find_character_backwards (const gchar * starting_point, char needle, const gchar * start); +#endif static void gum_function_metadata_free (GumFunctionMetadata * function); -static void gum_skip_generic_trailers (gconstpointer * trailer_ptr, - const GumContextDescriptor * t); static void gum_skip_generic_type_trailers (gconstpointer * trailer_ptr, const GumTypeContextDescriptor * t); static void gum_skip_generic_parts (gconstpointer * trailer_ptr, @@ -628,9 +622,11 @@ gum_module_metadata_collect_class (GumModuleMetadata * self, trailer = methods + vth->vtable_size; } -#if 0 +#if 1 if (GUM_TYPE_FLAGS_CLASS_HAS_OVERRIDE_TABLE (type_flags)) { + g_printerr ("TODO: handle override: %s\n", gum_resolve_relative_direct_ptr (&type->name)); +#if 0 const GumOverrideTableHeader * oth; const GumMethodOverrideDescriptor * methods; guint32 i; @@ -648,6 +644,7 @@ gum_module_metadata_collect_class (GumModuleMetadata * self, } trailer = methods + oth->num_entries; +#endif } #endif } @@ -778,6 +775,8 @@ gum_module_metadata_collect_export (const GumExportDetails * details, return TRUE; } +#ifdef HAVE_ARM64 + static void gum_module_metadata_maybe_ingest_thunk (GumModuleMetadata * self, const gchar * name, @@ -825,8 +824,6 @@ gum_module_metadata_maybe_ingest_thunk (GumModuleMetadata * self, if (GUM_REG_IS_TRACKED (dst)) { - gint offset; - if (!(src->base == ARM64_REG_X20 && src->disp == 0)) { /* @@ -922,6 +919,9 @@ gum_module_metadata_maybe_ingest_thunk (GumModuleMetadata * self, end_of_thunk = TRUE; break; } + +#undef GUM_REG_IS_TRACKED +#undef GUM_REG_INDEX } cs_free (insn, 1); @@ -936,6 +936,8 @@ gum_module_metadata_maybe_ingest_thunk (GumModuleMetadata * self, full_name = name + strlen ("dispatch thunk of "); class_name = gum_extract_class_name (full_name); + if (class_name == NULL) + return; /* TODO: Handle extensions */ vtable = g_hash_table_lookup (self->vtables, class_name); if (vtable == NULL) @@ -986,40 +988,31 @@ gum_find_character_backwards (const gchar * starting_point, { const gchar * ch = starting_point; - do + while (ch != start) { ch--; if (*ch == needle) return ch; } - while (ch != start); return NULL; } +#else + static void -gum_function_metadata_free (GumFunctionMetadata * function) +gum_module_metadata_maybe_ingest_thunk (GumModuleMetadata * self, + const gchar * name, + GumAddress address) { - g_free (function->name); } +#endif + static void -gum_skip_generic_trailers (gconstpointer * trailer_ptr, - const GumContextDescriptor * t) +gum_function_metadata_free (GumFunctionMetadata * function) { - gconstpointer trailer = *trailer_ptr; - - if (GUM_DESCRIPTOR_FLAGS_IS_GENERIC (t->flags)) - { - const GumGenericContextDescriptorHeader * th; - - th = GUM_ALIGN (trailer, GumGenericContextDescriptorHeader); - trailer = th + 1; - - gum_skip_generic_parts (&trailer, th); - } - - *trailer_ptr = trailer; + g_free (function->name); } static void