From 77214e8e94ef8762389068da63d1bcf148ddd2db Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 26 Jun 2015 15:49:08 -0700 Subject: [PATCH] Move installd patch to separated "patcyh" package. --- .gitignore | 1 - control | 5 +-- extrainst_.mm | 86 --------------------------------------------------- libuicache.mm | 37 ---------------------- makefile | 8 +---- 5 files changed, 2 insertions(+), 135 deletions(-) delete mode 100644 libuicache.mm diff --git a/.gitignore b/.gitignore index cfeb3bc..f891275 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,3 @@ uicache uiduid uiopen uishoot -libuicache.dylib diff --git a/control b/control index 7fbeadb..95ec2fb 100644 --- a/control +++ b/control @@ -4,12 +4,9 @@ Section: Utilities Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm Version: -Essential: yes Description: UIKit/GraphicsServices command line access Name: UIKit Tools Author: Jay Freeman (saurik) Depiction: http://cydia.saurik.com/info/uikittools/ -Depends: coreutils-bin, firmware (<< 8.2) | ldid -Replaces: taiguicache -Conflicts: taiguicache +Depends: coreutils-bin, firmware (<< 8.3) | com.saurik.patcyh Tag: purpose::console, role::hacker diff --git a/extrainst_.mm b/extrainst_.mm index d5f5e04..7c11540 100644 --- a/extrainst_.mm +++ b/extrainst_.mm @@ -133,86 +133,6 @@ void FixCache(NSString *home, NSString *plist) { printf("you must reboot to finalize your cache.\n"); } -#define INSTALLD "/usr/libexec/installd" -#define LIBUICACHE "/usr/lib/libuicache.dylib" - -static void *(*$memmem)(const void *, size_t, const void *, size_t); - -template -static bool PatchInstall(void *data) { - Header *header(reinterpret_cast
(data)); - - load_command *command(reinterpret_cast(header + 1)); - for (size_t i(0); i != header->ncmds; ++i) { - command = reinterpret_cast(reinterpret_cast(command) + command->cmdsize); - if (command->cmd != LC_LOAD_DYLIB) - continue; - - dylib_command *load(reinterpret_cast(command)); - const char *name(reinterpret_cast(command) + load->dylib.name.offset); - if (strcmp(name, LIBUICACHE) == 0) - return false; - } - - if (reinterpret_cast(command) != reinterpret_cast(header + 1) + header->sizeofcmds) - return false; - - dylib_command *load(reinterpret_cast(command)); - memset(load, 0, sizeof(*load)); - load->cmd = LC_LOAD_DYLIB; - - load->cmdsize = sizeof(*load) + sizeof(LIBUICACHE); - load->cmdsize = (load->cmdsize + 15) / 16 * 16; - memset(load + 1, 0, load->cmdsize - sizeof(*load)); - - dylib *dylib(&load->dylib); - dylib->name.offset = sizeof(*load); - memcpy(load + 1, LIBUICACHE, sizeof(LIBUICACHE)); - - ++header->ncmds; - header->sizeofcmds += load->cmdsize; - - return true; -} - -static bool PatchInstall() { - int fd(open(INSTALLD, O_RDWR)); - if (fd == -1) - return false; - - struct stat stat; - if (fstat(fd, &stat) == -1) { - close(fd); - return false; - } - - size_t size(stat.st_size); - void *data(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); - close(fd); - if (data == MAP_FAILED) - return false; - - bool changed(false); - switch (*reinterpret_cast(data)) { - case MH_MAGIC: - changed = PatchInstall(data); - break; - case MH_MAGIC_64: - changed = PatchInstall(data); - break; - } - - munmap(data, size); - - if (changed) { - system("ldid -s "INSTALLD""); - system("cp -af "INSTALLD" "INSTALLD"_"); - system("mv -f "INSTALLD"_ "INSTALLD""); - } - - return true; -} - int main(int argc, const char *argv[]) { if (argc < 2 || ( strcmp(argv[1], "install") != 0 && @@ -221,12 +141,6 @@ int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - $memmem = reinterpret_cast(dlsym(RTLD_DEFAULT, "memmem")); - - if (kCFCoreFoundationVersionNumber >= 1143) // XXX: iOS 8.3+ - if (PatchInstall()) - system("launchctl stop com.apple.mobile.installd"); - if (kCFCoreFoundationVersionNumber >= 700 && kCFCoreFoundationVersionNumber < 800) { // XXX: iOS 6.x NSString *home(@"/var/mobile"); NSString *plist([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]); diff --git a/libuicache.mm b/libuicache.mm deleted file mode 100644 index 0e107f4..0000000 --- a/libuicache.mm +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -@interface MIFileManager -+ (MIFileManager *) defaultManager; -- (NSURL *) destinationOfSymbolicLinkAtURL:(NSURL *)url error:(NSError *)error; -@end - -static Class $MIFileManager; - -static NSArray *(*_MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$)(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error); - -static NSArray *$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error) { - MIFileManager *manager(reinterpret_cast([$MIFileManager defaultManager])); - NSURL *destiny([manager destinationOfSymbolicLinkAtURL:url error:NULL]); - if (destiny == nil) - return _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(self, _cmd, url, YES, error); - - NSArray *prefix([url pathComponents]); - size_t skip([[destiny pathComponents] count]); - NSMutableArray *items([NSMutableArray array]); - for (NSURL *item in _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(self, _cmd, destiny, YES, error)) { - NSArray *components([item pathComponents]); - [items addObject:[NSURL fileURLWithPathComponents:[prefix arrayByAddingObjectsFromArray:[components subarrayWithRange:NSMakeRange(skip, [components count] - skip)]]]]; - } - - return items; -} - -__attribute__((__constructor__)) -static void initialize() { - $MIFileManager = objc_getClass("MIFileManager"); - SEL sel(@selector(urlsForItemsInDirectoryAtURL:ignoringSymlinks:error:)); - Method method(class_getInstanceMethod($MIFileManager, sel)); - _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$ = reinterpret_cast(method_getImplementation(method)); - method_setImplementation(method, reinterpret_cast(&$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$)); -} diff --git a/makefile b/makefile index e17bd50..386c82b 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -uikittools = uiduid uicache uiopen gssc sbdidlaunch sbreload cfversion iomfsetgamma libuicache.dylib +uikittools = uiduid uicache uiopen gssc sbdidlaunch sbreload cfversion iomfsetgamma all: $(uikittools) @@ -24,10 +24,6 @@ uishoot := -framework UIKit uicache: csstore.cpp extrainst_: csstore.cpp -%.dylib: %.mm - cycc -i2.0 -o$@ -- -dynamiclib $(flags) $^ $($@) -lobjc - ldid -S $@ - %: %.mm cycc -i2.0 -o$@ -- $^ $(flags) $($@) ldid -S$(wildcard $@.xml) $@ @@ -38,8 +34,6 @@ extrainst_: csstore.cpp package: all extrainst_ sudo rm -rf _ - mkdir -p _/usr/lib - cp -a $(filter %.dylib,$(uikittools)) _/usr/lib mkdir -p _/usr/bin cp -a $(filter-out %.dylib,$(uikittools)) _/usr/bin mkdir -p _/DEBIAN -- 2.45.2