Skip to content

Commit

Permalink
[WIP] Wire up some more
Browse files Browse the repository at this point in the history
Co-authored-by: Håvard Sørbø <[email protected]>
  • Loading branch information
oleavr and hsorbo committed Sep 20, 2023
1 parent 8438cc6 commit 744fab9
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions gum/gumswiftapiresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 744fab9

Please sign in to comment.