Skip to content

Commit

Permalink
Fix AltStore handling
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Aug 30, 2024
1 parent 10a49ba commit 2f49011
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion LiveContainerUI/LCSettingsListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)setupJITLessPressed {
}

- (void)copyAppGroupPathPressed {
UIPasteboard.generalPasteboard.string = LCUtils.appGroupPath;
UIPasteboard.generalPasteboard.string = LCUtils.appGroupPath.path;
}

- (void)copyDocumentsPathPressed {
Expand Down
2 changes: 1 addition & 1 deletion LiveContainerUI/LCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void LCPatchExecSlice(const char *path, struct mach_header_64 *header);
+ (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL success, NSError *error))completionHandler;

+ (BOOL)isAppGroupAltStoreLike;
+ (NSString *)appGroupPath;
+ (NSURL *)appGroupPath;
+ (NSString *)storeInstallURLScheme;

@end
39 changes: 23 additions & 16 deletions LiveContainerUI/LCUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ @implementation LCUtils

#pragma mark Certificate & password

+ (NSString *)appGroupPath {
return [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID].path;
+ (NSURL *)appGroupPath {
return [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
}

+ (BOOL)deleteKeychainItem:(NSString *)key ofStore:(NSString *)store {
Expand Down Expand Up @@ -50,8 +50,7 @@ + (NSData *)certificateDataFile {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"LCIgnoreALTCertificate"]) {
return nil;
}
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
NSURL *url = [appGroupPath URLByAppendingPathComponent:[NSString stringWithFormat:@"Apps/%@/App.app/ALTCertificate.p12", self.storeBundleID]];
NSURL *url = [self.storeBundlePath URLByAppendingPathComponent:@"ALTCertificate.p12"];
return [NSData dataWithContentsOfURL:url];
}

Expand Down Expand Up @@ -115,9 +114,7 @@ + (NSString *)storeBundleID {
}

+ (NSURL *)storeBundlePath {
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
appGroupPath = [appGroupPath URLByAppendingPathComponent:[NSString stringWithFormat:@"Apps/%@/App.app", self.storeBundleID]];
return appGroupPath;
return [self.appGroupPath URLByAppendingPathComponent:[NSString stringWithFormat:@"Apps/%@/App.app", self.storeBundleID]];
}

+ (NSString *)storeInstallURLScheme {
Expand Down Expand Up @@ -202,7 +199,20 @@ + (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL suc
#pragma mark Setup

+ (NSString *)appGroupID {
return [NSBundle.mainBundle.infoDictionary[@"ALTAppGroups"] firstObject];
static dispatch_once_t once;
static NSString *appGroupID;
dispatch_once(&once, ^{
for (NSString *group in NSBundle.mainBundle.infoDictionary[@"ALTAppGroups"]) {
NSURL *path = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:group];
NSURL *bundlePath = [path URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer/App.app"];
if ([NSFileManager.defaultManager fileExistsAtPath:bundlePath.path]) {
// This will fail if LiveContainer is installed in both stores, but it should never be the case
appGroupID = group;
return;
}
}
});
return appGroupID;
}

+ (BOOL)isAppGroupAltStoreLike {
Expand All @@ -211,8 +221,7 @@ + (BOOL)isAppGroupAltStoreLike {
}

+ (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"];
NSURL *infoPath = [self.appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer/App.app/Info.plist"];
NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfURL:infoPath];
if (!infoDict) return;

Expand All @@ -221,8 +230,7 @@ + (void)changeMainExecutableTo:(NSString *)exec error:(NSError **)error {
}

+ (void)writeStoreIDToSetupExecutableWithError:(NSError **)error {
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
NSURL *execPath = [appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer/App.app/JITLessSetup"];
NSURL *execPath = [self.appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer/App.app/JITLessSetup"];
NSMutableData *data = [NSMutableData dataWithContentsOfURL:execPath options:0 error:error];
if (!data) return;

Expand Down Expand Up @@ -255,14 +263,13 @@ + (NSURL *)archiveIPAWithSetupMode:(BOOL)setup error:(NSError **)error {
if (*error) return nil;

NSFileManager *manager = NSFileManager.defaultManager;
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID];
NSURL *bundlePath = [appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer"];
NSURL *bundlePath = [self.appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer"];

NSURL *tmpPath = [appGroupPath URLByAppendingPathComponent:@"tmp"];
NSURL *tmpPath = [self.appGroupPath URLByAppendingPathComponent:@"tmp"];
[manager removeItemAtURL:tmpPath error:nil];

NSURL *tmpPayloadPath = [tmpPath URLByAppendingPathComponent:@"Payload"];
NSURL *tmpIPAPath = [appGroupPath URLByAppendingPathComponent:@"tmp.ipa"];
NSURL *tmpIPAPath = [self.appGroupPath URLByAppendingPathComponent:@"tmp.ipa"];

[manager createDirectoryAtURL:tmpPath withIntermediateDirectories:YES attributes:nil error:error];
if (*error) return nil;
Expand Down
2 changes: 2 additions & 0 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
</array>
<key>CFBundleVersion</key>
<string>2.1.2</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sidestore</string>
Expand Down
1 change: 1 addition & 0 deletions entitlements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.SideStore.SideStore</string>
<string>group.com.rileytestut.AltStore</string>
</array>
<key>get-task-allow</key>
<true/>
Expand Down

0 comments on commit 2f49011

Please sign in to comment.