diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 80f7fea3..f5d9d298 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -25,6 +25,28 @@ jobs: - name: Checkout repository submodules run: git submodule update --init --recursive + - name: Get JRE8 + uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: build.yml + path: depends + workflow_conclusion: success + repo: PojavLauncherTeam/android-openjdk-build-multiarch + branch: jre8-ios-jitjailed + name: jre8-ios-aarch64 + + - name: Get JRE17 + uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: build.yml + path: depends + workflow_conclusion: success + repo: PojavLauncherTeam/android-openjdk-build-multiarch + branch: buildjre17 + name: jre17-ios-aarch64 + - name: Build packages env: password: ${{ secrets.ELLIE_MINI_SECRET }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff9a7226..816f52a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,6 +25,28 @@ jobs: - name: Checkout repository submodules run: git submodule update --init --recursive + - name: Get JRE8 + uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: build.yml + path: depends + workflow_conclusion: success + repo: PojavLauncherTeam/android-openjdk-build-multiarch + branch: jre8-ios-jitjailed + name: jre8-ios-aarch64 + + - name: Get JRE17 + uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: build.yml + path: depends + workflow_conclusion: success + repo: PojavLauncherTeam/android-openjdk-build-multiarch + branch: buildjre17 + name: jre17-ios-aarch64 + - name: Build packages env: password: ${{ secrets.ELLIE_MINI_SECRET }} diff --git a/JavaApp/libs_caciocavallo17/cacio-shared-1.18-SNAPSHOT.jar b/JavaApp/libs_caciocavallo17/cacio-shared-1.18-SNAPSHOT.jar new file mode 100644 index 00000000..0d4859d2 Binary files /dev/null and b/JavaApp/libs_caciocavallo17/cacio-shared-1.18-SNAPSHOT.jar differ diff --git a/JavaApp/libs_caciocavallo17/cacio-tta-1.18-SNAPSHOT.jar b/JavaApp/libs_caciocavallo17/cacio-tta-1.18-SNAPSHOT.jar new file mode 100644 index 00000000..5f431009 Binary files /dev/null and b/JavaApp/libs_caciocavallo17/cacio-tta-1.18-SNAPSHOT.jar differ diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavLauncher.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavLauncher.java index b9fee726..eb4716bf 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavLauncher.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavLauncher.java @@ -43,6 +43,10 @@ public class PojavLauncher { }); System.setProperty("cacio.managed.screensize", args[2]); + try { + // Try to initialize Caciocavallo17 + Class.forName("com.github.caciocavallosilano.cacio.ctc.CTCPreloadClassLoader"); + } catch (ClassNotFoundException e) {} if (args[0].equals(".LaunchJAR")) { UIKit.callback_JavaGUIViewController_launchJarFile(args[1]); diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/UIKit.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/UIKit.java index 7997e812..def91843 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/UIKit.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/UIKit.java @@ -3,7 +3,6 @@ package net.kdt.pojavlaunch.uikit; import java.io.*; import java.lang.reflect.*; import java.util.jar.*; -import net.java.openjdk.cacio.ctc.CTCScreen; import net.kdt.pojavlaunch.utils.MCOptionUtils; import net.kdt.pojavlaunch.*; import org.lwjgl.glfw.*; @@ -32,12 +31,19 @@ public class UIKit { public static void callback_JavaGUIViewController_launchJarFile(final String filepath) throws Throwable { // Thread for refreshing the AWT buffer new Thread(() -> { + Method getCurrentScreenRGB; try { + try { + getCurrentScreenRGB = Class.forName("net.java.openjdk.cacio.ctc.CTCScreen").getMethod("getCurrentScreenRGB"); + } catch (ClassNotFoundException e) { + getCurrentScreenRGB = Class.forName("com.github.caciocavallosilano.cacio.ctc.CTCScreen").getMethod("getCurrentScreenRGB"); + } + long lastTime = System.currentTimeMillis(); while (true) { int[] pixelsArray = null; try{ - pixelsArray = CTCScreen.getCurrentScreenRGB(); + pixelsArray = (int[])getCurrentScreenRGB.invoke(null); } catch (NullPointerException e) { Thread.sleep(500); } @@ -51,7 +57,7 @@ public class UIKit { } lastTime = currentTime; } - } catch (InterruptedException e) { + } catch (Throwable e) { e.printStackTrace(); } }, "AWTFBRefreshThread").start(); diff --git a/Makefile b/Makefile index 49367bbc..5ecbafad 100644 --- a/Makefile +++ b/Makefile @@ -325,18 +325,16 @@ ipa: dsym echo 'Building PojavLauncher $(VERSION) - IPA - Start' mkdir -p $(SOURCEDIR)/depends; \ cd $(SOURCEDIR)/depends; \ - if [ ! -d "java-8-openjdk" ]; then \ + if [ ! -d "java-8-openjdk" ] && [ -n "$(ls ../jre8-*.tar.xz)" ]; then \ mkdir java-8-openjdk && cd java-8-openjdk; \ - wget 'https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/releases/download/jre8-40df388/jre8-arm64-20220811-release.tar.xz'; \ - tar xvf *.tar.xz; \ - rm *.tar.xz; \ + tar xvf ../jre8-*.tar.xz; \ + rm ../jre8-*.tar.xz; \ fi; \ - cd ..; \ - if [ ! -d "java-17-openjdk" ]; then \ + cd ..; \ + if [ ! -d "java-17-openjdk" ] && [ -n "$(ls ../jre17-*.tar.xz)" ]; then \ mkdir java-17-openjdk && cd java-17-openjdk; \ - wget 'https://github.com/PojavLauncherTeam/android-openjdk-build-multiarch/releases/download/jre17-ca01427/jre17-arm64-20220817-release.tar.xz'; \ - tar xvf *.tar.xz; \ - rm *.tar.xz; \ + tar xvf ../jre17-*.tar.xz; \ + rm ../jre17-*.tar.xz; \ fi; \ mkdir -p $(OUTPUTDIR); \ cd $(OUTPUTDIR); \ @@ -346,6 +344,8 @@ ipa: dsym cp -R $(POJAV_JRE8_DIR) $(OUTPUTDIR)/Payload/PojavLauncher.app/jvm/; \ cp -R $(POJAV_JRE17_DIR) $(OUTPUTDIR)/Payload/PojavLauncher.app/jvm/; \ rm -rf $(OUTPUTDIR)/Payload/PojavLauncher.app/jvm/*/{bin,include,jre,lib/{ct.sym,libjsig.dylib,src.zip,tools.jar}}; \ + cp $(OUTPUTDIR)/Payload/PojavLauncher.app/Frameworks/libawt_xawt.dylib $(OUTPUTDIR)/Payload/PojavLauncher.app/jvm/*/lib/; \ + rm $(OUTPUTDIR)/Payload/PojavLauncher.app/Frameworks/libawt_*.dylib; \ ldid -S$(SOURCEDIR)/entitlements_ipa.xml $(OUTPUTDIR)/Payload/PojavLauncher.app/PojavLauncher; \ rm -f $(OUTPUTDIR)/*.ipa; \ cd $(OUTPUTDIR); \ diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index b979d75d..2b385a32 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -20,7 +20,7 @@ include_directories( ) # For cacio support library -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rpath @executable_path/jvm/java-8-openjdk/lib -rpath /usr/lib/jvm/java-8-openjdk/lib") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rpath @loader_path -rpath @executable_path/jvm/java-8-openjdk/lib -rpath /usr/lib/jvm/java-8-openjdk/lib") add_definitions(-DCONFIG_COMMIT="${CONFIG_COMMIT}") add_definitions(-DCONFIG_RELEASE=${CONFIG_RELEASE}) diff --git a/Natives/JavaGUIViewController.m b/Natives/JavaGUIViewController.m index 4a1690cc..275f5e90 100644 --- a/Natives/JavaGUIViewController.m +++ b/Natives/JavaGUIViewController.m @@ -113,6 +113,10 @@ const void * _CGDataProviderGetBytePointerCallbackAWT(void *info) { - (void)surfaceOnClick:(UITapGestureRecognizer *)sender { if (method_ReceiveInput == NULL) { class_CTCAndroidInput = (*runtimeJNIEnvPtr)->FindClass(runtimeJNIEnvPtr, "net/java/openjdk/cacio/ctc/CTCAndroidInput"); + if ((*runtimeJNIEnvPtr)->ExceptionCheck(runtimeJNIEnvPtr) == JNI_TRUE) { + (*runtimeJNIEnvPtr)->ExceptionClear(runtimeJNIEnvPtr); + class_CTCAndroidInput = (*runtimeJNIEnvPtr)->FindClass(runtimeJNIEnvPtr, "com/github/caciocavallosilano/cacio/ctc/CTCAndroidInput"); + } assert(class_CTCAndroidInput != NULL); method_ReceiveInput = (*runtimeJNIEnvPtr)->GetStaticMethodID(runtimeJNIEnvPtr, class_CTCAndroidInput, "receiveData", "(IIIII)V"); assert(method_ReceiveInput != NULL); diff --git a/Natives/JavaLauncher.m b/Natives/JavaLauncher.m index 5030ba57..ce83fe94 100644 --- a/Natives/JavaLauncher.m +++ b/Natives/JavaLauncher.m @@ -113,12 +113,7 @@ NSString* environmentFailsafes(int minVersion) { NSString *jre16Path = [NSString stringWithFormat:@"%@/java-16-openjdk", jvmPath]; NSString *jre17Path = [NSString stringWithFormat:@"%@/java-17-openjdk", jvmPath]; - BOOL foundJava8 = [fm fileExistsAtPath:jre8Path]; - if (!foundJava8) { - regLog("[JavaLauncher] Java 8 wasn't found on your device. Install Java 8 for more compatibility and the mod installer."); - } - - if (foundJava8 && minVersion <= 8) { + if ([fm fileExistsAtPath:jre8Path] && minVersion <= 8) { javaHome = jre8Path; } else if ([fm fileExistsAtPath:jre16Path] && minVersion <= 16) { javaHome = jre16Path; @@ -143,7 +138,7 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi NSString *javaHome_pre = getPreference(@"java_home"); // We handle unset JAVA_HOME right there - if (username == nil || getSelectedJavaVersion() < minVersion) { + if (getSelectedJavaVersion() < minVersion) { NSLog(@"[JavaLauncher] Attempting to change to Java %d (actual might be higher)", minVersion); javaHome_pre = environmentFailsafes(minVersion); NSLog(@"[JavaLauncher] JAVA_HOME is now set to %@", javaHome_pre); @@ -182,30 +177,9 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi allocmem_pre = [getPreference(@"allocated_memory") stringValue]; allocmem = [allocmem_pre cStringUsingEncoding:NSUTF8StringEncoding]; - - char classpath[10000]; // "/Applications/PojavLauncher.app/libs/launcher.jar:/Applications/PojavLauncher.app/libs/ExagearApacheCommons.jar:/Applications/PojavLauncher.app/libs/gson-2.8.6.jar:/Applications/PojavLauncher.app/libs/jsr305.jar:/Applications/PojavLauncher.app/libs/lwjgl3-minecraft.jar"; - // Generate classpath - DIR *d; - struct dirent *dir; - d = opendir(java_libs_path); - int cplen = -2; - if (d) { - // cplen += sprintf(classpath + cplen, "-Xbootclasspath/a:"); - while ((dir = readdir(d)) != NULL) { - if (cplen < 0) { - ++cplen; - continue; - } - cplen += sprintf(classpath + cplen, "%s/%s:", java_libs_path, dir->d_name); - } - classpath[cplen-1] = '\0'; - closedir(d); - } - debugLog("[JavaLauncher] Classpath generated: %s", classpath); - // Check if JVM restarts char *frameworkPath, *javaPath, *jnaLibPath, *userDir, *userHome, *memMin, *memMax, *arcDNS; asprintf(&frameworkPath, "-Djava.library.path=%1$s/Frameworks:%1$s/Frameworks/libOSMesaOverride.dylib.framework:%1$s/Frameworks/libMoltenVK.dylib.framework", getenv("BUNDLE_PATH")); @@ -238,6 +212,11 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi margv[++margc] = (char *) [NSString stringWithFormat:@"-Dpojav.selectedAccount=%@", selectedAccount].UTF8String; } + // Setup Caciocavallo + margv[++margc] = "-Djava.awt.headless=false"; + margv[++margc] = "-Dcacio.font.fontmanager=sun.awt.X11FontManager"; + margv[++margc] = "-Dcacio.font.fontscaler=sun.font.FreetypeFontScaler"; + // Load java char libjlipath8[2048]; // java 8 char libjlipath16[2048]; // java 16+ (?) @@ -257,38 +236,69 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi } // Setup Caciocavallo - margv[++margc] = "-Djava.awt.headless=false"; - margv[++margc] = "-Dcacio.font.fontmanager=sun.awt.X11FontManager"; - margv[++margc] = "-Dcacio.font.fontscaler=sun.font.FreetypeFontScaler"; margv[++margc] = "-Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel"; margv[++margc] = "-Dawt.toolkit=net.java.openjdk.cacio.ctc.CTCToolkit"; margv[++margc] = "-Djava.awt.graphicsenv=net.java.openjdk.cacio.ctc.CTCGraphicsEnvironment"; - - // Generate Caciocavallo bootclasspath - char cacio_libs_path[2048]; - char cacio_classpath[8192]; - sprintf((char*) cacio_libs_path, "%s/libs_caciocavallo", getenv("BUNDLE_PATH")); - cplen = sprintf(cacio_classpath, "-Xbootclasspath/p"); - d = opendir(cacio_libs_path); - int skip = 2; - if (d) { - while ((dir = readdir(d)) != NULL) { - if (skip > 0) { - --skip; - continue; - } - cplen += sprintf(cacio_classpath + cplen, ":%s/%s", cacio_libs_path, dir->d_name); - } - closedir(d); - } - margv[++margc] = cacio_classpath; } else { + // Required by Cosmetica to inject DNS margv[++margc] = "--add-opens=java.base/java.net=ALL-UNNAMED"; + // Setup Caciocavallo + margv[++margc] = "-Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel"; + margv[++margc] = "-Dawt.toolkit=com.github.caciocavallosilano.cacio.ctc.CTCToolkit"; + margv[++margc] = "-Djava.awt.graphicsenv=com.github.caciocavallosilano.cacio.ctc.CTCGraphicsEnvironment"; + // Required by Caciocavallo17 to access internal API + margv[++margc] = "--add-exports=java.desktop/java.awt=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/java.awt.peer=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/sun.awt.image=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/sun.java2d=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/java.awt.dnd.peer=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/sun.awt=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/sun.awt.event=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/sun.awt.datatransfer=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.desktop/sun.font=ALL-UNNAMED"; + margv[++margc] = "--add-exports=java.base/sun.security.action=ALL-UNNAMED"; + margv[++margc] = "--add-opens=java.base/java.util=ALL-UNNAMED"; + margv[++margc] = "--add-opens=java.desktop/java.awt=ALL-UNNAMED"; + margv[++margc] = "--add-opens=java.desktop/sun.font=ALL-UNNAMED"; + margv[++margc] = "--add-opens=java.desktop/sun.java2d=ALL-UNNAMED"; + margv[++margc] = "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED"; + // TODO: workaround, will be removed once the startup part works without PLaunchApp margv[++margc] = "--add-exports=cpw.mods.bootstraplauncher/cpw.mods.bootstraplauncher=ALL-UNNAMED"; } + // Add Caciocavallo bootclasspath + NSString *cacio_classpath = [NSString stringWithFormat:@"-Xbootclasspath/%s", isJava8 ? "p" : "a"]; + NSString *cacio_libs_path = [NSString stringWithFormat:@"%s/libs_caciocavallo%s", getenv("BUNDLE_PATH"), isJava8 ? "" : "17"]; + NSArray *files = [fm contentsOfDirectoryAtPath:cacio_libs_path error:nil]; + for(NSString *file in files) { + if ([file hasSuffix:@".jar"]) { + cacio_classpath = [NSString stringWithFormat:@"%@:%@/%@", cacio_classpath, cacio_libs_path, file]; + } + } + margv[++margc] = (char *)cacio_classpath.UTF8String; + +/* + char cacio_libs_path[2048]; + char cacio_classpath[8192]; + sprintf((char*) cacio_libs_path, "%s/libs_caciocavallo", getenv("BUNDLE_PATH")); + cplen = sprintf(cacio_classpath, "-Xbootclasspath/p"); + d = opendir(cacio_libs_path); + int skip = 2; + if (d) { + while ((dir = readdir(d)) != NULL) { + if (skip > 0) { + --skip; + continue; + } + cplen += sprintf(cacio_classpath + cplen, ":%s/%s", cacio_libs_path, dir->d_name); + } + closedir(d); + } + margv[++margc] = cacio_classpath; +*/ + if (!getEntitlementValue(@"com.apple.developer.kernel.extended-virtual-addressing")) { // In jailed environment, where extended virtual addressing entitlement isn't // present (for free dev account), the maximum metaspace size is 896M. @@ -311,7 +321,7 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi regLog("[Init] Found JLI lib"); margv[++margc] = "-cp"; - margv[++margc] = classpath; + margv[++margc] = (char *)[NSString stringWithFormat:@"%s/*", java_libs_path].UTF8String; margv[++margc] = "net.kdt.pojavlaunch.PojavLauncher"; if (username == nil) { diff --git a/Natives/LauncherViewController.m b/Natives/LauncherViewController.m index 4338db19..a7eaae2a 100644 --- a/Natives/LauncherViewController.m +++ b/Natives/LauncherViewController.m @@ -253,24 +253,11 @@ int versionSelectedAt = 0; } - (void)enterModInstaller:(UIBarButtonItem*)sender { - NSString *javaVer = getPreference(@"java_home"); - NSFileManager *fileManager = [NSFileManager defaultManager]; - if(![fileManager fileExistsAtPath:JRE8_HOME_JB] && getenv("POJAV_DETECTEDJB")) { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Cannot use the mod installer" message:@"In order to use the mod installer, you need to install Java 8." preferredStyle:UIAlertControllerStyleActionSheet]; - if (alert.popoverPresentationController != nil) { - alert.popoverPresentationController.sourceView = self.view; - alert.popoverPresentationController.sourceRect = CGRectMake(self.view.frame.size.width-10.0, 0, 10, 10); - } - UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; - [self presentViewController:alert animated:YES completion:nil]; - [alert addAction:ok]; - } else { - UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.sun.java-archive"] - inMode:UIDocumentPickerModeImport]; - documentPicker.delegate = self; - documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; - [self presentViewController:documentPicker animated:YES completion:nil]; - } + UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.sun.java-archive"] + inMode:UIDocumentPickerModeImport]; + documentPicker.delegate = self; + documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; + [self presentViewController:documentPicker animated:YES completion:nil]; } - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url { diff --git a/Natives/awt_xawt/xawt_fake.m b/Natives/awt_xawt/xawt_fake.m index dfa29694..794112fc 100644 --- a/Natives/awt_xawt/xawt_fake.m +++ b/Natives/awt_xawt/xawt_fake.m @@ -1,8 +1,13 @@ #include "../jni.h" -jfieldID colorValueID; +//jfieldID colorValueID; // java.awt.* +JNIEXPORT void JNICALL +Java_java_awt_AWTEvent_initIDs(JNIEnv *env, jclass cls) +{ +} + JNIEXPORT void JNICALL Java_java_awt_Button_initIDs (JNIEnv *env, jclass cls) @@ -13,7 +18,7 @@ JNIEXPORT void JNICALL Java_java_awt_Color_initIDs (JNIEnv *env, jclass clazz) { - colorValueID = (*env)->GetFieldID(env, clazz, "value", "I"); + //colorValueID = (*env)->GetFieldID(env, clazz, "value", "I"); } JNIEXPORT void JNICALL @@ -97,6 +102,11 @@ Java_java_awt_Frame_initIDs { } +JNIEXPORT void JNICALL +Java_java_awt_Insets_initIDs(JNIEnv *env, jclass cls) +{ +} + JNIEXPORT void JNICALL Java_java_awt_KeyboardFocusManager_initIDs (JNIEnv *env, jclass cls) @@ -191,6 +201,16 @@ Java_java_awt_AWTEvent_nativeSetSource(JNIEnv *env, jobject self, jobject newSou // Maybe implement this? } +JNIEXPORT void JNICALL +Java_java_awt_event_InputEvent_initIDs(JNIEnv *env, jclass cls) +{ +} + +JNIEXPORT void JNICALL +Java_java_awt_event_KeyEvent_initIDs(JNIEnv *env, jclass cls) +{ +} + JNIEXPORT void JNICALL Java_java_awt_event_MouseEvent_initIDs (JNIEnv *env, jclass clazz) diff --git a/Natives/main.m b/Natives/main.m index 9f0249b0..70e95990 100644 --- a/Natives/main.m +++ b/Natives/main.m @@ -231,10 +231,11 @@ int main(int argc, char * argv[]) { setenv("HOME", "/usr/share", 1); setenv("OLD_POJAV_HOME", "/var/mobile/Documents/.pojavlauncher", 1); setenv("POJAV_HOME", "/usr/share/pojavlauncher", 1); + // In this environment, libawt_xawt is not available/X11 only. + // hook dlopen to use our libawt_xawt + init_hookFunctions(); } else { setenv("POJAV_HOME", [NSString stringWithFormat:@"%s/Documents", getenv("HOME")].UTF8String, 1); - - init_hookFunctions(); } [fm createDirectoryAtPath:@(getenv("POJAV_HOME")) withIntermediateDirectories:NO attributes:nil error:nil]; diff --git a/Natives/main_hook.m b/Natives/main_hook.m index 968a9446..4f99b733 100644 --- a/Natives/main_hook.m +++ b/Natives/main_hook.m @@ -1,103 +1,22 @@ -#include -#include -#include -#include -#include +#import #include "external/fishhook/fishhook.h" -#import "utils.h" -int main(int argc, char * argv[]); - -static CFRunLoopRunResult (*orig_CFRunLoopRunInMode)(CFRunLoopMode mode, CFTimeInterval seconds, Boolean returnAfterSourceHandled); - -static int (*orig_dladdr)(const void* addr, Dl_info* info); static void* (*orig_dlopen)(const char* path, int mode); -//static void* (*orig_mmap)(void *addr, size_t len, int prot, int flags, int fd, off_t offset); -static char* (*orig_realpath)(const char *restrict path, char *restrict resolved_path); -pid_t (*orig_waitpid)(pid_t pid, int *status, int options); -//static void (*orig_sys_icache_invalidate)(void *start, size_t len); - - -int hooked_dladdr(const void* addr, Dl_info* info) { - //NSLog(@"hook dladdr(%p, %p)", addr, info); - int retVal = orig_dladdr(addr, info); - if (addr == main) { - //NSLog(@"hooked dladdr"); - info->dli_fname = getenv("JAVA_EXT_EXECNAME"); - } else if (retVal != 0) { - //NSLog(@"hooked dladdr"); - char *libname = basename((char *)info->dli_fname); - char src[2048], dst[2048]; - sprintf((char *)src, "%s/Frameworks", getenv("BUNDLE_PATH")); - if (0 == strncmp(info->dli_fname, src, strlen(src))) { - if (0 == strncmp(libname, "libjli.dylib", 12)) { - info->dli_fname = getenv("INTERNAL_JLI_PATH"); - } else if (0 == strncmp(libname, "libjvm.dylib", 12)) { - sprintf((char *)dst, "%s/lib/server/libjvm.dylib", getenv("JAVA_HOME")); - info->dli_fname = (char *)dst; - } - } - } - //if (retVal) NSLog(@"dli_fname=%s", info->dli_fname); - return retVal; -} void* hooked_dlopen(const char* path, int mode) { - //NSLog(@"dlopen(%s, %d)", path, mode); - - // Avoid loading the executable itself twice - if (path && [@(path) hasSuffix:@"PojavLauncher"]) { - return orig_dlopen(NULL, mode); + // Load our libawt_xawt + if (path && [@(path) hasSuffix:@"/libawt_xawt.dylib"]) { + return orig_dlopen([NSString stringWithFormat:@"%s/Frameworks/libawt_xawt.dylib", getenv("BUNDLE_PATH")].UTF8String, mode); } return orig_dlopen(path, mode); } -/* -void *hooked_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { - NSLog(@"mmap(%p, %ld, %d, %d, %d, %lld)", addr, len, prot, flags, fd, offset); - - if (flags & MAP_JIT) { - NSLog(@"'-> Found JIT mmap"); - //flags &= ~MAP_JIT; - } - - // raise(SIGINT); - return orig_mmap(addr, len, prot, flags, fd, offset); -} -*/ - -char *hooked_realpath(const char *restrict path, char *restrict resolved_path) { - //NSLog(@"hook realpath %s", path); - const char *javaHome = getenv("JAVA_HOME"); - if (0 == strncmp(path, javaHome, strlen(javaHome))) { - strcpy(resolved_path, path); - return resolved_path; - } else { - return orig_realpath(path, resolved_path); - } -} - -/* -void hooked_sys_icache_invalidate(void *start, size_t len) { - // mprotect(start, 16384, PROT_EXEC | PROT_READ); - // NSLog(@"mprotect errno %d", errno); - orig_sys_icache_invalidate(start, len); -} -*/ - void init_hookFunctions() { - // if (!started && strncmp(argv[0], "/Applications", 13)) - // Jailed only: hook some functions for symlinked JRE home dir - int retval = rebind_symbols((struct rebinding[3]){ - {"dladdr", hooked_dladdr, (void *)&orig_dladdr}, - {"dlopen", hooked_dlopen, (void *)&orig_dlopen}, - //{"realpath", hooked_realpath, (void *)&orig_realpath}, - {"realpath$DARWIN_EXTSN", hooked_realpath, (void *)&orig_realpath} - //{"mmap", hooked_mmap, (void *)&orig_mmap}, - //{"sys_icache_invalidate", hooked_sys_icache_invalidate, (void *)&orig_sys_icache_invalidate} - }, 3); + int retval = rebind_symbols((struct rebinding[1]){ + {"dlopen", hooked_dlopen, (void *)&orig_dlopen}, + }, 1); NSLog(@"hook retval = %d", retval); }