Skip to content

Commit fe917ef

Browse files
committed
Add an installer for the iOS Deb release to allow compatibility with rootless jailbreaks
1 parent 3fe9de8 commit fe917ef

File tree

7 files changed

+128
-72
lines changed

7 files changed

+128
-72
lines changed

Makefile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ CORE_FILTER += Core/debugger.c Core/sm83_disassembler.c Core/symbol_hash.c
244244
LDFLAGS += -arch arm64
245245
OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT)
246246
LDFLAGS += -miphoneos-version-min=11.0 -isysroot $(SYSROOT)
247-
REREGISTER_LDFLAGS := $(LDFLAGS) -lobjc -framework CoreServices -framework Foundation
247+
IOS_INSTALLER_LDFLAGS := $(LDFLAGS) -lobjc -framework CoreServices -framework Foundation
248248
LDFLAGS += -lobjc -framework UIKit -framework Foundation -framework CoreGraphics -framework Metal -framework MetalKit -framework AudioToolbox -framework AVFoundation -framework QuartzCore -framework CoreMotion -framework CoreVideo -framework CoreMedia -framework CoreImage -framework UserNotifications -weak_framework CoreHaptics
249249
CODESIGN := codesign -fs -
250250
else
@@ -325,7 +325,7 @@ quicklook: $(BIN)/SameBoy.qlgenerator
325325
sdl: $(SDL_TARGET) $(BIN)/SDL/dmg_boot.bin $(BIN)/SDL/mgb_boot.bin $(BIN)/SDL/cgb0_boot.bin $(BIN)/SDL/cgb_boot.bin $(BIN)/SDL/agb_boot.bin $(BIN)/SDL/sgb_boot.bin $(BIN)/SDL/sgb2_boot.bin $(BIN)/SDL/LICENSE $(BIN)/SDL/registers.sym $(BIN)/SDL/background.bmp $(BIN)/SDL/Shaders $(BIN)/SDL/Palettes
326326
bootroms: $(BIN)/BootROMs/agb_boot.bin $(BIN)/BootROMs/cgb_boot.bin $(BIN)/BootROMs/cgb0_boot.bin $(BIN)/BootROMs/dmg_boot.bin $(BIN)/BootROMs/mgb_boot.bin $(BIN)/BootROMs/sgb_boot.bin $(BIN)/BootROMs/sgb2_boot.bin
327327
tester: $(TESTER_TARGET) $(BIN)/tester/dmg_boot.bin $(BIN)/tester/cgb_boot.bin $(BIN)/tester/agb_boot.bin $(BIN)/tester/sgb_boot.bin $(BIN)/tester/sgb2_boot.bin
328-
_ios: $(BIN)/SameBoy-iOS.app $(OBJ)/reregister
328+
_ios: $(BIN)/SameBoy-iOS.app $(OBJ)/installer
329329
ios-ipa: $(BIN)/SameBoy-iOS.ipa
330330
ios-deb: $(BIN)/SameBoy-iOS.deb
331331
ifeq ($(PLATFORM),windows32)
@@ -344,7 +344,7 @@ CORE_SOURCES := $(filter-out $(CORE_FILTER),$(shell ls Core/*.c))
344344
CORE_HEADERS := $(shell ls Core/*.h)
345345
SDL_SOURCES := $(shell ls SDL/*.c) $(OPEN_DIALOG) $(patsubst %,SDL/audio/%.c,$(SDL_AUDIO_DRIVERS))
346346
TESTER_SOURCES := $(shell ls Tester/*.c)
347-
IOS_SOURCES := $(filter-out iOS/reregister.m, $(shell ls iOS/*.m)) $(shell ls AppleCommon/*.m)
347+
IOS_SOURCES := $(filter-out iOS/installer.m, $(shell ls iOS/*.m)) $(shell ls AppleCommon/*.m)
348348
COCOA_SOURCES := $(shell ls Cocoa/*.m) $(shell ls HexFiend/*.m) $(shell ls JoyKit/*.m) $(shell ls AppleCommon/*.m)
349349
QUICKLOOK_SOURCES := $(shell ls QuickLook/*.m) $(shell ls QuickLook/*.c)
350350

@@ -449,9 +449,8 @@ ifeq ($(CONF), release)
449449
$(STRIP) $@
450450
endif
451451

452-
$(OBJ)/reregister: iOS/reregister.m iOS/reregister.entitlements
453-
$(CC) $< -o $@ $(REREGISTER_LDFLAGS) $(CFLAGS)
454-
codesign -fs - --entitlements iOS/reregister.entitlements $@
452+
$(OBJ)/installer: iOS/installer.m
453+
$(CC) $< -o $@ $(IOS_INSTALLER_LDFLAGS) $(CFLAGS)
455454

456455
# Cocoa Port
457456

@@ -697,20 +696,22 @@ $(BIN)/SameBoy-iOS.deb: $(OBJ)/debian-binary $(OBJ)/control.tar.gz $(OBJ)/data.t
697696
-@$(MKDIR) -p $(dir $@)
698697
(cd $(OBJ) && ar cr $(abspath $@) $(notdir $^))
699698

700-
$(OBJ)/data.tar.gz: ios iOS/jailbreak.entitlements
701-
$(MKDIR) -p $(OBJ)/Applications
702-
cp -rf $(BIN)/SameBoy-iOS.app $(OBJ)/Applications/SameBoy-iOS.app
703-
cp build/obj-ios/reregister $(OBJ)/Applications/SameBoy-iOS.app
704-
codesign -fs - --entitlements iOS/jailbreak.entitlements $(OBJ)/Applications/SameBoy-iOS.app
705-
(cd $(OBJ) && tar -czf $(abspath $@) --format ustar --uid 501 --gid 501 --numeric-owner ./Applications)
706-
rm -rf $(OBJ)/Applications
699+
$(OBJ)/data.tar.gz: ios iOS/jailbreak.entitlements iOS/installer.entitlements
700+
$(MKDIR) -p $(OBJ)/private/var/containers/
701+
cp -rf $(BIN)/SameBoy-iOS.app $(OBJ)/private/var/containers/SameBoy-iOS.app
702+
cp build/obj-ios/installer $(OBJ)/private/var/containers/SameBoy-iOS.app
703+
codesign -fs - --entitlements iOS/installer.entitlements $(OBJ)/private/var/containers/SameBoy-iOS.app/installer
704+
codesign -fs - --entitlements iOS/jailbreak.entitlements $(OBJ)/private/var/containers/SameBoy-iOS.app
705+
(cd $(OBJ) && tar -czf $(abspath $@) --format ustar --uid 501 --gid 501 --numeric-owner ./private)
706+
rm -rf $(OBJ)/private/
707707

708-
$(OBJ)/control.tar.gz: iOS/deb-postinst iOS/deb-control
708+
$(OBJ)/control.tar.gz: iOS/deb-postinst iOS/deb-prerm iOS/deb-control
709709
-@$(MKDIR) -p $(dir $@)
710710
sed "s/@VERSION/$(VERSION)/" < iOS/deb-control > $(OBJ)/control
711711
ln iOS/deb-postinst $(OBJ)/postinst
712-
(cd $(OBJ) && tar -czf $(abspath $@) --format ustar --uid 501 --gid 501 --numeric-owner ./control ./postinst)
713-
rm $(OBJ)/control $(OBJ)/postinst
712+
ln iOS/deb-prerm $(OBJ)/prerm
713+
(cd $(OBJ) && tar -czf $(abspath $@) --format ustar --uid 501 --gid 501 --numeric-owner ./control ./postinst ./prerm)
714+
rm $(OBJ)/control $(OBJ)/postinst $(OBJ)/prerm
714715

715716
$(OBJ)/debian-binary:
716717
-@$(MKDIR) -p $(dir $@)

iOS/deb-control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: com.github.liji32.sameboy.ios
22
Name: SameBoy
33
Depends: firmware (>= 11.0)
4-
Architecture: iphoneos-arm
4+
Architecture: all
55
Description: A Game Boy emulator for iOS
66
Maintainer: Lior Halphon
77
Author: Lior Halphon

iOS/deb-postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
/Applications/SameBoy-iOS.app/reregister
2+
/private/var/containers/SameBoy-iOS.app/installer install

iOS/deb-prerm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
/Applications/SameBoy-iOS.app/installer uninstall || /var/jb/Applications/SameBoy-iOS.app/installer uninstall
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
<true/>
1616
<key>platform-application</key>
1717
<true/>
18+
<key>com.apple.private.security.no-container</key>
19+
<true/>
1820
</dict>
1921
</plist>

iOS/installer.m

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#import <Foundation/Foundation.h>
2+
#import <dlfcn.h>
3+
#import <objc/runtime.h>
4+
5+
@interface LSApplicationProxy : NSObject
6+
@property (readonly, getter=isContainerized) bool containerized;
7+
@property (readonly) NSString *bundleIdentifier;
8+
@property (readonly) NSURL * bundleURL;
9+
@end
10+
11+
@interface LSApplicationWorkspace : NSObject
12+
+ (instancetype)defaultWorkspace;
13+
- (NSArray <LSApplicationProxy *> *)allInstalledApplications;
14+
- (bool)unregisterApplication:(NSURL *)url;
15+
- (bool)registerApplicationDictionary:(NSDictionary *)dict;
16+
@end
17+
18+
@interface MCMAppDataContainer : NSObject
19+
+ (MCMAppDataContainer *)containerWithIdentifier:(NSString *)identifier
20+
createIfNecessary:(bool)create
21+
existed:(bool *)existed
22+
error:(NSError **)error;
23+
@property(readonly) NSURL *url;
24+
@end
25+
26+
27+
int main(int argc, char **argv)
28+
{
29+
if (argc != 2) return 1;
30+
// Make sure MobileContainerManager is loaded
31+
if (!dlopen("/System/Library/PrivateFrameworks/MobileContainerManager.framework/MobileContainerManager", RTLD_NOW)) return 1;
32+
33+
bool uninstall = false;
34+
if (strcmp(argv[1], "uninstall") == 0) {
35+
uninstall = true;
36+
}
37+
else if (strcmp(argv[1], "install") != 0) {
38+
return 1;
39+
}
40+
41+
NSString *installPath = @"/var/jb/Applications/SameBoy-iOS.app";
42+
if (access("/Applications/", W_OK) == 0) {
43+
installPath = @"/Applications/SameBoy-iOS.app";
44+
}
45+
NSLog(@"Install path is %@", installPath);
46+
47+
for (LSApplicationProxy *app in [[LSApplicationWorkspace defaultWorkspace] allInstalledApplications]) {
48+
if (![app.bundleIdentifier isEqualToString:[NSBundle mainBundle].bundleIdentifier]) continue;
49+
if (![app.bundleURL.path.stringByResolvingSymlinksInPath isEqual:installPath.stringByResolvingSymlinksInPath]) {
50+
// Already installed elsewhere
51+
NSLog(@"Already installed at %@", app.bundleURL.path);
52+
return 1;
53+
}
54+
55+
NSLog(@"Unregistering previous installation");
56+
// We're registered but not containerized (or just uninstalling), unregister ourselves first
57+
if (![[LSApplicationWorkspace defaultWorkspace] unregisterApplication:app.bundleURL]) return 1;
58+
59+
break;
60+
}
61+
62+
// Don't modify files if we're at the correct path already
63+
if (uninstall || ![[NSBundle mainBundle].bundlePath.stringByResolvingSymlinksInPath isEqual:installPath.stringByResolvingSymlinksInPath]) {
64+
// Remove any previous copy
65+
NSError *error = nil;
66+
if (!access(installPath.UTF8String, F_OK)) {
67+
NSLog(@"Removing previous installation");
68+
[[NSFileManager defaultManager] removeItemAtPath:installPath error:&error];
69+
if (error) {
70+
NSLog(@"Error: %@", error);
71+
return 1;
72+
}
73+
}
74+
75+
// If we're uninstalling, we're done
76+
if (uninstall) return 0;
77+
78+
NSLog(@"Installing...");
79+
80+
[[NSFileManager defaultManager] moveItemAtPath:[NSBundle mainBundle].bundlePath toPath:installPath error:&error];
81+
if (error) {
82+
NSLog(@"Error: %@", error);
83+
return 1;
84+
}
85+
}
86+
87+
88+
NSLog(@"Registering...");
89+
90+
NSString *container = [objc_getClass("MCMAppDataContainer") containerWithIdentifier:[NSBundle mainBundle].bundleIdentifier
91+
createIfNecessary:true
92+
existed:nil
93+
error:nil].url.path;
94+
95+
return ![[LSApplicationWorkspace defaultWorkspace] registerApplicationDictionary:@{
96+
@"ApplicationType": @"System",
97+
@"CFBundleIdentifier": [NSBundle mainBundle].bundleIdentifier,
98+
@"CompatibilityState": @NO,
99+
@"Container": container,
100+
@"IsDeletable": @NO,
101+
@"Path": installPath,
102+
@"_LSBundlePlugins": @{},
103+
@"IsContainerized": @YES,
104+
}];
105+
}

iOS/reregister.m

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)