From ec1afe94ca053015047690564f4e76e04dbbcc69 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Sat, 27 Aug 2022 17:07:12 +0700 Subject: [PATCH] Integrated JitStreamer attach on startup --- Natives/LoginViewController.m | 50 ++++++++++++++++++++++++++++ Natives/en.lproj/Localizable.strings | 5 +++ Natives/ios_uikit_bridge.m | 2 +- Natives/utils.h | 4 +++ Natives/utils.m | 11 +++++- README.md | 9 +++-- 6 files changed, 76 insertions(+), 5 deletions(-) diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 445b7a59..cffe6380 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -1,6 +1,7 @@ #include #include +#import "AFNetworking.h" #import #import "authenticator/BaseAuthenticator.h" @@ -188,6 +189,14 @@ technoNote.textAlignment = NSTextAlignmentCenter; [scrollView addSubview:technoNote]; } + + if (!getEntitlementValue(@"dynamic-codesigning")) { + if (isJITEnabled()) { + self.title = NSLocalizedString(@"login.jit.enabled", nil); + } else { + [self enableJITWithJitStreamer]; + } + } } - (void)displayProgress:(NSString *)title { @@ -375,6 +384,47 @@ [self presentViewController:vc animated:YES completion:nil]; } +- (void)enableJITWithJitStreamer +{ + [self displayProgress:NSLocalizedString(@"login.jit.checking", nil)]; + + // TODO: customizable address + NSString *address = @"69.69.0.1"; + + AFHTTPSessionManager *manager = AFHTTPSessionManager.manager; + manager.requestSerializer.timeoutInterval = 10; + manager.responseSerializer = AFHTTPResponseSerializer.serializer; + manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", nil]; + [manager GET:[NSString stringWithFormat:@"http://%@/version", address] parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask *task, NSData *response) { + NSString *version = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; + NSLog(@"Found JitStreamer %@", version); + self.title = NSLocalizedString(@"login.jit.found.JitStreamer", nil); + manager.requestSerializer.timeoutInterval = 0; + manager.responseSerializer = AFJSONResponseSerializer.serializer; + [manager POST:[NSString stringWithFormat:@"http://%@/attach/%d/", address, getpid()] parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask *task, id response) { + self.title = NSLocalizedString(@"login.jit.enabled", nil); + self.navigationItem.leftBarButtonItem = nil; + } failure:^(NSURLSessionDataTask *task, NSError *error) { + NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey]; + NSDictionary *errorDict = [NSJSONSerialization JSONObjectWithData:errorData options:0 error:nil]; + self.title = [NSString stringWithFormat:NSLocalizedString(@"login.jit.fail.JitStreamer", nil), errorDict[@"message"]]; + self.navigationItem.leftBarButtonItem = nil; + showDialog(self, NSLocalizedString(@"Error", nil), errorDict[@"message"]); + // Request may fail if detach is unsuccessful + if (isJITEnabled()) { + self.title = NSLocalizedString(@"login.jit.enabled", nil); + } else { + // TODO: [self enableJITWithAltJIT]; + } + }]; + } failure:^(NSURLSessionDataTask *task, NSError *error) { + self.title = @""; + self.navigationItem.leftBarButtonItem = nil; + //showDialog(self, @"Error", [NSString stringWithFormat:@"%@", error]); + // TODO: [self enableJITWithAltJIT]; + }]; +} + - (void)aboutLauncher { AboutLauncherViewController *vc = [[AboutLauncherViewController alloc] init]; diff --git a/Natives/en.lproj/Localizable.strings b/Natives/en.lproj/Localizable.strings index 6d809d5f..5280503e 100644 --- a/Natives/en.lproj/Localizable.strings +++ b/Natives/en.lproj/Localizable.strings @@ -21,6 +21,11 @@ "login.alert.title" = "Login"; "login.alert.field.username" = "Username"; +"login.jit.checking" = "Checking for JIT"; +"login.jit.enabled" = "JIT has been enabled"; +"login.jit.fail.JitStreamer" = "JitStreamer error: %@"; +"login.jit.found.JitStreamer" = "Found JitStreamer, enabling JIT"; + "login.menu.about" = "About PojavLauncher"; "login.menu.sendlogs" = "Send your logs"; "login.menu.updates" = "Recent updates"; diff --git a/Natives/ios_uikit_bridge.m b/Natives/ios_uikit_bridge.m index bc594c5c..0975e9ed 100644 --- a/Natives/ios_uikit_bridge.m +++ b/Natives/ios_uikit_bridge.m @@ -35,7 +35,7 @@ void internal_showDialog(UIViewController *viewController, NSString* title, NSSt void showDialog(UIViewController *viewController, NSString* title, NSString* message) { dispatch_async(dispatch_get_main_queue(), ^{ - internal_showDialog(currentVC(), title, message); + internal_showDialog(viewController ? viewController : currentVC(), title, message); }); } diff --git a/Natives/utils.h b/Natives/utils.h index 4d385fb4..4d4ee4ca 100644 --- a/Natives/utils.h +++ b/Natives/utils.h @@ -41,6 +41,10 @@ JavaVM* runtimeJavaVMPtr; JNIEnv* runtimeJNIEnvPtr; //__weak UIViewController *viewController; +#define CS_DEBUGGED 0x10000000 +int csops(pid_t pid, unsigned int ops, void *useraddr, size_t usersize); +BOOL isJITEnabled(); + void* gbuffer; // OSMesa framebuffer long showingWindow; int savedWidth, savedHeight; diff --git a/Natives/utils.m b/Natives/utils.m index 2fdd9606..42adc4d1 100644 --- a/Natives/utils.m +++ b/Natives/utils.m @@ -5,9 +5,9 @@ #include #include "log.h" - #include "utils.h" +BOOL getEntitlementValue(NSString *key); @implementation UIWindow(ext) @@ -48,6 +48,15 @@ UIViewController* currentVC() { return [delegate window].visibleViewController; } +BOOL isJITEnabled() { + if (getEntitlementValue(@"dynamic-codesigning")) { + return YES; + } + + int flags; + csops(getpid(), 0, &flags, sizeof(flags)); + return (flags & CS_DEBUGGED) != 0; +} NSMutableDictionary* parseJSONFromFile(NSString *path) { NSError *error; diff --git a/README.md b/README.md index 29d00b74..4fd2c0cd 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,13 @@ The [PojavLauncher Website](https://pojav.ml) has extensive documentation on how ### Without jailbreak (sideload as IPA) Note: This is experimental, although game works smoothly, you should not set Render distance too much. -1. Install [AltStore](https://altstore.io) +1. Install [AltStore](https://altstore.io). Others will also work. 2. Download an IPA build of PojavLauncher in the Actions tab. -3. Open the downloaded IPA in AltStore to install. -4. Launch PojavLauncher with JIT enabled. +3. Open the downloaded IPA in the sideload app to install. +4. For enabling JIT, choose one of these: + - Setup [JitStreamer](http://jitstreamer.com), then launch PojavLauncher. JIT will be automatically enabled on startup. This is the most convenient way. + - Launch PojavLauncher with `Enable JIT` option in AltStore. This requires the device to be plugged in the computer or have Wi-Fi syncing enabled. + - Setup and use others such as [Jitterbug](https://github.com/osy/Jitterbug). ### Procursus-bootstraps *Note: This is currently unavailable. Will be fixed soon! For the meantime, you can follow the same way as [below](#bingnerelucubratus-bootstraps)*.