diff --git a/gum/gumswiftapiresolver.c b/gum/gumswiftapiresolver.c index 4107b91c6..c3aa22dda 100644 --- a/gum/gumswiftapiresolver.c +++ b/gum/gumswiftapiresolver.c @@ -21,7 +21,6 @@ #include "gumprocess.h" #include -#include /* temporary */ #define GUM_DESCRIPTOR_FLAGS_KIND(flags) \ (flags & 0x1f) @@ -86,6 +85,7 @@ struct _GumModuleMetadata const gchar * name; const gchar * path; + GumAddress base_address; GArray * functions; GumSwiftApiResolver * resolver; }; @@ -279,6 +279,7 @@ gum_swift_api_resolver_init (GumSwiftApiResolver * self) module->ref_count = 2; module->name = d->name; module->path = d->path; + module->base_address = d->range->base_address; module->functions = NULL; module->resolver = self; @@ -460,8 +461,6 @@ gum_module_metadata_unref (GumModuleMetadata * module) } } -static GumAddress the_base; - static GArray * gum_module_metadata_get_functions (GumModuleMetadata * self) { @@ -470,19 +469,10 @@ gum_module_metadata_get_functions (GumModuleMetadata * self) self->functions = g_array_new (FALSE, FALSE, sizeof (GumFunctionMetadata)); g_array_set_clear_func (self->functions, (GDestroyNotify) gum_function_metadata_free); - g_printerr ("sizeof (GumContextDescriptor) == %zu\n", sizeof (GumContextDescriptor)); - g_printerr ("sizeof (GumTypeContextDescriptor) == %zu\n", sizeof (GumTypeContextDescriptor)); - g_printerr ("sizeof (GumClassDescriptor) == %zu\n", sizeof (GumClassDescriptor)); - g_printerr ("offsetof (GumClassDescriptor, target_type) == %zu\n", G_STRUCT_OFFSET (GumClassDescriptor, target_type)); - g_printerr ("offsetof (GumClassDescriptor, superclass_type) == %zu\n", G_STRUCT_OFFSET (GumClassDescriptor, superclass_type)); - g_printerr ("collecting exports of %s\n", self->path); - the_base = gum_module_find_base_address (self->path); gum_module_enumerate_sections (self->path, gum_module_metadata_collect_section, self); - g_printerr (">>>\n"); gum_module_enumerate_exports (self->path, gum_module_metadata_collect_export, self); - g_printerr ("<<<\n"); } return self->functions; @@ -513,8 +503,6 @@ gum_module_metadata_collect_section (const GumSectionDetails * details, descriptor_flags = type->target_ctx.flags; name = gum_resolve_relative_direct_ptr (&type->name); - g_printerr ("\n=== %s\n", name); - g_printerr ("\tflags=0x%08x\n", descriptor_flags); switch (GUM_DESCRIPTOR_FLAGS_KIND (descriptor_flags)) { @@ -579,7 +567,6 @@ gum_module_metadata_collect_section (const GumSectionDetails * details, } } - g_printerr ("\tclass offset=0x%x\n", (int) (GUM_ADDRESS (cd) - the_base)); if (GUM_TYPE_FLAGS_CLASS_HAS_VTABLE (type_flags)) { const GumVTableDescriptorHeader * vth; @@ -590,17 +577,22 @@ gum_module_metadata_collect_section (const GumSectionDetails * details, methods = GUM_ALIGN ((const GumMethodDescriptor *) (vth + 1), GumMethodDescriptor); - g_printerr ("\tvtable offset: 0x%x\n", vth->vtable_offset); - g_printerr ("\tvtable size: 0x%x\n", vth->vtable_size); - for (i = 0; i != vth->vtable_size; i++) { const GumMethodDescriptor * method = &methods[i]; + gconstpointer impl; + GumFunctionMetadata func; + + impl = gum_resolve_relative_direct_ptr (&method->impl); - g_printerr ("\t\tmethods[%u]: 0x%08x, %p\n", + func.name = g_strdup_printf ( + "%s.vtable[%u](%s+0x%" G_GINT64_MODIFIER "x)", + name, i, - method->flags, - gum_resolve_relative_direct_ptr (&method->impl)); + module->name, + GUM_ADDRESS (impl) - module->base_address); + func.address = GUM_ADDRESS (impl); + g_array_append_val (module->functions, func); } trailer = methods + vth->vtable_size; @@ -616,38 +608,32 @@ gum_module_metadata_collect_section (const GumSectionDetails * details, methods = GUM_ALIGN ((const GumMethodOverrideDescriptor *) (oth + 1), GumMethodOverrideDescriptor); - g_printerr ("\toverride_table size: 0x%x\n", oth->num_entries); - for (i = 0; i != oth->num_entries; i++) { const GumMethodOverrideDescriptor * method = &methods[i]; + gconstpointer impl; + GumFunctionMetadata func; + + impl = gum_resolve_relative_direct_ptr (&method->impl); - g_printerr ("\t\tmethods[%u]: %p\n", + func.name = g_strdup_printf ( + "%s.overrides[%u](%s+0x%" G_GINT64_MODIFIER "x)", + name, i, - gum_resolve_relative_direct_ptr (&method->impl)); + module->name, + GUM_ADDRESS (impl) - module->base_address); + func.address = GUM_ADDRESS (impl); + g_array_append_val (module->functions, func); } trailer = methods + oth->num_entries; } -#if 0 - static int count = 0; - count++; - if (count == 3) - { - g_printerr ("Waiting for debugger in PID %u...\n", getpid ()); - while (!gum_process_is_debugger_attached ()) - { - g_usleep (G_USEC_PER_SEC); - } - } -#endif - break; } case GUM_CONTEXT_DESCRIPTOR_STRUCT: { - g_printerr ("\t[struct] %s\n", name); + /* TODO */ break; } default: diff --git a/tests/core/apiresolver.c b/tests/core/apiresolver.c index dca573e61..70f8fc713 100644 --- a/tests/core/apiresolver.c +++ b/tests/core/apiresolver.c @@ -245,6 +245,8 @@ TESTCASE (objc_method_can_be_resolved_from_instance_method_address) g_free (method); } +#include + TESTCASE (swift_method_can_be_resolved) { GumAddress address; @@ -259,9 +261,19 @@ TESTCASE (swift_method_can_be_resolved) g_printerr (">>>\n"); gum_api_resolver_enumerate_matches (fixture->resolver, - "*CoreDevice!*RSDDeviceInfo*", resolve_method_impl, &address, &error); + "*CoreDevice!*RemoteDevice*", resolve_method_impl, &address, &error); + //"*CoreDevice!*RSDDeviceInfo*", resolve_method_impl, &address, &error); + //"*hello*!*", resolve_method_impl, &address, &error); g_printerr ("<<<\n"); g_assert_no_error (error); + +#if 0 + g_printerr ("Waiting for debugger in PID %u...\n", getpid ()); + while (!gum_process_is_debugger_attached ()) + { + g_usleep (G_USEC_PER_SEC); + } +#endif } static gboolean