From 42a0959f16a519edc700b2be9381c4e81efe3658 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Wed, 24 Apr 2024 13:56:52 +0700 Subject: [PATCH] Fix Could not find certificate as SideStore bundle ID format changed --- LCJITLessSetupViewController.m | 3 +-- LCRootViewController.m | 3 +-- LCUtils.h | 3 +-- LCUtils.m | 36 ++++++++++++++++++++++++++++------ Resources/Info.plist | 2 ++ entitlements_setup.xml | 2 +- 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/LCJITLessSetupViewController.m b/LCJITLessSetupViewController.m index e8825af..4befe89 100644 --- a/LCJITLessSetupViewController.m +++ b/LCJITLessSetupViewController.m @@ -30,10 +30,9 @@ - (void)loadView { } LCUtils.certificateData = certData; - [LCUtils changeMainExecutableTo:@"LiveContainer_PleaseDoNotShortenTheExecutableNameBecauseItIsUsedToReserveSpaceForOverwritingThankYou"]; NSError *error; - NSURL *url = [LCUtils archiveIPAWithError:&error]; + NSURL *url = [LCUtils archiveIPAWithSetupMode:NO error:&error]; if (!url) { [self showDialogTitle:@"Error" message:error.localizedDescription handler:nil]; return; diff --git a/LCRootViewController.m b/LCRootViewController.m index 317a3bf..8a7e2b8 100644 --- a/LCRootViewController.m +++ b/LCRootViewController.m @@ -201,9 +201,8 @@ - (void)setupJITLessTapped { return; } - [LCUtils changeMainExecutableTo:@"JITLessSetup"]; NSError *error; - NSURL *url = [LCUtils archiveIPAWithError:&error]; + NSURL *url = [LCUtils archiveIPAWithSetupMode:YES error:&error]; if (!url) { [self showDialogTitle:@"Error" message:error.localizedDescription]; return; diff --git a/LCUtils.h b/LCUtils.h index efd594c..59e92ab 100644 --- a/LCUtils.h +++ b/LCUtils.h @@ -16,8 +16,7 @@ + (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL success, NSError *error))completionHandler; + (BOOL)isAppGroupSideStore; -+ (NSError *)changeMainExecutableTo:(NSString *)exec; -+ (NSURL *)archiveIPAWithError:(NSError **)error; ++ (NSURL *)archiveIPAWithSetupMode:(BOOL)setup error:(NSError **)error; @end diff --git a/LCUtils.m b/LCUtils.m index 6ec319a..d5ce16a 100644 --- a/LCUtils.m +++ b/LCUtils.m @@ -162,19 +162,43 @@ + (BOOL)isAppGroupSideStore { return [self.appGroupID containsString:@"com.SideStore.SideStore"]; } -+ (NSError *)changeMainExecutableTo:(NSString *)exec { - NSError *error; ++ (void)changeMainExecutableTo:(NSString *)exec error:(NSError **)error { NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID]; NSURL *infoPath = [appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer/App.app/Info.plist"]; NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfURL:infoPath]; - if (!infoDict) return nil; + if (!infoDict) return; infoDict[@"CFBundleExecutable"] = exec; - [infoDict writeToURL:infoPath error:&error]; - return error; + [infoDict writeToURL:infoPath error:error]; +} + ++ (void)writeStoreIDToSetupExecutableWithError:(NSError **)error { + NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID]; + NSURL *execPath = [appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer/App.app/JITLessSetup"]; + NSMutableData *data = [NSMutableData dataWithContentsOfURL:execPath options:0 error:error]; + if (!data) return; + + NSData *findPattern = [@"KeychainAccessGroupWillBeWrittenByLiveContainerAAAAAAAAAAAAAAAAAAAA" dataUsingEncoding:NSUTF8StringEncoding]; + NSRange range = [data rangeOfData:findPattern options:0 range:NSMakeRange(0, data.length)]; + if (range.location == NSNotFound) return; + + memset((char *)data.mutableBytes + range.location, ' ', range.length); + NSString *replacement = [NSString stringWithFormat:@"%@", self.appGroupID]; + assert(replacement.length < range.length); + memcpy((char *)data.mutableBytes + range.location, replacement.UTF8String, replacement.length); + [data writeToURL:execPath options:0 error:error]; } -+ (NSURL *)archiveIPAWithError:(NSError **)error { ++ (NSURL *)archiveIPAWithSetupMode:(BOOL)setup error:(NSError **)error { + if (setup) { + [self writeStoreIDToSetupExecutableWithError:error]; + if (*error) return nil; + [self changeMainExecutableTo:@"JITLessSetup" error:error]; + } else { + [self changeMainExecutableTo:@"LiveContainer_PleaseDoNotShortenTheExecutableNameBecauseItIsUsedToReserveSpaceForOverwritingThankYou" error:error]; + } + if (*error) return nil; + NSFileManager *manager = NSFileManager.defaultManager; NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID]; NSURL *bundlePath = [appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer"]; diff --git a/Resources/Info.plist b/Resources/Info.plist index 48a12f9..b121d28 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -160,6 +160,8 @@ 1 2 + UIFileSharingEnabled + UILaunchImageFile LaunchImage UILaunchImages diff --git a/entitlements_setup.xml b/entitlements_setup.xml index fa8aad2..3d073c1 100644 --- a/entitlements_setup.xml +++ b/entitlements_setup.xml @@ -12,7 +12,7 @@ keychain-access-groups - group.* + KeychainAccessGroupWillBeWrittenByLiveContainerAAAAAAAAAAAAAAAAAAAA