From 744fab98614669fac93d44d4ff29ccbe24c55596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Wed, 20 Sep 2023 12:34:43 +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 | 76 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/gum/gumswiftapiresolver.c b/gum/gumswiftapiresolver.c index 5a1f91a5b..a4c2f4e84 100644 --- a/gum/gumswiftapiresolver.c +++ b/gum/gumswiftapiresolver.c @@ -617,13 +617,13 @@ gum_module_metadata_collect_class (GumModuleMetadata * self, const GumTypeContextDescriptor * type) { GumClass klass; + guint i; gum_class_parse (&klass, (const GumClassDescriptor *) type); if (klass.num_methods != 0) { GPtrArray * vtable; - guint i; vtable = g_hash_table_lookup (self->vtables, klass.name); @@ -647,45 +647,45 @@ gum_module_metadata_collect_class (GumModuleMetadata * self, g_array_append_val (self->functions, func); } + } - for (i = 0; i != klass.num_overrides; i++) + for (i = 0; i != klass.num_overrides; i++) + { + const GumMethodOverrideDescriptor * od = &klass.overrides[i]; + GumClass parent_class; + const GumMethodDescriptor * parent_method; + guint vtable_index; + GPtrArray * parent_vtable; + GumFunctionMetadata func; + + gum_class_parse (&parent_class, + gum_resolve_relative_indirectable_ptr (&od->class)); + parent_method = gum_resolve_relative_indirectable_ptr (&od->method); + vtable_index = parent_method - parent_class.methods; + + parent_vtable = g_hash_table_lookup (self->vtables, parent_class.name); + + func.name = NULL; + if (parent_vtable != NULL && vtable_index < parent_vtable->len) { - const GumMethodOverrideDescriptor * od = &klass.overrides[i]; - GumClass parent_class; - const GumMethodDescriptor * parent_method; - guint vtable_index; - GPtrArray * parent_vtable; - GumFunctionMetadata func; - - gum_class_parse (&parent_class, - gum_resolve_relative_indirectable_ptr (&od->class)); - parent_method = gum_resolve_relative_indirectable_ptr (&od->method); - vtable_index = parent_method - parent_class.methods; - - parent_vtable = g_hash_table_lookup (self->vtables, parent_class.name); - - func.name = NULL; - if (parent_vtable != NULL && vtable_index < parent_vtable->len) + const gchar * name = g_ptr_array_index (parent_vtable, vtable_index); + if (name != NULL) { - const gchar * name = g_ptr_array_index (parent_vtable, vtable_index); - if (name != NULL) - { - func.name = g_strconcat ( - klass.name, - name + strlen (parent_class.name), - NULL); - } + func.name = g_strconcat ( + klass.name, + name + strlen (parent_class.name), + NULL); } - if (func.name == NULL) - func.name = g_strdup_printf ("%s.overrides[%u]", klass.name, i); + } + if (func.name == NULL) + func.name = g_strdup_printf ("%s.overrides[%u]", klass.name, i); - func.address = GUM_ADDRESS ( - gum_resolve_method_implementation (&od->impl, parent_method)); + func.address = GUM_ADDRESS ( + gum_resolve_method_implementation (&od->impl, parent_method)); - g_array_append_val (self->functions, func); + g_array_append_val (self->functions, func); - gum_class_clear (&parent_class); - } + gum_class_clear (&parent_class); } gum_class_clear (&klass); @@ -878,7 +878,7 @@ 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 */ + return; vtable = g_hash_table_lookup (self->vtables, class_name); if (vtable == NULL) @@ -910,7 +910,13 @@ gum_extract_class_name (const gchar * full_name) } else { - ch = strchr (full_name, '('); + const gchar * start; + + start = g_str_has_prefix (full_name, "(extension in ") + ? full_name + strlen ("(extension in ") + : full_name; + + ch = strchr (start, '('); if (ch == NULL) return NULL; }