Skip to content

Commit

Permalink
impelement #19
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeBlack committed Dec 22, 2024
1 parent 8b8443a commit 34998af
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 107 deletions.
1 change: 1 addition & 0 deletions LCSharedUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import Foundation;

@interface LCSharedUtils : NSObject
+ (NSString*) teamIdentifier;
+ (NSString *)appGroupID;
+ (NSURL*) appGroupPath;
+ (NSString *)certificatePassword;
Expand Down
14 changes: 11 additions & 3 deletions LCSharedUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@

@implementation LCSharedUtils

+ (NSString*) teamIdentifier {
static NSString* ans = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
ans = [[lcMainBundle.bundleIdentifier componentsSeparatedByString:@"."] lastObject];
});
return ans;
}

+ (NSString *)appGroupID {
static dispatch_once_t once;
static NSString *appGroupID = @"group.com.SideStore.SideStore";
dispatch_once(&once, ^{
NSString* teamIdentifier = [[lcMainBundle.bundleIdentifier componentsSeparatedByString:@"."] lastObject];
NSArray* possibleAppGroups = @[
[@"group.com.SideStore.SideStore." stringByAppendingString:teamIdentifier],
[@"group.com.rileytestut.AltStore." stringByAppendingString:teamIdentifier]
[@"group.com.SideStore.SideStore." stringByAppendingString:[self teamIdentifier]],
[@"group.com.rileytestut.AltStore." stringByAppendingString:[self teamIdentifier]]
];

for (NSString *group in possibleAppGroups) {
Expand Down
8 changes: 6 additions & 2 deletions LiveContainerSwiftUI/LCAppInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ - (void)patchExecAndSignIfNeedWithCompletionHandler:(void(^)(bool success, NSStr
int signRevision = 1;

NSDate* expirationDate = info[@"LCExpirationDate"];
if(expirationDate && [[[NSUserDefaults alloc] initWithSuiteName:[LCUtils appGroupID]] boolForKey:@"LCSignOnlyOnExpiration"] && !forceSign) {
NSString* teamId = info[@"LCTeamId"];
if(expirationDate && [teamId isEqualToString:[LCUtils teamIdentifier]] && [[[NSUserDefaults alloc] initWithSuiteName:[LCUtils appGroupID]] boolForKey:@"LCSignOnlyOnExpiration"] && !forceSign) {
if([expirationDate laterDate:[NSDate now]] == expirationDate) {
// not expired yet, don't sign again
completetionHandler(YES, nil);
Expand Down Expand Up @@ -280,7 +281,7 @@ - (void)patchExecAndSignIfNeedWithCompletionHandler:(void(^)(bool success, NSStr
[info removeObjectForKey:@"LCBundleExecutable"];
[info removeObjectForKey:@"LCBundleIdentifier"];

void (^signCompletionHandler)(BOOL success, NSDate* expirationDate, NSError *error) = ^(BOOL success, NSDate* expirationDate, NSError *_Nullable error) {
void (^signCompletionHandler)(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *error) = ^(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *_Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
info[@"LCJITLessSignID"] = @(signID);
Expand All @@ -293,6 +294,9 @@ - (void)patchExecAndSignIfNeedWithCompletionHandler:(void(^)(bool success, NSStr
if(success && expirationDate) {
info[@"LCExpirationDate"] = expirationDate;
}
if(success && teamId) {
info[@"LCTeamId"] = teamId;
}
// Save sign ID and restore bundle ID
[self save];

Expand Down
2 changes: 1 addition & 1 deletion LiveContainerSwiftUI/LCAppSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct LCAppSettingsView : View{
}

} else {
Text("lc.appSettings.languageLoading".loc)
Text("lc.common.loading".loc)
.onAppear() {
Task{ loadSupportedLanguages() }
}
Expand Down
135 changes: 75 additions & 60 deletions LiveContainerSwiftUI/LCJITLessDiagnoseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct LCJITLessDiagnoseView : View {
@State var certificateDataFound = false
@State var certificatePasswordFound = false
@State var appGroupAccessible = false
@State var certLastUpdateDateStr = "Unknown"
@State var certLastUpdateDateStr = "lc.common.unknown".loc

@State var isJITLessTestInProgress = false

Expand All @@ -28,69 +28,80 @@ struct LCJITLessDiagnoseView : View {
var body: some View {
if loaded {
Form {
HStack {
Text("Bundle Identifier")
Spacer()
Text(Bundle.main.bundleIdentifier ?? "Unknown")
.foregroundStyle(.gray)
}
HStack {
Text("App Group ID")
Spacer()
Text(appGroupId)
.foregroundStyle(.gray)
}
HStack {
Text("App Group Accessible")
Spacer()
Text(appGroupAccessible ? "YES" : "NO")
.foregroundStyle(.gray)
}
HStack {
Text("Store")
Spacer()
if store == .AltStore {
Text("AltStore")
Section {
HStack {
Text("lc.jitlessDiag.bundleId".loc)
Spacer()
Text(Bundle.main.bundleIdentifier ?? "lc.common.unknown".loc)
.foregroundStyle(.gray)
} else {
Text("SideStore")
}
HStack {
Text("lc.jitlessDiag.appGroupId".loc)
Spacer()
Text(appGroupId)
.foregroundStyle(.gray)
}
HStack {
Text("lc.jitlessDiag.appGroupAccessible".loc)
Spacer()
Text(appGroupAccessible ? "lc.common.yes".loc : "lc.common.no".loc)
.foregroundStyle(.gray)
}
HStack {
Text("lc.jitlessDiag.store".loc)
Spacer()
if store == .AltStore {
Text("AltStore")
.foregroundStyle(.gray)
} else {
Text("SideStore")
.foregroundStyle(.gray)
}
}
HStack {
Text("lc.jitlessDiag.patchDetected".loc)
Spacer()
Text(isPatchDetected ? "lc.common.yes".loc : "lc.common.no".loc)
.foregroundStyle(.gray)
}
}
HStack {
Text("Patch Detected")
Spacer()
Text(isPatchDetected ? "YES" : "NO")
.foregroundStyle(.gray)
}

HStack {
Text("Certificate Data Found")
Spacer()
Text(certificateDataFound ? "YES" : "NO")
.foregroundStyle(.gray)

}
HStack {
Text("Certificate Password Found")
Spacer()
Text(certificatePasswordFound ? "YES" : "NO")
.foregroundStyle(.gray)
}

HStack {
Text("Certificate Last Update Date")
Spacer()
Text(certLastUpdateDateStr)
.foregroundStyle(.gray)
HStack {
Text("lc.jitlessDiag.certDataFound".loc)
Spacer()
Text(certificateDataFound ? "lc.common.yes".loc : "lc.common.no".loc)
.foregroundStyle(.gray)

}
HStack {
Text("lc.jitlessDiag.certPassFound".loc)
Spacer()
Text(certificatePasswordFound ? "lc.common.yes".loc : "lc.common.no".loc)
.foregroundStyle(.gray)
}

HStack {
Text("lc.jitlessDiag.certLastUpdate".loc)
Spacer()
Text(certLastUpdateDateStr)
.foregroundStyle(.gray)
}

Button {
testJITLessMode()
} label: {
Text("lc.settings.testJitLess".loc)
}
.disabled(isJITLessTestInProgress)
}

Button {
testJITLessMode()
} label: {
Text("lc.settings.testJitLess".loc)
Section {
Button {
getHelp()
} label: {
Text("lc.jitlessDiag.getHelp".loc)
}
}
.disabled(isJITLessTestInProgress)

}
.navigationTitle("lc.settings.jitlessDiagnose".loc)
.navigationBarTitleDisplayMode(.inline)
Expand All @@ -114,7 +125,7 @@ struct LCJITLessDiagnoseView : View {
}

} else {
Text("Loading...")
Text("lc.common.loading".loc)
.onAppear() {
onAppear()
}
Expand All @@ -123,7 +134,7 @@ struct LCJITLessDiagnoseView : View {
}

func onAppear() {
appGroupId = LCUtils.appGroupID() ?? "Unknown"
appGroupId = LCUtils.appGroupID() ?? "lc.common.unknown".loc
store = LCUtils.store()
isPatchDetected = checkIsPatched()
appGroupAccessible = LCUtils.appGroupPath() != nil
Expand All @@ -135,7 +146,7 @@ struct LCJITLessDiagnoseView : View {
formatter1.timeStyle = .medium
certLastUpdateDateStr = formatter1.string(from: lastUpdateDate)
} else {
certLastUpdateDateStr = "Unknown"
certLastUpdateDateStr = "lc.common.unknown".loc
}


Expand Down Expand Up @@ -181,4 +192,8 @@ struct LCJITLessDiagnoseView : View {
}

}

func getHelp() {
UIApplication.shared.open(URL(string: "https://github.com/khanhduytran0/LiveContainer/issues/265")!)
}
}
2 changes: 1 addition & 1 deletion LiveContainerSwiftUI/LCSelectContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct LCSelectContainerView : View{
isPresent = false
delegate.addContainers(containers: multiSelection)
} label: {
Text("lc.common.ok".loc)
Text("lc.common.done".loc)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions LiveContainerSwiftUI/LCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ void LCPatchAltStore(const char *path, struct mach_header_64 *header);
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url;

+ (void)removeCodeSignatureFromBundleURL:(NSURL *)appURL;
+ (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSError *error))completionHandler;
+ (NSProgress *)signAppBundleWithZSign:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSError *error))completionHandler;
+ (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *error))completionHandler;
+ (NSProgress *)signAppBundleWithZSign:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *error))completionHandler;
+ (BOOL)isAppGroupAltStoreLike;
+ (Store)store;
+ (NSString *)teamIdentifier;
+ (NSString *)appGroupID;
+ (NSString *)appUrlScheme;
+ (NSURL *)appGroupPath;
Expand Down
23 changes: 13 additions & 10 deletions LiveContainerSwiftUI/LCUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import MachO;
@import UIKit;

#import "AltStoreCore/ALTSigner.h"
#import "../AltStoreCore/ALTSigner.h"
#import "LCUtils.h"
#import "LCVersionInfo.h"
#import "../ZSign/zsigner.h"
Expand All @@ -18,6 +18,9 @@ - (BOOL)safari_isHTTPFamilyURL {
@implementation LCUtils

#pragma mark Certificate & password
+ (NSString *)teamIdentifier {
return [NSClassFromString(@"LCSharedUtils") teamIdentifier];
}

+ (NSURL *)appGroupPath {
return [NSClassFromString(@"LCSharedUtils") appGroupPath];
Expand Down Expand Up @@ -160,7 +163,7 @@ + (void)removeCodeSignatureFromBundleURL:(NSURL *)appURL {
}
}

+ (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSError *error))completionHandler {
+ (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *error))completionHandler {
NSError *error;

// I'm too lazy to reimplement signer, so let's borrow everything from SideStore
Expand All @@ -170,20 +173,20 @@ + (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL suc
// Load libraries from Documents, yeah
[self loadStoreFrameworksWithError:&error];
if (error) {
completionHandler(NO, nil, error);
completionHandler(NO, nil, nil, error);
return nil;
}

ALTCertificate *cert = [[NSClassFromString(@"ALTCertificate") alloc] initWithP12Data:self.certificateData password:self.certificatePassword];
if (!cert) {
error = [NSError errorWithDomain:NSBundle.mainBundle.bundleIdentifier code:1 userInfo:@{NSLocalizedDescriptionKey: @"Failed to create ALTCertificate. Please try: 1. make sure your store is patched 2. reopen your store 3. refresh all apps"}];
completionHandler(NO, nil, error);
completionHandler(NO, nil, nil, error);
return nil;
}
ALTProvisioningProfile *profile = [[NSClassFromString(@"ALTProvisioningProfile") alloc] initWithURL:profilePath];
if (!profile) {
error = [NSError errorWithDomain:NSBundle.mainBundle.bundleIdentifier code:2 userInfo:@{NSLocalizedDescriptionKey: @"Failed to create ALTProvisioningProfile. Please try: 1. make sure your store is patched 2. reopen your store 3. refresh all apps"}];
completionHandler(NO, nil, error);
completionHandler(NO, nil, nil, error);
return nil;
}

Expand All @@ -192,13 +195,13 @@ + (NSProgress *)signAppBundle:(NSURL *)path completionHandler:(void (^)(BOOL suc
ALTSigner *signer = [[NSClassFromString(@"ALTSigner") alloc] initWithTeam:team certificate:cert];

void (^signCompletionHandler)(BOOL success, NSError *error) = ^(BOOL success, NSError *_Nullable error) {
completionHandler(success, [profile expirationDate], error);
completionHandler(success, [profile expirationDate], [profile teamIdentifier], error);
};

return [signer signAppAtURL:path provisioningProfiles:@[(id)profile] completionHandler:signCompletionHandler];
}

+ (NSProgress *)signAppBundleWithZSign:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSError *error))completionHandler {
+ (NSProgress *)signAppBundleWithZSign:(NSURL *)path completionHandler:(void (^)(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *error))completionHandler {
NSError *error;

// use zsign as our signer~
Expand All @@ -208,7 +211,7 @@ + (NSProgress *)signAppBundleWithZSign:(NSURL *)path completionHandler:(void (^)
[self loadStoreFrameworksWithError2:&error];

if (error) {
completionHandler(NO, nil, error);
completionHandler(NO, nil, nil, error);
return nil;
}

Expand Down Expand Up @@ -292,14 +295,14 @@ + (void)validateJITLessSetupWithSigner:(Signer)signer completionHandler:(void (^
// Sign the test app bundle
if(signer == AltSign) {
[LCUtils signAppBundle:[NSURL fileURLWithPath:path]
completionHandler:^(BOOL success, NSDate* expirationDate, NSError *_Nullable error) {
completionHandler:^(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *_Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(success, error);
});
}];
} else {
[LCUtils signAppBundleWithZSign:[NSURL fileURLWithPath:path]
completionHandler:^(BOOL success, NSDate* expirationDate, NSError *_Nullable error) {
completionHandler:^(BOOL success, NSDate* expirationDate, NSString* teamId, NSError *_Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(success, error);
});
Expand Down
Loading

0 comments on commit 34998af

Please sign in to comment.