#ifndef PATCH_HPP
#define PATCH_HPP
+#include <string>
+
#include <dlfcn.h>
#include <sys/mman.h>
#include <mach-o/loader.h>
-#define INSTALLD "/usr/libexec/installd"
#define LIBUICACHE "/usr/lib/libpatcyh.dylib"
static void *(*$memmem)(const void *, size_t, const void *, size_t) = reinterpret_cast<void *(*)(const void *, size_t, const void *, size_t)>(dlsym(RTLD_DEFAULT, "memmem"));
return true;
}
-static bool PatchInstall(bool uninstall, bool abort) {
+static bool Patch(const std::string &path, const std::string &service, bool uninstall, bool abort) {
if (!abort && system("ldid --") != 0) {
fprintf(stderr, "this package requires ldid to be installed\n");
return false;
}
- int fd(open(INSTALLD, O_RDWR));
+ int fd(open(path.c_str(), O_RDWR));
if (fd == -1)
return false;
munmap(data, size);
if (changed) {
- system("ldid -s "INSTALLD"");
- system("cp -af "INSTALLD" "INSTALLD"_");
- system("mv -f "INSTALLD"_ "INSTALLD"");
+ system(("ldid -s " + path + "").c_str());
+ system(("cp -af " + path + " " + path + "_").c_str());
+ system(("mv -f " + path + "_ " + path + "").c_str());
+ system(("launchctl stop " + service + "").c_str());
}
return true;
}
+
+static bool PatchInstall(bool uninstall, bool abort) {
+ return Patch("/usr/libexec/installd", "com.apple.mobile.installd", uninstall, abort);
+}
+
+static bool PatchLaunch(bool uninstall, bool abort) {
+ return Patch("/usr/libexec/lsd", "com.apple.lsd", uninstall, abort);
+}
+
#endif//PATCH_HPP
[items addObject:[NSURL fileURLWithPathComponents:[prefix arrayByAddingObjectsFromArray:[components subarrayWithRange:NSMakeRange(skip, [components count] - skip)]]]];
}
+ NSLog(@"items = %@", items);
return items;
}
+static NSString *(*_NSURL$path)(NSURL *self, SEL _cmd);
+
+static NSString *$NSURL$path(NSURL *self, SEL _cmd) {
+ return [[_NSURL$path(self, _cmd) mutableCopy] autorelease];
+}
+
+static NSRange (*_NSString$rangeOfString$options$)(NSString *self, SEL _cmd, NSString *value, NSStringCompareOptions options);
+
+static NSRange $NSString$rangeOfString$options$(NSString *self, SEL _cmd, NSString *value, NSStringCompareOptions options) {
+ if ([value isEqualToString:@".app/"]) do {
+ char *real(realpath("/Applications", NULL));
+ NSString *destiny([NSString stringWithUTF8String:real]);
+ free(real);
+
+ if ([destiny isEqualToString:@"/Applications"])
+ break;
+
+ destiny = [destiny stringByAppendingString:@"/"];
+ if (![self hasPrefix:destiny])
+ break;
+
+ if (![self hasSuffix:@".app"])
+ break;
+
+ BOOL directory;
+ if (![[NSFileManager defaultManager] fileExistsAtPath:self isDirectory:&directory])
+ break;
+ if (!directory)
+ break;
+
+ NSLog(@"path = %@", self);
+ // the trailing / allows lsd to "restart" its verification attempt
+ [(NSMutableString *) self setString:[NSString stringWithFormat:@"/Applications/%@/", [self substringFromIndex:[destiny length]]]];
+ } while (false);
+
+ return _NSString$rangeOfString$options$(self, _cmd, value, options);
+}
+
__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<NSArray *(*)(MIFileManager *, SEL, NSURL *, BOOL, NSError *)>(method_getImplementation(method));
- method_setImplementation(method, reinterpret_cast<IMP>(&$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$));
+
+ if ($MIFileManager != Nil) {
+ SEL sel(@selector(urlsForItemsInDirectoryAtURL:ignoringSymlinks:error:));
+ if (Method method = class_getInstanceMethod($MIFileManager, sel)) {
+ _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$ = reinterpret_cast<NSArray *(*)(MIFileManager *, SEL, NSURL *, BOOL, NSError *)>(method_getImplementation(method));
+ method_setImplementation(method, reinterpret_cast<IMP>(&$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$));
+ }
+ }
+
+ if (Class $NSURL = objc_getClass("NSURL")) {
+ SEL sel(@selector(path));
+ if (Method method = class_getInstanceMethod($NSURL, sel)) {
+ _NSURL$path = reinterpret_cast<NSString *(*)(NSURL *, SEL)>(method_getImplementation(method));
+ method_setImplementation(method, reinterpret_cast<IMP>(&$NSURL$path));
+ }
+ }
+
+ if (Class $NSString = objc_getClass("NSString")) {
+ SEL sel(@selector(rangeOfString:options:));
+ if (Method method = class_getInstanceMethod($NSString, sel)) {
+ _NSString$rangeOfString$options$ = reinterpret_cast<NSRange (*)(NSString *, SEL, NSString *, NSStringCompareOptions)>(method_getImplementation(method));
+ method_setImplementation(method, reinterpret_cast<IMP>(&$NSString$rangeOfString$options$));
+ }
+ }
}