Skip to content

Commit

Permalink
support SideJITServer
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeBlack committed Sep 10, 2024
1 parent 1ddcbbe commit 33c98d4
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 13 deletions.
29 changes: 23 additions & 6 deletions LCSharedUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,30 @@ + (BOOL)askForJIT {
NSString *tsPath = [NSString stringWithFormat:@"%@/../_TrollStore", NSBundle.mainBundle.bundlePath];
if (!access(tsPath.UTF8String, F_OK)) {
urlScheme = @"apple-magnifier://enable-jit?bundle-id=%@";
NSURL *launchURL = [NSURL URLWithString:[NSString stringWithFormat:urlScheme, NSBundle.mainBundle.bundleIdentifier]];
if ([UIApplication.sharedApplication canOpenURL:launchURL]) {
[UIApplication.sharedApplication openURL:launchURL options:@{} completionHandler:nil];
return YES;
}
} else {
urlScheme = @"sidestore://sidejit-enable?bid=%@";
}
NSURL *launchURL = [NSURL URLWithString:[NSString stringWithFormat:urlScheme, NSBundle.mainBundle.bundleIdentifier]];
if ([UIApplication.sharedApplication canOpenURL:launchURL]) {
[UIApplication.sharedApplication openURL:launchURL options:@{} completionHandler:nil];
return YES;
NSUserDefaults* groupUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[self appGroupID]];

NSString* sideJITServerAddress = [groupUserDefaults objectForKey:@"LCSideJITServerAddress"];
NSString* deviceUDID = [groupUserDefaults objectForKey:@"LCDeviceUDID"];
if (!sideJITServerAddress || !deviceUDID) {
return NO;
}
NSString* launchJITUrlStr = [NSString stringWithFormat: @"%@/%@/%@", sideJITServerAddress, deviceUDID, NSBundle.mainBundle.bundleIdentifier];
NSURLSession* session = [NSURLSession sharedSession];
NSURL* launchJITUrl = [NSURL URLWithString:launchJITUrlStr];
NSURLRequest* req = [[NSURLRequest alloc] initWithURL:launchJITUrl];
NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error) {
NSLog(@"[LC] failed to contact SideJITServer: %@", error);
}
}];
[task resume];

}
return NO;
}
Expand Down
2 changes: 1 addition & 1 deletion LiveContainerSwiftUI/LCAppBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ struct LCAppBanner : View {
renameFolerContinuation?.resume()
}
)
.alert("Enabling JIT", isPresented: $enablingJITShow) {
.alert("Waiting for JIT", isPresented: $enablingJITShow) {
Button {
self.confirmEnablingJIT = true
self.confirmEnablingJITContinuation?.resume()
Expand Down
55 changes: 49 additions & 6 deletions LiveContainerSwiftUI/LCSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ struct LCSettingsView: View {
@State var silentSwitchApp = false
@State var injectToLCItelf = false

@State var sideJITServerAddress : String
@State var deviceUDID: String

init(apps: Binding<[LCAppInfo]>, appDataFolderNames: Binding<[String]>) {
_isJitLessEnabled = State(initialValue: LCUtils.certificatePassword() != nil)
_isAltCertIgnored = State(initialValue: UserDefaults.standard.bool(forKey: "LCIgnoreALTCertificate"))
Expand All @@ -42,6 +45,18 @@ struct LCSettingsView: View {

_apps = apps
_appDataFolderNames = appDataFolderNames

if let configSideJITServerAddress = LCUtils.appGroupUserDefault.string(forKey: "LCSideJITServerAddress") {
_sideJITServerAddress = State(initialValue: configSideJITServerAddress)
} else {
_sideJITServerAddress = State(initialValue: "")
}

if let configDeviceUDID = LCUtils.appGroupUserDefault.string(forKey: "LCDeviceUDID") {
_deviceUDID = State(initialValue: configDeviceUDID)
} else {
_deviceUDID = State(initialValue: "")
}

}

Expand Down Expand Up @@ -95,14 +110,32 @@ struct LCSettingsView: View {
Text("If you see frequent re-sign, enable this option.")
}

Section{
Toggle(isOn: $frameShortIcon) {
Text("Frame Short Icon")
// Section{
// Toggle(isOn: $frameShortIcon) {
// Text("Frame Short Icon")
// }
// } header: {
// Text("Miscellaneous")
// } footer: {
// Text("Frame shortcut icons with LiveContainer icon.")
// }
Section {
HStack {
Text("Address")
Spacer()
TextField("http://x.x.x.x:8080", text: $sideJITServerAddress)
.multilineTextAlignment(.trailing)
}
HStack {
Text("UDID")
Spacer()
TextField("", text: $deviceUDID)
.multilineTextAlignment(.trailing)
}
} header: {
Text("Miscellaneous")
Text("JIT")
} footer: {
Text("Frame shortcut icons with LiveContainer icon.")
Text("Set up your SideJITServer/JITStreamer server. Local Network permission is required.")
}

Section {
Expand Down Expand Up @@ -203,15 +236,25 @@ struct LCSettingsView: View {
.onChange(of: injectToLCItelf) { newValue in
saveItem(key: "LCLoadTweaksToSelf", val: newValue)
}
.onChange(of: deviceUDID) { newValue in
saveAppGroupItem(key: "LCDeviceUDID", val: newValue)
}
.onChange(of: sideJITServerAddress) { newValue in
saveAppGroupItem(key: "LCSideJITServerAddress", val: newValue)
}
}
.navigationViewStyle(StackNavigationViewStyle())

}

func saveItem(key: String, val: Bool) {
func saveItem(key: String, val: Any) {
UserDefaults.standard.setValue(val, forKey: key)
}

func saveAppGroupItem(key: String, val: Any) {
LCUtils.appGroupUserDefault.setValue(val, forKey: key)
}

func setupJitLess() {
if !LCUtils.isAppGroupAltStoreLike() {
errorInfo = "Unsupported installation method. Please use AltStore or SideStore to setup this feature."
Expand Down
2 changes: 2 additions & 0 deletions LiveContainerSwiftUI/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ struct SiteAssociation : Codable {
}

extension LCUtils {
public static let appGroupUserDefault = UserDefaults.init(suiteName: LCUtils.appGroupID())!

// 0= not installed, 1= is installed, 2=current liveContainer is the second one
public static let multiLCStatus = {
if LCUtils.appUrlScheme()?.lowercased() != "livecontainer" {
Expand Down
14 changes: 14 additions & 0 deletions LiveContainerUI/LCMachOUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,17 @@ void LCPatchExecSlice(const char *path, struct mach_header_64 *header) {
close(fd);
return nil;
}

void LCChangeExecUUID(struct mach_header_64 *header) {
uint8_t *imageHeaderPtr = (uint8_t*)header + sizeof(struct mach_header_64);
struct load_command *command = (struct load_command *)imageHeaderPtr;
for(int i = 0; i < header->ncmds > 0; i++) {
if(command->cmd == LC_UUID) {
struct uuid_command *uuidCmd = (struct uuid_command *)command;
// let's add the first byte by 1
uuidCmd->uuid[0] += 1;
break;
}
command = (struct load_command *)((void *)command + command->cmdsize);
}
}
1 change: 1 addition & 0 deletions LiveContainerUI/LCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ typedef void (^LCParseMachOCallback)(const char *path, struct mach_header_64 *he
NSString *LCParseMachO(const char *path, LCParseMachOCallback callback);
void LCPatchAddRPath(const char *path, struct mach_header_64 *header);
void LCPatchExecSlice(const char *path, struct mach_header_64 *header);
void LCChangeExecUUID(struct mach_header_64 *header);

@interface PKZipArchiver : NSObject

Expand Down
24 changes: 24 additions & 0 deletions LiveContainerUI/LCUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,31 @@ + (NSURL *)archiveIPAWithBundleName:(NSString*)newBundleName error:(NSError **)e
infoDict[@"CFBundleIcons~ipad"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"][0] = @"AppIcon60x60_2";
infoDict[@"CFBundleIcons~ipad"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"][1] = @"AppIcon76x76_2";
infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"][0] = @"AppIcon60x60_2";
// reset a executable name so they don't look the same on the log
NSURL* appBundlePath = [tmpPayloadPath URLByAppendingPathComponent:@"App.app"];

NSURL* execFromPath = [appBundlePath URLByAppendingPathComponent:infoDict[@"CFBundleExecutable"]];
infoDict[@"CFBundleExecutable"] = @"LiveContainer_PleaseDoNotShortenTheExecutableNameBecauseItIsUsedToReserveSpaceForOverwritingThankYou2";
NSURL* execToPath = [appBundlePath URLByAppendingPathComponent:infoDict[@"CFBundleExecutable"]];

[manager moveItemAtURL:execFromPath toURL:execToPath error:error];
if (*error) {
NSLog(@"[LC] %@", *error);
return nil;
}

// We have to change executable's UUID so iOS won't consider 2 executables the same
NSString* errorChangeUUID = LCParseMachO([execToPath.path UTF8String], ^(const char *path, struct mach_header_64 *header) {
LCChangeExecUUID(header);
});
if (errorChangeUUID) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:errorChangeUUID forKey:NSLocalizedDescriptionKey];
// populate the error object with the details
*error = [NSError errorWithDomain:@"world" code:200 userInfo:details];
NSLog(@"[LC] %@", errorChangeUUID);
return nil;
}

[infoDict writeToURL:infoPath error:error];

Expand Down

0 comments on commit 33c98d4

Please sign in to comment.