From acf9afa67c8d41c35981981d925450cd206a1551 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Tue, 2 Jan 2024 10:55:51 -0800 Subject: [PATCH] o Fix issue with exception handling o Fix alignment issues with entitlment parsing --- app/AppGroup.m | 25 +++++++++++-------- app/main.m | 1 - .../xcshareddata/xcschemes/iSH.xcscheme | 23 +++++++++++++++-- main.c | 2 +- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/app/AppGroup.m b/app/AppGroup.m index 228bf8d91e..2d4142b27a 100644 --- a/app/AppGroup.m +++ b/app/AppGroup.m @@ -15,22 +15,22 @@ #define CSMAGIC_EMBEDDED_SIGNATURE 0xfade0cc0 #define CSMAGIC_EMBEDDED_ENTITLEMENTS 0xfade7171 -struct cs_blob_index { +struct __attribute__((packed)) cs_blob_index { uint32_t type; uint32_t offset; }; -struct cs_superblob { +struct __attribute__((packed)) cs_superblob { uint32_t magic; uint32_t length; uint32_t count; - struct cs_blob_index index[]; + struct cs_blob_index index[]; // This must be handled carefully since it's a flexible array member. }; -struct cs_entitlements { +struct __attribute__((packed)) cs_entitlements { uint32_t magic; uint32_t length; - char entitlements[]; + char entitlements[]; // This must be handled carefully since it's a flexible array member. }; static NSDictionary *AppEntitlements(void) { @@ -78,17 +78,22 @@ NSData *entitlementsData = nil; for (uint32_t i = 0; i < ntohl(cs->count); i++) { - struct cs_entitlements *ents = (void *) ((char *) cs + ntohl(cs->index[i].offset)); + uint32_t offset = ntohl(cs->index[i].offset); + const struct cs_entitlements *ents = (const struct cs_entitlements *)((const char *)cs + offset); - // Read the magic number in a way that does not assume alignment uint32_t magic; memcpy(&magic, &ents->magic, sizeof(uint32_t)); - if (ntohl(ents->magic) == CSMAGIC_EMBEDDED_ENTITLEMENTS) { - entitlementsData = [NSData dataWithBytes:ents->entitlements length:ntohl(ents->length) - offsetof(struct cs_entitlements, entitlements)]; + magic = ntohl(magic); + + if (magic == CSMAGIC_EMBEDDED_ENTITLEMENTS) { + uint32_t length; + memcpy(&length, &ents->length, sizeof(uint32_t)); + length = ntohl(length); + + entitlementsData = [NSData dataWithBytes:ents->entitlements length:length - offsetof(struct cs_entitlements, entitlements)]; break; // Entitlements found } } - if (entitlementsData == nil) return; diff --git a/app/main.m b/app/main.m index 832ea69860..eed7af5d4a 100644 --- a/app/main.m +++ b/app/main.m @@ -19,7 +19,6 @@ int main(int argc, char * argv[]) { int retVal = 0; @try { - // Your existing setup code here retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } @catch (NSException *exception) { diff --git a/iSH-AOK.xcodeproj/xcshareddata/xcschemes/iSH.xcscheme b/iSH-AOK.xcodeproj/xcshareddata/xcschemes/iSH.xcscheme index 33f18b8a60..ef9658efb6 100644 --- a/iSH-AOK.xcodeproj/xcshareddata/xcschemes/iSH.xcscheme +++ b/iSH-AOK.xcodeproj/xcshareddata/xcschemes/iSH.xcscheme @@ -92,8 +92,7 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" enableASanStackUseAfterReturn = "YES" - disableMainThreadChecker = "YES" - disablePerformanceAntipatternChecker = "YES" + enableUBSanitizer = "YES" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" @@ -114,6 +113,26 @@ + + + + + + + +