Skip to content

Commit

Permalink
Fix Could not find certificate as SideStore bundle ID format changed
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Apr 24, 2024
1 parent ebea623 commit 42a0959
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
3 changes: 1 addition & 2 deletions LCJITLessSetupViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions LCRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions LCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 30 additions & 6 deletions LCUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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</string>" 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:@"%@</string>", 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"];
Expand Down
2 changes: 2 additions & 0 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIFileSharingEnabled</key>
<true/>
<key>UILaunchImageFile</key>
<string>LaunchImage</string>
<key>UILaunchImages</key>
Expand Down
2 changes: 1 addition & 1 deletion entitlements_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<true/>
<key>keychain-access-groups</key>
<array>
<string>group.*</string>
<string>KeychainAccessGroupWillBeWrittenByLiveContainerAAAAAAAAAAAAAAAAAAAA</string>
</array>
</dict>
</plist>

0 comments on commit 42a0959

Please sign in to comment.