From 4a8c27eea0eb91c3c030dad8c2d78879784d2d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Wed, 20 Sep 2023 15:01:36 +0200 Subject: [PATCH] [WIP] Handle resilient superclasses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Håvard Sørbø --- gum/gumswiftapiresolver.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/gum/gumswiftapiresolver.c b/gum/gumswiftapiresolver.c index a4c2f4e84..d3ef04243 100644 --- a/gum/gumswiftapiresolver.c +++ b/gum/gumswiftapiresolver.c @@ -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) @@ -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; @@ -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 @@ -231,6 +235,11 @@ struct _GumTypeGenericContextDescriptorHeader GumGenericContextDescriptorHeader base; }; +struct _GumResilientSuperclass +{ + GumRelativeDirectPtr superclass; +}; + struct _GumSingletonMetadataInitialization { GumRelativeDirectPtr initialization_cache; @@ -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); @@ -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); @@ -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)