diff --git a/gum/gumswiftapiresolver.c b/gum/gumswiftapiresolver.c index 83ee972ce..f9ec2a87d 100644 --- a/gum/gumswiftapiresolver.c +++ b/gum/gumswiftapiresolver.c @@ -266,6 +266,8 @@ static void gum_module_metadata_unref (GumModuleMetadata * module); static GArray * gum_module_metadata_get_functions (GumModuleMetadata * self); static gboolean gum_module_metadata_collect_section ( const GumSectionDetails * details, gpointer user_data); +static void gum_module_metadata_collect_class (GumModuleMetadata * self, + const GumTypeContextDescriptor * type); static void gum_module_metadata_collect_function (GumModuleMetadata * self, const gchar * label, gconstpointer impl, const GumTypeContextDescriptor * holder); @@ -559,85 +561,84 @@ gum_module_metadata_collect_section (const GumSectionDetails * details, switch (GUM_DESCRIPTOR_FLAGS_KIND (descriptor_flags)) { case GUM_CONTEXT_DESCRIPTOR_CLASS: - { - const GumClassDescriptor * cd; - gconstpointer trailer; - guint16 type_flags; + gum_module_metadata_collect_class (module, type); + break; + default: + break; + } + } - cd = (const GumClassDescriptor *) type; - trailer = cd + 1; + return TRUE; +} - gum_skip_generic_type_trailers (&trailer, type); +static void +gum_module_metadata_collect_class (GumModuleMetadata * self, + const GumTypeContextDescriptor * type) +{ + const GumClassDescriptor * cd; + gconstpointer trailer; + guint16 type_flags; - gum_skip_metadata_initialization_trailers (&trailer, type); + cd = (const GumClassDescriptor *) type; + trailer = cd + 1; - type_flags = GUM_DESCRIPTOR_FLAGS_KIND_FLAGS (type->context.flags); + gum_skip_generic_type_trailers (&trailer, type); - if (GUM_TYPE_FLAGS_CLASS_HAS_VTABLE (type_flags)) - { - const GumVTableDescriptorHeader * vth; - const GumMethodDescriptor * methods; - guint32 i; + gum_skip_metadata_initialization_trailers (&trailer, type); - vth = GUM_ALIGN (trailer, GumVTableDescriptorHeader); - methods = GUM_ALIGN ((const GumMethodDescriptor *) (vth + 1), - GumMethodDescriptor); + type_flags = GUM_DESCRIPTOR_FLAGS_KIND_FLAGS (type->context.flags); - for (i = 0; i != vth->vtable_size; i++) - { - const GumMethodDescriptor * method = &methods[i]; - gchar * label; + if (GUM_TYPE_FLAGS_CLASS_HAS_VTABLE (type_flags)) + { + const GumVTableDescriptorHeader * vth; + const GumMethodDescriptor * methods; + guint32 i; - label = g_strdup_printf ("vtable[%u]", i); + vth = GUM_ALIGN (trailer, GumVTableDescriptorHeader); + methods = GUM_ALIGN ((const GumMethodDescriptor *) (vth + 1), + GumMethodDescriptor); - gum_module_metadata_collect_function (module, label, - gum_resolve_relative_direct_ptr (&method->impl), type); + for (i = 0; i != vth->vtable_size; i++) + { + const GumMethodDescriptor * method = &methods[i]; + gchar * label; - g_free (label); - } + label = g_strdup_printf ("vtable[%u]", i); - trailer = methods + vth->vtable_size; - } + gum_module_metadata_collect_function (self, label, + gum_resolve_relative_direct_ptr (&method->impl), type); - if (GUM_TYPE_FLAGS_CLASS_HAS_OVERRIDE_TABLE (type_flags)) - { - const GumOverrideTableHeader * oth; - const GumMethodOverrideDescriptor * methods; - guint32 i; + g_free (label); + } - oth = GUM_ALIGN (trailer, GumOverrideTableHeader); - methods = GUM_ALIGN ((const GumMethodOverrideDescriptor *) (oth + 1), - GumMethodOverrideDescriptor); + trailer = methods + vth->vtable_size; + } - for (i = 0; i != oth->num_entries; i++) - { - const GumMethodOverrideDescriptor * method = &methods[i]; - gchar * label; + if (GUM_TYPE_FLAGS_CLASS_HAS_OVERRIDE_TABLE (type_flags)) + { + const GumOverrideTableHeader * oth; + const GumMethodOverrideDescriptor * methods; + guint32 i; - label = g_strdup_printf ("overrides[%u]", i); + oth = GUM_ALIGN (trailer, GumOverrideTableHeader); + methods = GUM_ALIGN ((const GumMethodOverrideDescriptor *) (oth + 1), + GumMethodOverrideDescriptor); - gum_module_metadata_collect_function (module, label, - gum_resolve_relative_direct_ptr (&method->impl), type); + for (i = 0; i != oth->num_entries; i++) + { + const GumMethodOverrideDescriptor * method = &methods[i]; + gchar * label; - g_free (label); - } + label = g_strdup_printf ("overrides[%u]", i); - trailer = methods + oth->num_entries; - } + gum_module_metadata_collect_function (self, label, + gum_resolve_relative_direct_ptr (&method->impl), type); - break; - } - case GUM_CONTEXT_DESCRIPTOR_STRUCT: - { - /* TODO */ - break; - } - default: - break; + g_free (label); } - } - return TRUE; + trailer = methods + oth->num_entries; + } } static void @@ -650,17 +651,17 @@ gum_module_metadata_collect_function (GumModuleMetadata * self, GumFunctionMetadata func; const GumContextDescriptor * cur; + if (impl == NULL) + return; + scope = g_string_sized_new (16); - g_printerr ("\n>>> walking from \"%s\"\n", (char *) gum_resolve_relative_direct_ptr (&holder->name)); for (cur = gum_resolve_relative_indirectable_ptr (&holder->context.parent); cur != NULL; cur = gum_resolve_relative_indirectable_ptr (&cur->parent)) { GumContextDescriptorKind kind = GUM_DESCRIPTOR_FLAGS_KIND (cur->flags); - g_printerr ("\tcur=%p kind=%u\n", cur, GUM_DESCRIPTOR_FLAGS_KIND (cur->flags)); - switch (kind) { case GUM_CONTEXT_DESCRIPTOR_MODULE: @@ -695,16 +696,13 @@ gum_module_metadata_collect_function (GumModuleMetadata * self, break; } - g_printerr ("\t\tTODO\n"); + //g_printerr ("\t\tTODO\n"); break; } } - g_printerr ("<<<\n"); g_string_append (scope, gum_resolve_relative_direct_ptr (&holder->name)); - g_printerr (" => \"%s\"\n", scope->str); - func.name = g_strdup_printf ( "%s.%s(%s+0x%" G_GINT64_MODIFIER "x)", scope->str,