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 19, 2023
1 parent 33d8d0a commit 5c1e6cf
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions gum/gumswiftapiresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -648,6 +644,7 @@ gum_module_metadata_collect_class (GumModuleMetadata * self,
}

trailer = methods + oth->num_entries;
#endif
}
#endif
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
{
/*
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c1e6cf

Please sign in to comment.