Skip to content

Commit

Permalink
Allow packaging both as an IPA and as a DEB package for jailbreak
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Jan 28, 2023
1 parent fabc390 commit ed39e62
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 6 deletions.
45 changes: 41 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ endif
CFLAGS += -arch arm64 -miphoneos-version-min=11.0 -isysroot $(SYSROOT) -IAppleCommon
LDFLAGS += -arch arm64
OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT)
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 -weak_framework CoreHaptics -miphoneos-version-min=11.0 -isysroot $(SYSROOT)
LDFLAGS += -miphoneos-version-min=11.0 -isysroot $(SYSROOT)
REREGISTER_LDFLAGS := $(LDFLAGS) -lobjc -framework CoreServices -framework Foundation
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 -weak_framework CoreHaptics
CODESIGN := codesign -fs -
else
ifeq ($(PLATFORM),Darwin)
Expand Down Expand Up @@ -247,15 +249,17 @@ quicklook: $(BIN)/SameBoy.qlgenerator
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
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
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
_ios: $(BIN)/SameBoy-iOS.app
_ios: $(BIN)/SameBoy-iOS.app $(OBJ)/reregister
ios-ipa: $(BIN)/SameBoy-iOS.ipa
ios-deb: $(BIN)/SameBoy-iOS.deb
all: cocoa sdl tester libretro

# Get a list of our source files and their respective object file targets

CORE_SOURCES := $(shell ls Core/*.c)
SDL_SOURCES := $(shell ls SDL/*.c) $(OPEN_DIALOG) $(patsubst %,SDL/audio/%.c,$(SDL_AUDIO_DRIVERS))
TESTER_SOURCES := $(shell ls Tester/*.c)
IOS_SOURCES := $(shell ls iOS/*.m) $(shell ls AppleCommon/*.m)
IOS_SOURCES := $(filter-out iOS/reregister.m, $(shell ls iOS/*.m)) $(shell ls AppleCommon/*.m)
COCOA_SOURCES := $(shell ls Cocoa/*.m) $(shell ls HexFiend/*.m) $(shell ls JoyKit/*.m) $(shell ls AppleCommon/*.m)
QUICKLOOK_SOURCES := $(shell ls QuickLook/*.m) $(shell ls QuickLook/*.c)

Expand All @@ -272,7 +276,7 @@ TESTER_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(TESTER_SOURCES))

# Automatic dependency generation

ifneq ($(filter-out ios clean bootroms libretro %.bin, $(MAKECMDGOALS)),)
ifneq ($(filter-out ios ios-ipa ios-dev clean bootroms libretro %.bin, $(MAKECMDGOALS)),)
-include $(CORE_OBJECTS:.o=.dep)
ifneq ($(filter $(MAKECMDGOALS),sdl),)
-include $(SDL_OBJECTS:.o=.dep)
Expand Down Expand Up @@ -357,6 +361,9 @@ ifeq ($(CONF), release)
$(STRIP) $@
endif

$(OBJ)/reregister: iOS/reregister.m
$(CC) $< -o $@ $(REREGISTER_LDFLAGS) $(CFLAGS)

# Cocoa Port

$(BIN)/SameBoy.app: $(BIN)/SameBoy.app/Contents/MacOS/SameBoy \
Expand Down Expand Up @@ -587,7 +594,37 @@ endif

ios:
@$(MAKE) _ios

$(BIN)/SameBoy-iOS.ipa: ios
$(MKDIR) -p $(OBJ)/Payload
cp -rf $(BIN)/SameBoy-iOS.app $(OBJ)/Payload/SameBoy-iOS.app
(cd $(OBJ) && zip $(abspath $@) -r Payload)
rm -rf $(OBJ)/Payload


$(BIN)/SameBoy-iOS.deb: $(OBJ)/debian-binary $(OBJ)/control.tar.gz $(OBJ)/data.tar.gz
-@$(MKDIR) -p $(dir $@)
(cd $(OBJ) && ar cr $(abspath $@) $(notdir $^))

$(OBJ)/data.tar.gz: ios iOS/jailbreak.entitlements
$(MKDIR) -p $(OBJ)/Applications
cp -rf $(BIN)/SameBoy-iOS.app $(OBJ)/Applications/SameBoy-iOS.app
cp build/obj-ios/reregister iOS/reregister.entitlements $(OBJ)/Applications/SameBoy-iOS.app
codesign -fs - --entitlements iOS/jailbreak.entitlements $(OBJ)/Applications/SameBoy-iOS.app
(cd $(OBJ) && tar -czf $(abspath $@) ./Applications)
rm -rf $(OBJ)/Applications

$(OBJ)/control.tar.gz: iOS/deb-postinst iOS/deb-control
-@$(MKDIR) -p $(dir $@)
sed "s/@VERSION/$(VERSION)/" < iOS/deb-control > $(OBJ)/control
ln iOS/deb-postinst $(OBJ)/postinst
(cd $(OBJ) && tar -czf $(abspath $@) ./control ./postinst)
rm $(OBJ)/control $(OBJ)/postinst

$(OBJ)/debian-binary:
-@$(MKDIR) -p $(dir $@)
echo 2.0 > $@

# Clean
clean:
rm -rf build
Expand Down
10 changes: 10 additions & 0 deletions iOS/deb-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: com.github.liji32.sameboy.ios
Name: SameBoy
Depends: firmware (>= 11.0)
Architecture: iphoneos-arm
Description: A Game Boy emulator for iOS
Maintainer: Lior Halphon
Author: Lior Halphon
Section: Games
Icon: file:///Applications/SameBoy-iOS.app/[email protected]
Version: @VERSION
3 changes: 3 additions & 0 deletions iOS/deb-postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
ldid -S/Applications/SameBoy-iOS.app/reregister.entitlements /Applications/SameBoy-iOS.app/reregister
/Applications/SameBoy-iOS.app/reregister
8 changes: 8 additions & 0 deletions iOS/jailbreak.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>com.apple.private.security.container-required</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions iOS/main.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <UIKit/UIKit.h>
#import "GBViewController.h"
#include <Core/gb.h>
#include "GBView.h"
#import "GBViewController.h"
#import "GBView.h"

int main(int argc, char * argv[])
{
Expand Down
19 changes: 19 additions & 0 deletions iOS/reregister.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>com.apple.private.mobileinstall.allowedSPI</key>
<array>
<string>InstallForLaunchServices</string>
<string>UninstallForLaunchServices</string>
</array>
<key>com.apple.lsapplicationworkspace.rebuildappdatabases</key>
<true/>
<key>com.apple.private.MobileContainerManager.allowed</key>
<true/>
<key>com.apple.frontboard.launchapplications</key>
<true/>
<key>platform-application</key>
<true/>
</dict>
</plist>
54 changes: 54 additions & 0 deletions iOS/reregister.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <objc/runtime.h>

@interface LSApplicationProxy : NSObject
@property (nonatomic, readonly, getter=isContainerized) bool containerized;
@property (nonatomic, readonly) NSString *bundleIdentifier;
@end

@interface LSApplicationWorkspace : NSObject
+ (instancetype)defaultWorkspace;
- (NSArray <LSApplicationProxy *> *)allInstalledApplications;
- (bool)unregisterApplication:(NSURL *)url;
- (bool)registerApplicationDictionary:(NSDictionary *)dict;
@end

@interface MCMAppDataContainer : NSObject
+ (MCMAppDataContainer *)containerWithIdentifier:(NSString *)identifier
createIfNecessary:(bool)create
existed:(bool *)existed
error:(NSError **)error;
@property(readonly, nonatomic) NSURL *url;
@end


int main(void)
{
// Make sure MobileContainerManager is loaded
if (!dlopen("/System/Library/PrivateFrameworks/MobileContainerManager.framework/MobileContainerManager", RTLD_NOW)) return 1;
for (LSApplicationProxy *app in [[LSApplicationWorkspace defaultWorkspace] allInstalledApplications]) {
if (![app.bundleIdentifier isEqualToString:[NSBundle mainBundle].bundleIdentifier]) continue;
if (app.containerized) return 0; // Everything's fine, no need to reregister
// We're registered but not containerized, unregister ourselves first
if (![[LSApplicationWorkspace defaultWorkspace] unregisterApplication:[NSBundle mainBundle].bundleURL]) return 1;

break;
}

NSString *container = [objc_getClass("MCMAppDataContainer") containerWithIdentifier:[NSBundle mainBundle].bundleIdentifier
createIfNecessary:true
existed:nil
error:nil].url.path;

return ![[LSApplicationWorkspace defaultWorkspace] registerApplicationDictionary:@{
@"ApplicationType": @"System",
@"CFBundleIdentifier": [NSBundle mainBundle].bundleIdentifier,
@"CompatibilityState": @NO,
@"Container": container,
@"IsDeletable": @NO,
@"Path": [NSBundle mainBundle].bundlePath,
@"_LSBundlePlugins": @{},
@"IsContainerized": @YES,
}];
}

0 comments on commit ed39e62

Please sign in to comment.