Add option to open app with JIT

This commit is contained in:
khanhduytran0 2024-01-23 18:18:57 +07:00
parent 0cc5ab1978
commit 647f43087c
10 changed files with 106 additions and 3 deletions

View File

@ -14,6 +14,6 @@ trollstorehelper_CODESIGN_FLAGS = --entitlements entitlements.plist
trollstorehelper_INSTALL_PATH = /usr/local/bin trollstorehelper_INSTALL_PATH = /usr/local/bin
trollstorehelper_LIBRARIES = archive trollstorehelper_LIBRARIES = archive
trollstorehelper_FRAMEWORKS = CoreTelephony trollstorehelper_FRAMEWORKS = CoreTelephony
trollstorehelper_PRIVATE_FRAMEWORKS = SpringBoardServices BackBoardServices MobileContainerManager FrontBoardServices trollstorehelper_PRIVATE_FRAMEWORKS = SpringBoardServices BackBoardServices MobileContainerManager FrontBoardServices RunningBoardServices
include $(THEOS_MAKE_PATH)/tool.mk include $(THEOS_MAKE_PATH)/tool.mk

View File

@ -48,5 +48,7 @@
<true/> <true/>
<key>com.apple.frontboard.shutdown</key> <key>com.apple.frontboard.shutdown</key>
<true/> <true/>
<key>com.apple.runningboard.process-state</key>
<true/>
</dict> </dict>
</plist> </plist>

3
RootHelper/jit.h Normal file
View File

@ -0,0 +1,3 @@
#import <Foundation/Foundation.h>
int enableJIT(NSString *bundleID);

45
RootHelper/jit.m Normal file
View File

@ -0,0 +1,45 @@
@import Foundation;
@import Darwin;
@interface RBSProcessPredicate
+ (instancetype)predicateMatchingBundleIdentifier:(NSString *)bundleID;
@end
@interface RBSProcessHandle
+ (instancetype)handleForPredicate:(RBSProcessPredicate *)predicate error:(NSError **)error;
- (int)rbs_pid;
@end
#define PT_DETACH 11
#define PT_ATTACHEXC 14
int ptrace(int request, pid_t pid, caddr_t addr, int data);
int enableJIT(NSString *bundleID) {
#ifdef EMBEDDED_ROOT_HELPER
return -1;
#else
RBSProcessPredicate *predicate = [RBSProcessPredicate predicateMatchingBundleIdentifier:bundleID];
RBSProcessHandle* process = [RBSProcessHandle handleForPredicate:predicate error:nil];
int pid = process.rbs_pid;
if (!pid)
{
return ESRCH;
}
int ret = ptrace(PT_ATTACHEXC, pid, 0, 0);
if (ret == -1)
{
return errno;
}
usleep(100000);
ret = ptrace(PT_DETACH, pid, 0, 0);
if (ret == -1)
{
return errno;
}
return 0;
#endif
}

View File

@ -11,6 +11,7 @@
#import <mach-o/loader.h> #import <mach-o/loader.h>
#import <mach-o/fat.h> #import <mach-o/fat.h>
#import "devmode.h" #import "devmode.h"
#import "jit.h"
#ifndef EMBEDDED_ROOT_HELPER #ifndef EMBEDDED_ROOT_HELPER
#import "codesign.h" #import "codesign.h"
#import "coretrust_bug.h" #import "coretrust_bug.h"
@ -1573,6 +1574,12 @@ int MAIN_NAME(int argc, char *argv[], char *envp[])
// Give the system some time to reboot // Give the system some time to reboot
sleep(1); sleep(1);
} }
else if([cmd isEqualToString:@"enable-jit"])
{
if(args.count < 2) return -3;
NSString* userAppId = args.lastObject;
ret = enableJIT(userAppId);
}
NSLog(@"trollstorehelper returning %d", ret); NSLog(@"trollstorehelper returning %d", ret);
return ret; return ret;

View File

@ -50,6 +50,7 @@
- (NSAttributedString*)detailedInfoTitle; - (NSAttributedString*)detailedInfoTitle;
- (NSAttributedString*)detailedInfoDescription; - (NSAttributedString*)detailedInfoDescription;
//- (UIImage*)image; //- (UIImage*)image;
- (BOOL)isDebuggable;
- (void)log; - (void)log;
@end @end

View File

@ -1165,5 +1165,23 @@ extern UIImage* imageWithSize(UIImage* image, CGSize size);
}]; }];
} }
- (BOOL)isDebuggable
{
[self loadEntitlements];
__block BOOL debuggable = NO;
[self enumerateAllEntitlements:^(NSString *key, NSObject *value, BOOL *stop)
{
if([key isEqualToString:@"get-task-allow"])
{
NSNumber* valueNum = (NSNumber*)value;
if(valueNum && [valueNum isKindOfClass:NSNumber.class])
{
debuggable = valueNum.boolValue;
*stop = YES;
}
}
}];
return debuggable;
}
@end @end

View File

@ -187,7 +187,7 @@ UIImage* imageWithSize(UIImage* image, CGSize size)
[TSInstallationController presentInstallationAlertIfEnabledForFile:pathToIPA isRemoteInstall:NO completion:nil]; [TSInstallationController presentInstallationAlertIfEnabledForFile:pathToIPA isRemoteInstall:NO completion:nil];
} }
- (void)openAppPressedForRowAtIndexPath:(NSIndexPath*)indexPath - (void)openAppPressedForRowAtIndexPath:(NSIndexPath*)indexPath enableJIT:(BOOL)enableJIT
{ {
TSApplicationsManager* appsManager = [TSApplicationsManager sharedInstance]; TSApplicationsManager* appsManager = [TSApplicationsManager sharedInstance];
@ -211,6 +211,17 @@ UIImage* imageWithSize(UIImage* image, CGSize size)
[didFailController addAction:cancelAction]; [didFailController addAction:cancelAction];
[TSPresentationDelegate presentViewController:didFailController animated:YES completion:nil]; [TSPresentationDelegate presentViewController:didFailController animated:YES completion:nil];
} }
else if (enableJIT)
{
int ret = [appsManager enableJITForBundleID:appId];
if (ret != 0)
{
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Error enabling JIT: trollstorejithelper returned %d", ret] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
[errorAlert addAction:closeAction];
[TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil];
}
}
} }
- (void)showDetailsPressedForRowAtIndexPath:(NSIndexPath*)indexPath - (void)showDetailsPressedForRowAtIndexPath:(NSIndexPath*)indexPath
@ -424,11 +435,21 @@ UIImage* imageWithSize(UIImage* image, CGSize size)
UIAlertAction* openAction = [UIAlertAction actionWithTitle:@"Open" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) UIAlertAction* openAction = [UIAlertAction actionWithTitle:@"Open" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action)
{ {
[self openAppPressedForRowAtIndexPath:indexPath]; [self openAppPressedForRowAtIndexPath:indexPath enableJIT:NO];
[self deselectRow]; [self deselectRow];
}]; }];
[appSelectAlert addAction:openAction]; [appSelectAlert addAction:openAction];
if ([appInfo isDebuggable])
{
UIAlertAction* openWithJITAction = [UIAlertAction actionWithTitle:@"Open with JIT" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action)
{
[self openAppPressedForRowAtIndexPath:indexPath enableJIT:YES];
[self deselectRow];
}];
[appSelectAlert addAction:openWithJITAction];
}
UIAlertAction* showDetailsAction = [UIAlertAction actionWithTitle:@"Show Details" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) UIAlertAction* showDetailsAction = [UIAlertAction actionWithTitle:@"Show Details" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action)
{ {
[self showDetailsPressedForRowAtIndexPath:indexPath]; [self showDetailsPressedForRowAtIndexPath:indexPath];

View File

@ -16,6 +16,7 @@
- (int)uninstallApp:(NSString*)appId; - (int)uninstallApp:(NSString*)appId;
- (int)uninstallAppByPath:(NSString*)path; - (int)uninstallAppByPath:(NSString*)path;
- (BOOL)openApplicationWithBundleID:(NSString *)appID; - (BOOL)openApplicationWithBundleID:(NSString *)appID;
- (int)enableJITForBundleID:(NSString *)appID;
- (int)changeAppRegistration:(NSString*)appPath toState:(NSString*)newState; - (int)changeAppRegistration:(NSString*)appPath toState:(NSString*)newState;
@end @end

View File

@ -179,6 +179,11 @@ extern NSUserDefaults* trollStoreUserDefaults();
return [[LSApplicationWorkspace defaultWorkspace] openApplicationWithBundleID:appId]; return [[LSApplicationWorkspace defaultWorkspace] openApplicationWithBundleID:appId];
} }
- (int)enableJITForBundleID:(NSString *)appId
{
return spawnRoot(rootHelperPath(), @[@"enable-jit", appId], nil, nil);
}
- (int)changeAppRegistration:(NSString*)appPath toState:(NSString*)newState - (int)changeAppRegistration:(NSString*)appPath toState:(NSString*)newState
{ {
if(!appPath || !newState) return -200; if(!appPath || !newState) return -200;