From 166f637a647c24db0db19a1865271d2b22cb08ae Mon Sep 17 00:00:00 2001 From: Eilionoir Tunnicliff Date: Fri, 2 Sep 2022 23:25:58 -0400 Subject: [PATCH 1/6] :bruh: --- Natives/LauncherPreferencesViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index 812c1f6f..bc0047f4 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -757,7 +757,7 @@ int tempIndex; title = @"Allocated RAM"; if(getenv("POJAV_DETECTEDJB")) { message = @"This option allows you to change the amount of memory used by the game. The minimum is 25% (default) and the maximum is 85%. To be safe, any value over 40% will require a tool like jetsamctl to prevent memory crashes."; - } else if (!(getenv("POJAV_DETECTEDJB") && ![getPreference(@"disable_home_symlink") boolValue] == YES)){ + } else if (!(getenv("POJAV_DETECTEDJB") && ![getPreference(@"ram_unjb_enable") boolValue] == YES)){ message = @"This option allows you to change the amount of memory used by the game. This option is disabled by default on unjailbroken devices due to potential instability of the launcher."; } else { message = @"This option allows you to change the amount of memory used by the game. The minimum is 25% (default) and the maximum is 85%. Use this at your own risk while unjailbroken, as it can cause instability or break launching the game entirely."; From cc69b4cbeb1cda56d0336a59468cbc90266b717a Mon Sep 17 00:00:00 2001 From: Eilionoir Tunnicliff Date: Fri, 2 Sep 2022 23:27:05 -0400 Subject: [PATCH 2/6] :bruh: 2 --- Natives/LauncherPreferencesViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index bc0047f4..95e2a7b3 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -757,7 +757,7 @@ int tempIndex; title = @"Allocated RAM"; if(getenv("POJAV_DETECTEDJB")) { message = @"This option allows you to change the amount of memory used by the game. The minimum is 25% (default) and the maximum is 85%. To be safe, any value over 40% will require a tool like jetsamctl to prevent memory crashes."; - } else if (!(getenv("POJAV_DETECTEDJB") && ![getPreference(@"ram_unjb_enable") boolValue] == YES)){ + } else if (!(getenv("POJAV_DETECTEDJB") && ![getPreference(@"ram_unjb_enable") boolValue] == NO)){ message = @"This option allows you to change the amount of memory used by the game. This option is disabled by default on unjailbroken devices due to potential instability of the launcher."; } else { message = @"This option allows you to change the amount of memory used by the game. The minimum is 25% (default) and the maximum is 85%. Use this at your own risk while unjailbroken, as it can cause instability or break launching the game entirely."; From c8be2494e9b5b0268f9a7191caaa9b3f71082658 Mon Sep 17 00:00:00 2001 From: Eilionoir Tunnicliff Date: Fri, 2 Sep 2022 23:39:15 -0400 Subject: [PATCH 3/6] Java kit fixes in Makefile, added to .gitignore --- .gitignore | 3 +++ Makefile | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b6e1b109..f5360437 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ /Natives/build .DS_Store /pojavlauncher.xcodeproj +/depends +/Natives/resources/AppIcon60x60@2x.png +/Natives/resources/AppIcon76x76@2x~ipad.png diff --git a/Makefile b/Makefile index d47363ae..91a59c36 100644 --- a/Makefile +++ b/Makefile @@ -324,25 +324,26 @@ dsym: deb ipa: dsym echo 'Building PojavLauncher $(VERSION) - IPA - Start' - mkdir -p $(SOURCEDIR)/depends; \ + @mkdir -p $(SOURCEDIR)/depends; \ cd $(SOURCEDIR)/depends; \ if [ ! -f "java-8-openjdk/bin/java" ] && [ ! -f "$(ls ../jre8-*.tar.xz)" ]; then \ if [ "$(RUNNER)" != "1" ]; then \ - wget 'https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/releases/download/jre8-40df388/jre8-arm64-20220811-release.tar.xz'; \ + wget 'https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/releases/download/jre8-40df388/jre8-arm64-20220811-release.tar.xz' -q --show-progress; \ fi; \ mkdir java-8-openjdk && cd java-8-openjdk; \ tar xvf ../jre8-*.tar.xz; \ rm ../jre8-*.tar.xz; \ fi; \ - cd ..; \ + cd $(SOURCEDIR)/depends; \ if [ ! -f "java-17-openjdk/bin/java" ] && [ ! -f "$(ls ../jre17-*.tar.xz)" ]; then \ if [ "$(RUNNER)" != "1" ]; then \ - wget 'https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/releases/download/jre17-ca01427/jre17-arm64-20220817-release.tar.xz'; \ + wget 'https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/releases/download/jre17-ca01427/jre17-arm64-20220817-release.tar.xz' -q --show-progress; \ fi; \ mkdir java-17-openjdk && cd java-17-openjdk; \ tar xvf ../jre17-*.tar.xz; \ rm ../jre17-*.tar.xz; \ fi; \ + cd ..; \ mkdir -p $(OUTPUTDIR); \ cd $(OUTPUTDIR); \ $(call DIRCHECK,$(OUTPUTDIR)/Payload); \ From 77b650e44dce6e4ffa8ccc98f9bdd4ed9856bab2 Mon Sep 17 00:00:00 2001 From: Eilionoir Tunnicliff Date: Fri, 2 Sep 2022 23:39:58 -0400 Subject: [PATCH 4/6] Align correctly --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 91a59c36..8e9262a4 100644 --- a/Makefile +++ b/Makefile @@ -324,7 +324,7 @@ dsym: deb ipa: dsym echo 'Building PojavLauncher $(VERSION) - IPA - Start' - @mkdir -p $(SOURCEDIR)/depends; \ + @mkdir -p $(SOURCEDIR)/depends; \ cd $(SOURCEDIR)/depends; \ if [ ! -f "java-8-openjdk/bin/java" ] && [ ! -f "$(ls ../jre8-*.tar.xz)" ]; then \ if [ "$(RUNNER)" != "1" ]; then \ From a9ca069f1fdbfdc0256c53f2221e07b1ec5ef065 Mon Sep 17 00:00:00 2001 From: Eilionoir Tunnicliff Date: Fri, 2 Sep 2022 23:53:42 -0400 Subject: [PATCH 5/6] Various makefile fixes ported from the post-jailbreak-pojav branch --- Makefile | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 8e9262a4..a6a36696 100644 --- a/Makefile +++ b/Makefile @@ -164,11 +164,11 @@ DEPLOY = \ fi # Make sure everything is already available for use. Error if they require something -ifeq ($(call HAS_COMMAND,cmake --version),1) +ifneq ($(call DEPCHECK,cmake --version),1) $(error You need to install cmake) endif -ifeq ($(call HAS_COMMAND,$(BOOTJDK)/javac -version),1) +ifneq ($(call DEPCHECK,$(BOOTJDK)/javac -version),1) $(error You need to install JDK 8) endif @@ -178,26 +178,26 @@ $(error You need to install JDK 8) endif endif -ifeq ($(call HAS_COMMAND,ldid),1) +ifneq ($(call DEPCHECK,ldid),1) $(error You need to install ldid) endif -ifeq ($(call HAS_COMMAND,fakeroot -v),1) +ifneq ($(call DEPCHECK,fakeroot -v),1) $(error You need to install fakeroot) endif -ifeq ($(call HAS_COMMAND,dpkg-deb --version),1) +ifneq ($(call DEPCHECK,dpkg-deb --version),1) $(error You need to install dpkg-dev) endif ifeq ($(DETECTPLAT),Linux) -ifeq ($(call HAS_COMMAND,lld),1) +ifneq ($(call DEPCHECK,lld),1) $(error You need to install lld) endif endif -ifeq ($(call HAS_COMMAND,nproc --version),1) -ifeq ($(call HAS_COMMAND,gnproc --version),1) +ifneq ($(call DEPCHECK,nproc --version),1) +ifneq ($(call DEPCHECK,gnproc --version),1) $(warning Unable to determine number of threads, defaulting to 2.) JOBS ?= 2 else @@ -217,12 +217,13 @@ endif # native - Builds the Objective-C code. # java - Builds the Java code. # extras - Builds the Assets and Storyboard. -# deb - Builds the Debian package. +# deb - Builds the Debian package. Will be removed in 2.2. # ipa - Builds the application package. -# install - runs deb + installs to jailbroken device. -# deploy - runs native and java + installs to jailbroken device. +# install - runs deb + installs to jailbroken device. Will be removed in 2.2. +# deploy - runs native and java + installs to jailbroken device. Will be removed in 2.2. +# dsym - Generates debug symbol files -all: clean native java extras deb +all: clean native java extras deb dsym ipa check: @printf '\nDumping all Makefile variables.\n' @@ -313,7 +314,7 @@ deb: native java extras else \ $(call PACKAGING,development); \ fi - @echo 'Building PojavLauncher $(VERSION) - DEB - Start' + @echo 'Building PojavLauncher $(VERSION) - DEB - End' dsym: deb @echo 'Building PojavLauncher $(VERSION) - DSYM - Start' @@ -418,13 +419,14 @@ help: @echo '' @echo 'Usage:' @echo ' make Makes everything under all' - @echo ' make all Builds natives, javaapp, extras, and package' + @echo ' make all Builds the entire app' @echo ' make native Builds the native app' @echo ' make java Builds the Java app' - @echo ' make deb Builds deb of PojavLauncher' -# @echo ' make ipa Builds ipa of PojavLauncher' - @echo ' make install Copy package to local iDevice' - @echo ' make deploy Copy package to local iDevice' + @echo ' make deb (DEPRECATED) Builds deb of PojavLauncher' + @echo ' make ipa Builds ipa of PojavLauncher' + @echo ' make install (DEPRECATED) Copy package to local iDevice' + @echo ' make deploy (DEPRECATED) Copy package to local iDevice' + @echo ' make dsym Generate debug symbol files' @echo ' make clean Cleans build directories' -.PHONY: all clean native java extras deb ipa install deploy +.PHONY: all clean native java extras deb ipa install deploy dsym From de977f67f8642f702748a8b8957372fbbe899274 Mon Sep 17 00:00:00 2001 From: Eilionoir Tunnicliff Date: Sat, 3 Sep 2022 01:37:53 -0400 Subject: [PATCH 6/6] Overhaul jailbreak detection mechanisms --- Natives/CMakeLists.txt | 1 + Natives/external/Apple/codesign.h | 65 +++++++++++++++++ Natives/main.m | 117 ++++++++++++++++++++++++------ 3 files changed, 159 insertions(+), 24 deletions(-) create mode 100644 Natives/external/Apple/codesign.h diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index ef8f10f6..ec3ed0a1 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -17,6 +17,7 @@ include_directories( "external/DBNumberedSlider/Classes" "external/fishhook" "external/mesa" + "external/Apple" ) # For cacio support library diff --git a/Natives/external/Apple/codesign.h b/Natives/external/Apple/codesign.h new file mode 100644 index 00000000..57df0324 --- /dev/null +++ b/Natives/external/Apple/codesign.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ + +#ifndef _SYS_CODESIGN_H_ +#define _SYS_CODESIGN_H_ + +#include + +/* code signing attributes of a process */ +#define CS_VALID 0x0001 /* dynamically valid */ +#define CS_HARD 0x0100 /* don't load invalid pages */ +#define CS_KILL 0x0200 /* kill process if it becomes invalid */ +#define CS_EXEC_SET_HARD 0x1000 /* set CS_HARD on any exec'ed process */ +#define CS_EXEC_SET_KILL 0x2000 /* set CS_KILL on any exec'ed process */ +#define CS_KILLED 0x10000 /* was killed by kernel for invalidity */ +#define CS_RESTRICT 0x20000 /* tell dyld to treat restricted */ + +/* csops operations */ +#define CS_OPS_STATUS 0 /* return status */ +#define CS_OPS_MARKINVALID 1 /* invalidate process */ +#define CS_OPS_MARKHARD 2 /* set HARD flag */ +#define CS_OPS_MARKKILL 3 /* set KILL flag (sticky) */ +#define CS_OPS_PIDPATH 4 /* get executable's pathname */ +#define CS_OPS_CDHASH 5 /* get code directory hash */ +#define CS_OPS_PIDOFFSET 6 /* get offset of active Mach-o slice */ +#define CS_OPS_ENTITLEMENTS_BLOB 7 /* get entitlements blob */ +#define CS_OPS_MARKRESTRICT 8 /* set RESTRICT flag (sticky) */ + +#ifndef KERNEL + +__BEGIN_DECLS + +/* code sign operations */ +int csops(pid_t pid, unsigned int ops, void * useraddr, size_t usersize); + +__END_DECLS + +#endif /* ! KERNEL */ + +#endif /* _SYS_CODESIGN_H_ */ diff --git a/Natives/main.m b/Natives/main.m index bb3e2b2b..c23e3515 100644 --- a/Natives/main.m +++ b/Natives/main.m @@ -1,3 +1,7 @@ +#import +#import +#import +#import #import #import "AppDelegate.h" @@ -18,6 +22,9 @@ #include "JavaLauncher.h" #include "log.h" #include "utils.h" +#include "codesign.h" + +#define CS_PLATFORM_BINARY 0x4000000 #if CONFIG_RELEASE == 1 # define CONFIG_TYPE "release" @@ -32,38 +39,91 @@ #define fm NSFileManager.defaultManager void printEntitlementAvailability(NSString *key) { - NSLog(@"- %@: %@", key, getEntitlementValue(key) ? @"YES" : @"NO"); + NSLog(@"[Pre-Init] - %@: %@", key, getEntitlementValue(key) ? @"YES" : @"NO"); +} + +bool init_checkForsubstrated() { + // Please kindly tell pwn20wnd that he sucks + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; + size_t miblen = 4; + size_t size; + int st = sysctl(mib, miblen, NULL, &size, NULL, 0); + struct kinfo_proc * process = NULL; + struct kinfo_proc * newprocess = NULL; + do { + size += size / 10; + newprocess = realloc(process, size); + if (!newprocess){ + if (process){ + free(process); + } + return nil; + } + process = newprocess; + st = sysctl(mib, miblen, process, &size, NULL, 0); + } while (st == -1 && errno == ENOMEM); + if (st == 0){ + if (size % sizeof(struct kinfo_proc) == 0){ + int nprocess = size / sizeof(struct kinfo_proc); + if (nprocess){ + for (int i = nprocess - 1; i >= 0; i--){ + if(strcmp(process[i].kp_proc.p_comm,"substrated") == 0) { + return true; + } + } + } + } + } + return false; +} + +void init_checkForJailbreak() { + bool jbDyld = false; + bool jbFlag = true; + bool jbProc = init_checkForsubstrated(); + + int imageCount = _dyld_image_count(); + uint32_t flags = CS_PLATFORM_BINARY; + + for (int i=0; i < imageCount; i++) { + if (strcmp(_dyld_get_image_name(i),"/usr/lib/pspawn_payload-stg2.dylib") == 0) { + jbDyld = true; + } else { + jbDyld = false; + } + } + if (csops(0, CS_OPS_STATUS, &flags, sizeof(flags)) != -1) { + if ((flags & CS_PLATFORM_BINARY) == 0) { + jbFlag = false; + } else { + jbFlag = true; + } + } + + if (jbDyld || jbFlag || jbProc) { + setenv("POJAV_DETECTEDJB", "1", 1); + } } void init_logDeviceAndVer(char *argument) { + // Hardware + Software struct utsname systemInfo; uname(&systemInfo); - // Hardware + software const char *deviceHardware = systemInfo.machine; const char *deviceSoftware = [[[UIDevice currentDevice] systemVersion] cStringUsingEncoding:NSUTF8StringEncoding]; - - // Jailbreak - const char *jbStrap; - if (strncmp(argument, "/Applications", 13) == 0) { - if ([[NSFileManager defaultManager] fileExistsAtPath:@"/.procursus_strapped"]) { - jbStrap = "Procursus"; - } else { - jbStrap = "Other"; - } - regLog("[Pre-Init] %s with iOS %s (%s)", deviceHardware, deviceSoftware, jbStrap); - } else { - regLog("[Pre-Init] %s with iOS %s (sideloaded)", deviceHardware, deviceSoftware); - } - + // PojavLauncher version regLog("[Pre-Init] PojavLauncher version: %s - %s", CONFIG_TYPE, CONFIG_COMMIT); setenv("POJAV_DETECTEDHW", deviceHardware, 1); setenv("POJAV_DETECTEDSW", deviceSoftware, 1); - if (strncmp(argument, "/Applications", 13) == 0) { - setenv("POJAV_DETECTEDJB", jbStrap, 1); + + if (getenv("POJAV_DETECTEDJB")) { + regLog("[Pre-Init] %s with iOS %s (Jailbroken)", deviceHardware, deviceSoftware); + } else { + regLog("[Pre-Init] %s with iOS %s (Unjailbroken)", deviceHardware, deviceSoftware); } - + regLog("[Pre-init] Entitlements availability:"); printEntitlementAvailability(@"com.apple.developer.kernel.extended-virtual-addressing"); printEntitlementAvailability(@"com.apple.developer.kernel.increased-memory-limit"); @@ -71,6 +131,7 @@ void init_logDeviceAndVer(char *argument) { } void init_migrateDirIfNecessary() { + // TODO: Rewrite to migrate from /usr/share -> new Docs in 2.2 NSString *completeFile = @"/var/mobile/Documents/.pojavlauncher/migration_complete"; NSString *oldDir = @"/var/mobile/Documents/.pojavlauncher"; if ([fm fileExistsAtPath:oldDir] && ![fm fileExistsAtPath:completeFile]) { @@ -232,15 +293,23 @@ int main(int argc, char * argv[]) { JNI_TRUE, JNI_FALSE, JNI_TRUE); } + init_checkForJailbreak(); + init_migrateDirIfNecessary(); setenv("BUNDLE_PATH", dirname(argv[0]), 1); - // Are we running on a jailbroken environment? - if (strncmp(argv[0], "/Applications", 13) == 0) { - setenv("HOME", "/usr/share", 1); - setenv("OLD_POJAV_HOME", "/var/mobile/Documents/.pojavlauncher", 1); - setenv("POJAV_HOME", "/usr/share/pojavlauncher", 1); + if (getenv("POJAV_DETECTEDJB")) { + // TODO: Set to new Docs for both jben and unjben in 2.2 + if (0 == access("/usr/share/pojavlauncher", F_OK)) { + // If /usr/share/pojavlauncher isnt already available + // this code will crash the app on launch + setenv("HOME", "/usr/share", 1); + setenv("OLD_POJAV_HOME", "/var/mobile/Documents/.pojavlauncher", 1); + setenv("POJAV_HOME", "/usr/share/pojavlauncher", 1); + } else { + setenv("POJAV_HOME", [NSString stringWithFormat:@"%s/Documents", getenv("HOME")].UTF8String, 1); + } } else { setenv("POJAV_HOME", [NSString stringWithFormat:@"%s/Documents", getenv("HOME")].UTF8String, 1); }