Browse Source

use libjb now

Kevin Bradley 8 months ago
parent
commit
af8bc7e73c
5 changed files with 136 additions and 50 deletions
  1. 2 2
      uicache/Makefile
  2. 54 0
      uicache/libjb-rooted.tbd
  3. 8 0
      uicache/libjb.h
  4. 54 0
      uicache/libjb.tbd
  5. 18 48
      uicache/uicache.mm

+ 2 - 2
uicache/Makefile

@@ -1,5 +1,5 @@
 IPHONE_ARCHS = arm64
-TARGET = appletv:16.1:13.0
+TARGET = iphone:latest:13.0
 export GO_EASY_ON_ME=1
 #TARGET_IPHONEOS_DEPLOYMENT_VERSION = 6.0
 DEBUG = 0
@@ -8,7 +8,7 @@ include $(THEOS)/makefiles/common.mk
 TOOL_NAME = uicache
 uicache_FILES = uicache.mm csstore.cpp
 uicache_CFLAGS += -fvisibility=hidden -I.
-uicache_LDFLAGS += -F. -framework PineBoardServices -framework CoreServices
+uicache_LDFLAGS += -F. -framework CoreServices -L. -ljb #-framework PineBoardServices
 uicache_INSTALL_PATH = /usr/bin
 uicache_CODESIGN_FLAGS=-Suicache.xml
 uicache_CODESIGN=ldid

+ 54 - 0
uicache/libjb-rooted.tbd

@@ -0,0 +1,54 @@
+--- !tapi-tbd
+tbd-version:           4
+targets:               [ arm64-ios ]
+uuids:
+  - target: arm64-ios
+    value: '04AFBC2F-3E51-3930-8C9F-85B76FA0DDF0'
+flags:                 [ flat_namespace, not_app_extension_safe ]
+install-name:          /usr/lib/libjb.dylib
+current-version:       0
+compatibility-version: 0
+exports:
+  - targets:              [ arm64-ios ]
+    objc-classes:         [ APFSHelper, JBManager ]
+undefineds:
+  - targets:              [ arm64-ios ]
+    symbols:              [ _APFSVolumeDelete, _CFShow, _CFStringGetCStringPtr,
+                            _IOIteratorNext, _IOMasterPort, _IOObjectRelease,
+                            _IORegistryEntryCreateCFProperties,
+                            _IORegistryEntryGetPath,
+                            _IOServiceGetMatchingServices, _IOServiceMatching,
+                            __DefaultRuneLocale,
+                            ___CFConstantStringClassReference, ___assert_rtn,
+                            ___stack_chk_fail, ___stack_chk_guard,
+                            __dyld_register_func_for_add_image,
+                            __objc_empty_cache, __objc_empty_vtable, _abort,
+                            _asprintf, _bzero, _calloc, _class_addMethod,
+                            _class_addProperty, _class_addProtocol,
+                            _class_getInstanceMethod, _class_getInstanceVariable,
+                            _class_getName, _class_getSuperclass,
+                            _class_isMetaClass, _class_replaceMethod, _free,
+                            _getchar, _hash_create, _hash_search,
+                            _kCFCoreFoundationVersionNumber,
+                            _mach_port_deallocate, _mach_task_self_, _malloc,
+                            _memcpy, _method_setImplementation, _objc_alloc,
+                            _objc_allocateClassPair,
+                            _objc_autoreleaseReturnValue,
+                            _objc_constructInstance,
+                            _objc_copyClassNamesForImage,
+                            _objc_enumerationMutation, _objc_getClass,
+                            _objc_getMetaClass, _objc_getProtocol,
+                            _objc_getRequiredClass, _objc_initializeClassPair,
+                            _objc_lookUpClass, _objc_msgSend,
+                            _objc_registerClassPair, _objc_release, _objc_retain,
+                            _objc_retainAutorelease,
+                            _objc_retainAutoreleasedReturnValue,
+                            _object_getClass, _object_getIndexedIvars,
+                            _object_getIvar, _printf, _property_copyAttributeList,
+                            _protocol_getMethodDescription, _protocol_getName,
+                            _pthread_mutex_lock, _pthread_mutex_unlock,
+                            _sel_getUid, _strcmp, _strlen, _strncmp, dyld_stub_binder ]
+    objc-classes:         [ NSCharacterSet, NSFileManager, NSMutableArray,
+                            NSMutableDictionary, NSNumber, NSObject, NSPipe,
+                            NSPredicate, NSRegularExpression, NSString, NSTask ]
+...

+ 8 - 0
uicache/libjb.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+@interface JBManager: NSObject
++(NSString *)jbPrefix;
++(int)refreshPrefix;
++ (int)deleteVolume:(NSString *)volume;
++ (NSArray *)deviceArray;
+@end

+ 54 - 0
uicache/libjb.tbd

@@ -0,0 +1,54 @@
+--- !tapi-tbd
+tbd-version:           4
+targets:               [ arm64-ios ]
+uuids:
+  - target: arm64-ios
+    value: '04AFBC2F-3E51-3930-8C9F-85B76FA0DDF0'
+flags:                 [ flat_namespace, not_app_extension_safe ]
+install-name:          /fs/jb/usr/lib/libjb.dylib
+current-version:       0
+compatibility-version: 0
+exports:
+  - targets:              [ arm64-ios ]
+    objc-classes:         [ APFSHelper, JBManager ]
+undefineds:
+  - targets:              [ arm64-ios ]
+    symbols:              [ _APFSVolumeDelete, _CFShow, _CFStringGetCStringPtr,
+                            _IOIteratorNext, _IOMasterPort, _IOObjectRelease,
+                            _IORegistryEntryCreateCFProperties,
+                            _IORegistryEntryGetPath,
+                            _IOServiceGetMatchingServices, _IOServiceMatching,
+                            __DefaultRuneLocale,
+                            ___CFConstantStringClassReference, ___assert_rtn,
+                            ___stack_chk_fail, ___stack_chk_guard,
+                            __dyld_register_func_for_add_image,
+                            __objc_empty_cache, __objc_empty_vtable, _abort,
+                            _asprintf, _bzero, _calloc, _class_addMethod,
+                            _class_addProperty, _class_addProtocol,
+                            _class_getInstanceMethod, _class_getInstanceVariable,
+                            _class_getName, _class_getSuperclass,
+                            _class_isMetaClass, _class_replaceMethod, _free,
+                            _getchar, _hash_create, _hash_search,
+                            _kCFCoreFoundationVersionNumber,
+                            _mach_port_deallocate, _mach_task_self_, _malloc,
+                            _memcpy, _method_setImplementation, _objc_alloc,
+                            _objc_allocateClassPair,
+                            _objc_autoreleaseReturnValue,
+                            _objc_constructInstance,
+                            _objc_copyClassNamesForImage,
+                            _objc_enumerationMutation, _objc_getClass,
+                            _objc_getMetaClass, _objc_getProtocol,
+                            _objc_getRequiredClass, _objc_initializeClassPair,
+                            _objc_lookUpClass, _objc_msgSend,
+                            _objc_registerClassPair, _objc_release, _objc_retain,
+                            _objc_retainAutorelease,
+                            _objc_retainAutoreleasedReturnValue,
+                            _object_getClass, _object_getIndexedIvars,
+                            _object_getIvar, _printf, _property_copyAttributeList,
+                            _protocol_getMethodDescription, _protocol_getName,
+                            _pthread_mutex_lock, _pthread_mutex_unlock,
+                            _sel_getUid, _strcmp, _strlen, _strncmp, dyld_stub_binder ]
+    objc-classes:         [ NSCharacterSet, NSFileManager, NSMutableArray,
+                            NSMutableDictionary, NSNumber, NSObject, NSPipe,
+                            NSPredicate, NSRegularExpression, NSString, NSTask ]
+...

+ 18 - 48
uicache/uicache.mm

@@ -67,9 +67,7 @@
 #import <xpc/xpc.h>
 
 #import "NSTask.h"
-#include <spawn.h>
-#include <sys/wait.h>
-
+#import "libjb.h"
 #include "csstore.hpp"
 
 #if TARGET_OS_IPHONE
@@ -187,40 +185,12 @@ static Class $LSApplicationWorkspace;
 LSApplicationWorkspace *workspace;
 static bool force;
 
-extern char **environ;
-static NSString *prefixPath = @"/fs/jb";
-
-BOOL _determineUsePrefixes(void) {
-    return ([[NSFileManager defaultManager] contentsOfDirectoryAtPath:prefixPath error:nil].count > 0);
+NSString *prefixPath(void) {
+    return [JBManager jbPrefix];
 }
 
 NSString *applicationPath(void) {
-    return _determineUsePrefixes() ? [prefixPath stringByAppendingPathComponent:@"Applications"] : @"/Applications";
-}
-
-int my_system(const char *cmd) {
-    pid_t pid;
-    char *argv[] = {"bash", "-c", (char*)cmd, NULL};
-    int status;
-    fprintf(stderr, "Run command: %s\n", cmd);
-    BOOL prefixes = _determineUsePrefixes();
-    NSString *shPath = @"/bin/sh";
-    if (prefixes) {
-        shPath = [prefixPath stringByAppendingPathComponent:shPath];
-    }
-    status = posix_spawn(&pid, [shPath UTF8String], NULL, NULL, argv, environ);;
-    if (status == 0) {
-        printf("Child pid: %i\n", pid);
-        if (waitpid(pid, &status, 0) != -1) {
-            printf("Child exited with status %i\n", status);
-            
-        } else {
-            perror("waitpid");
-        }
-    } else {
-        printf("posix_spawn: %s\n", strerror(status));
-    }
-    return status;
+    return [prefixPath() stringByAppendingPathComponent:@"/Applications"];
 }
 
 NSArray *getAllApplications()
@@ -277,6 +247,8 @@ NSString *pathInApplications(NSString *path) {
     } else if ([path hasPrefix:@"/var/stash"] && [pathComponents[4] isEqualToString:@"Applications"]) {
         // Matches /var/stash/*/Applications/
         return [@"/Applications/" stringByAppendingPathComponent:pathComponents[5]];
+    } else if ([path hasPrefix:prefixPath()] && [prefixPath() length] > 1) {
+        return path;
     }
     return nil;
 }
@@ -459,14 +431,14 @@ int standard_uicache(void)
     NSString *home(NSHomeDirectory());
     NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]);
 
-    my_system("killall -SIGSTOP " FRONTBOARD);
+    system("killall -SIGSTOP " FRONTBOARD);
     sleep(1);
 
     @try {
 
     DeleteCSStores([home UTF8String]);
 
-    my_system("killall lsd");
+    system("killall lsd");
 
     if ([workspace respondsToSelector:@selector(invalidateIconCache:)])
         while (![workspace invalidateIconCache:nil])
@@ -564,16 +536,16 @@ int standard_uicache(void)
         unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons", home] UTF8String]);
         unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist", home] UTF8String]);
 
-        my_system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]);
-        my_system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]);
+        system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]);
+        system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]);
 
-        my_system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]);
+        system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]);
     }
 
-    my_system("killall installd");
+    system("killall installd");
 
     } @finally {
-        my_system("killall -SIGCONT " FRONTBOARD);
+        system("killall -SIGCONT " FRONTBOARD);
     }
 
     notify_post("com.apple.mobile.application_installed");
@@ -593,7 +565,8 @@ pid_t pidOfCydia(void) {
     xpc_dictionary_apply((xpc_object_t)response, ^bool(const char *key, xpc_object_t value) {
         if (xpc_get_type(value) == XPC_TYPE_DICTIONARY) {
             const char *program = xpc_dictionary_get_string(value, "Program");
-            if (program && strcmp(program, "/Applications/Cydia.app/Cydia") == 0) {
+            NSString *cydiaPath = [applicationPath() stringByAppendingPathComponent:@"Cydia.app/Cydia"];
+            if (program && strcmp(program, [cydiaPath UTF8String]) == 0) {
                 pid = (pid_t)xpc_dictionary_get_int64(value, "PID");
                 if (verbose) fprintf(stderr, "Found Cydia running with PID: %d\n", pid);
                 return false;
@@ -682,7 +655,7 @@ int optimized_uicache(void) {
             pid_t cydia_pid;
             // Check for updated components
             NSTask *find = [NSTask new];
-            [find setLaunchPath:@"/fs/jb/usr/bin/find"];
+            [find setLaunchPath:[prefixPath() stringByAppendingPathComponent:@"/usr/bin/find"]];
             [find setStandardOutput:[NSPipe pipe]];
             NSString *stampPath = [NSString stringWithFormat:@"/var/tmp/uicache.stamp.%@", app.applicationIdentifier];
             [fm createFileAtPath:stampPath contents:nil attributes:@{NSFileModificationDate: lastRegistered}];
@@ -769,7 +742,6 @@ int main(int argc, const char *argv[])
         NSString *app_id = NULL;
         char ch;
         bool have_path = false;
-        force = true;
         while ((ch = getopt_long(argc, (char *const *)argv, "afl::p:ru:vh?", long_options, &option_index)) != -1) {
             switch (ch)
             {
@@ -783,7 +755,6 @@ int main(int argc, const char *argv[])
                     usage();
                     break;
                 case 'l':
-                    force = true;
                     if (optarg) {
                         app_id = @(optarg);
                     } else if (argv[optind] != NULL && argv[optind][0] != '-') {
@@ -808,7 +779,6 @@ int main(int argc, const char *argv[])
                     verbose++;
                     break;
                 default:
-                    force = true;
                     break;
             }
         }
@@ -853,8 +823,8 @@ int main(int argc, const char *argv[])
                     usleep(1000);
                 }
             } else {
-                my_system("launchctl stop " FRONTBOARD_ID);
-                my_system("launchctl stop com.apple.backboardd");
+                system("launchctl stop " FRONTBOARD_ID);
+                system("launchctl stop com.apple.backboardd");
             }
 #elif TARGET_OS_TV
             [[[PBSSystemServiceConnection sharedConnection] systemServiceProxy] relaunchBackboardd];