-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df808e8
commit ee06075
Showing
10 changed files
with
225 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface LCJITLessSetupViewController : UIViewController | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#import "LCJITLessSetupViewController.h" | ||
#import "LCUtils.h" | ||
#import "UIKitPrivate.h" | ||
|
||
@implementation LCJITLessSetupViewController | ||
|
||
- (void)showDialogTitle:(NSString *)title message:(NSString *)message handler:(void(^)(UIAlertAction *))handler { | ||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:title | ||
message:message | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:handler]; | ||
[alert addAction:okAction]; | ||
[self presentViewController:alert animated:YES completion:nil]; | ||
} | ||
|
||
- (void)loadView { | ||
[super loadView]; | ||
self.view.backgroundColor = UIColor.systemBackgroundColor; | ||
self.title = @"LiveContainer JIT-less setup"; | ||
|
||
if (!LCUtils.storeCertPassword) { | ||
[self showDialogTitle:@"Error" message:@"Failed to find certificate password" handler:nil]; | ||
return; | ||
} | ||
|
||
[LCUtils updateCertPassword]; | ||
[LCUtils changeMainExecutableTo:@"LiveContainer_PleaseDoNotShortenTheExecutableNameBecauseItIsUsedToReserveSpaceForOverwritingThankYou"]; | ||
|
||
NSError *error; | ||
NSURL *url = [LCUtils archiveIPAWithError:&error]; | ||
if (!url) { | ||
[self showDialogTitle:@"Error" message:error.localizedDescription handler:nil]; | ||
return; | ||
} | ||
|
||
[self showDialogTitle:@"Instruction" message:@"Done. Press OK to finish setting up." | ||
handler:^(UIAlertAction * action) { | ||
[UIApplication.sharedApplication openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sidestore://install?url=%@", url]] options:@{} completionHandler:nil]; | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface PKZipArchiver : NSObject | ||
|
||
- (NSData *)zippedDataForURL:(NSURL *)url; | ||
|
||
@end | ||
|
||
@interface LCUtils : NSObject | ||
|
||
+ (NSString *)certPassword; | ||
+ (void)updateCertPassword; | ||
+ (NSData *)storeCertPassword; | ||
|
||
+ (BOOL)isAppGroupSideStore; | ||
+ (NSError *)changeMainExecutableTo:(NSString *)exec; | ||
|
||
+ (NSURL *)archiveIPAWithError:(NSError **)error; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#import "LCUtils.h" | ||
#include <dlfcn.h> | ||
|
||
@implementation LCUtils | ||
|
||
#pragma mark Certificate password | ||
|
||
+ (NSString *)storeCertPassword { | ||
NSDictionary *dict = @{ | ||
(id)kSecClass: (id)kSecClassGenericPassword, | ||
(id)kSecAttrService: @"com.SideStore.SideStore", | ||
(id)kSecAttrAccount: @"signingCertificatePassword", | ||
(id)kSecAttrSynchronizable: (id)kSecAttrSynchronizableAny, | ||
(id)kSecMatchLimit: (id)kSecMatchLimitOne, | ||
(id)kSecReturnData: (id)kCFBooleanTrue | ||
}; | ||
CFTypeRef result = nil; | ||
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dict, &result); | ||
if (status == errSecSuccess) { | ||
return [[NSString alloc] initWithData:(__bridge NSData *)result encoding:NSUTF8StringEncoding]; | ||
} else { | ||
return nil; | ||
} | ||
} | ||
|
||
+ (void)updateCertPassword { | ||
[NSUserDefaults.standardUserDefaults setObject:self.storeCertPassword forKey:@"LCCertificateID"]; | ||
} | ||
|
||
+ (NSString *)certPassword { | ||
return [NSUserDefaults.standardUserDefaults objectForKey:@"LCCertificateID"]; | ||
} | ||
|
||
#pragma mark Setup | ||
|
||
+ (NSString *)appGroupID { | ||
return [NSBundle.mainBundle.infoDictionary[@"ALTAppGroups"] firstObject]; | ||
} | ||
|
||
+ (BOOL)isAppGroupSideStore { | ||
return [self.appGroupID containsString:@"com.SideStore.SideStore"]; | ||
} | ||
|
||
+ (NSError *)changeMainExecutableTo:(NSString *)exec { | ||
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; | ||
|
||
infoDict[@"CFBundleExecutable"] = exec; | ||
[infoDict writeToURL:infoPath error:&error]; | ||
return error; | ||
} | ||
|
||
+ (NSURL *)archiveIPAWithError:(NSError **)error { | ||
NSFileManager *manager = NSFileManager.defaultManager; | ||
NSURL *appGroupPath = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupID]; | ||
NSURL *bundlePath = [appGroupPath URLByAppendingPathComponent:@"Apps/com.kdt.livecontainer"]; | ||
|
||
NSURL *tmpPath = [appGroupPath URLByAppendingPathComponent:@"tmp"]; | ||
[manager removeItemAtURL:tmpPath error:nil]; | ||
|
||
NSURL *tmpPayloadPath = [tmpPath URLByAppendingPathComponent:@"Payload"]; | ||
NSURL *tmpIPAPath = [appGroupPath URLByAppendingPathComponent:@"tmp.ipa"]; | ||
|
||
[manager createDirectoryAtURL:tmpPath withIntermediateDirectories:YES attributes:nil error:error]; | ||
if (*error) return nil; | ||
|
||
[manager copyItemAtURL:bundlePath toURL:tmpPayloadPath error:error]; | ||
if (*error) return nil; | ||
|
||
dlopen("/System/Library/PrivateFrameworks/PassKitCore.framework/PassKitCore", RTLD_GLOBAL); | ||
NSData *zipData = [[NSClassFromString(@"PKZipArchiver") new] zippedDataForURL:tmpPayloadPath.URLByDeletingLastPathComponent]; | ||
if (!zipData) return nil; | ||
|
||
[manager removeItemAtURL:tmpPath error:error]; | ||
if (*error) return nil; | ||
|
||
[zipData writeToURL:tmpIPAPath options:0 error:error]; | ||
if (*error) return nil; | ||
|
||
return tmpIPAPath; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>application-identifier</key> | ||
<string>com.kdt.livecontainer</string> | ||
<key>get-task-allow</key> | ||
<true/> | ||
<!-- Optional entitlements --> | ||
<key>com.apple.developer.kernel.extended-virtual-addressing</key> | ||
<true/> | ||
<key>com.apple.developer.kernel.increased-memory-limit</key> | ||
<true/> | ||
<key>application-identifier</key> | ||
<string>com.kdt.livecontainer</string> | ||
<key>com.apple.developer.kernel.extended-virtual-addressing</key> | ||
<true/> | ||
<key>com.apple.developer.kernel.increased-memory-limit</key> | ||
<true/> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>group.com.SideStore.SideStore</string> | ||
</array> | ||
<key>get-task-allow</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>application-identifier</key> | ||
<string>com.kdt.livecontainer</string> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>group.com.SideStore.SideStore</string> | ||
</array> | ||
<key>get-task-allow</key> | ||
<true/> | ||
<key>keychain-access-groups</key> | ||
<array> | ||
<string>group.*</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters