Skip to content

Commit

Permalink
[WIP] Handle resilient superclasses
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 744fab9 commit 4a8c27e
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions gum/gumswiftapiresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
((flags & GUM_CLASS_HAS_VTABLE) != 0)
#define GUM_TYPE_FLAGS_CLASS_HAS_OVERRIDE_TABLE(flags) \
((flags & GUM_CLASS_HAS_OVERRIDE_TABLE) != 0)
#define GUM_TYPE_FLAGS_CLASS_HAS_RESILIENT_SUPERCLASS(flags) \
((flags & GUM_CLASS_HAS_RESILIENT_SUPERCLASS) != 0)

#define GUM_GENERIC_DESCRIPTOR_FLAGS_HAS_TYPE_PACKS(flags) \
((flags & GUM_GENERIC_DESCRIPTOR_HAS_TYPE_PACKS) != 0)
Expand Down Expand Up @@ -70,6 +72,7 @@ typedef struct _GumGenericParamDescriptor GumGenericParamDescriptor;
typedef struct _GumGenericRequirementDescriptor GumGenericRequirementDescriptor;
typedef struct _GumTypeGenericContextDescriptorHeader
GumTypeGenericContextDescriptorHeader;
typedef struct _GumResilientSuperclass GumResilientSuperclass;
typedef struct _GumSingletonMetadataInitialization GumSingletonMetadataInitialization;
typedef struct _GumForeignMetadataInitialization GumForeignMetadataInitialization;
typedef struct _GumVTableDescriptorHeader GumVTableDescriptorHeader;
Expand Down Expand Up @@ -151,8 +154,9 @@ enum _GumAnonymousContextDescriptorFlags

enum _GumTypeContextDescriptorFlags
{
GUM_CLASS_HAS_VTABLE = (1 << 15),
GUM_CLASS_HAS_OVERRIDE_TABLE = (1 << 14),
GUM_CLASS_HAS_VTABLE = (1 << 15),
GUM_CLASS_HAS_OVERRIDE_TABLE = (1 << 14),
GUM_CLASS_HAS_RESILIENT_SUPERCLASS = (1 << 13),
};

enum _GumTypeMetadataInitializationKind
Expand Down Expand Up @@ -231,6 +235,11 @@ struct _GumTypeGenericContextDescriptorHeader
GumGenericContextDescriptorHeader base;
};

struct _GumResilientSuperclass
{
GumRelativeDirectPtr superclass;
};

struct _GumSingletonMetadataInitialization
{
GumRelativeDirectPtr initialization_cache;
Expand Down Expand Up @@ -312,6 +321,8 @@ static void gum_skip_generic_type_trailers (gconstpointer * trailer_ptr,
const GumTypeContextDescriptor * t);
static void gum_skip_generic_parts (gconstpointer * trailer_ptr,
const GumGenericContextDescriptorHeader * h);
static void gum_skip_resilient_superclass_trailer (gconstpointer * trailer_ptr,
const GumTypeContextDescriptor * t);
static void gum_skip_metadata_initialization_trailers (
gconstpointer * trailer_ptr, const GumTypeContextDescriptor * t);

Expand Down Expand Up @@ -980,6 +991,8 @@ gum_class_parse (GumClass * klass,

gum_skip_generic_type_trailers (&trailer, type);

gum_skip_resilient_superclass_trailer (&trailer, type);

gum_skip_metadata_initialization_trailers (&trailer, type);

type_flags = GUM_DESCRIPTOR_FLAGS_KIND_FLAGS (type->context.flags);
Expand Down Expand Up @@ -1221,6 +1234,23 @@ gum_skip_generic_parts (gconstpointer * trailer_ptr,
*trailer_ptr = trailer;
}

static void
gum_skip_resilient_superclass_trailer (gconstpointer * trailer_ptr,
const GumTypeContextDescriptor * t)
{
gconstpointer trailer = *trailer_ptr;

if (GUM_TYPE_FLAGS_CLASS_HAS_RESILIENT_SUPERCLASS (
GUM_DESCRIPTOR_FLAGS_KIND_FLAGS (t->context.flags)))
{
const GumResilientSuperclass * rs =
GUM_ALIGN (trailer, GumResilientSuperclass);
trailer = rs + 1;
}

*trailer_ptr = trailer;
}

static void
gum_skip_metadata_initialization_trailers (gconstpointer * trailer_ptr,
const GumTypeContextDescriptor * t)
Expand Down

0 comments on commit 4a8c27e

Please sign in to comment.