Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------includes-------//
- #include <limits.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include <unistd.h>
- #include <string.h>
- #include <dlfcn.h>
- #include <mach-o/dyld.h>
- #include <sys/stat.h>
- #include <sys/attr.h>
- #include <Foundation/Foundation.h>
- #include <AppSupport/CPDistributedMessagingCenter.h>
- #include <rocketbootstrap.h>
- #include <substrate.h>
- #include <sys/syscall.h>
- #include <dirent.h>
- int statfs(const char *path, struct statfs *buf);
- //#define printf(a, ...)
- //#define NSLog(a, ...)
- //-------pointers-------//
- FILE* (*orig_fopen)(const char * filename, const char * mode);
- int (*orig_access)(const char *pathname, int mode);
- int (*orig_open)(const char *path, int oflags);
- int (*orig_stat)(const char *pathname, struct stat *statbuf);
- int (*orig_lstat)(const char *pathname, struct stat *statbuf);
- int (*orig_statfs)(const char *path, struct statfs *buf);
- ssize_t (*orig_readlink)(const char *path, char *buf, size_t bufsiz);
- const char *(*orig_dyld_get_image_name)(uint32_t index);
- uint32_t (*orig_dyld_image_count)(void);
- void *(*orig_dlopen)(const char *filename, int flag);
- void *(*orig_dlsym)(void *handle, const char *name);
- char *(*orig_dlerror)(void);
- char *(*orig_getenv)(const char * name);
- int (*orig_getattrlist)(const char *path, struct attrlist * attr, void * info, size_t size, unsigned int smth);
- DIR *(*orig_opendir)(const char *dirname);
- CPDistributedMessagingCenter * __strong messagingCenter; //message center
- char fake_err[2000];
- char *ourBundle;
- char *ourContainer;
- //-------defines-------//
- #define startsWith(string, what) !(strncmp(string, what, strlen(what)))
- #define endsWith(string, what) !(strncmp(string + strlen(string)-strlen(what), what, strlen(what)))
- //----usefulness----//
- bool isMacho(const char* path) {
- if (!messagingCenter) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. oof!");
- return true;
- }
- NSDictionary *userInfoDict = [NSDictionary dictionaryWithObject:@(path) forKey:@"path"];
- NSDictionary *response = [messagingCenter sendMessageAndReceiveReplyName:@"isMacho" userInfo:userInfoDict];
- BOOL isMacho = [[response objectForKey:@"isMacho"] boolValue];
- return isMacho;
- }
- char *realPath(const char* path) {
- if (!messagingCenter) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. oof!");
- return NULL;
- }
- NSDictionary *userInfoDict = [NSDictionary dictionaryWithObject:@(path) forKey:@"path"];
- NSDictionary *response = [messagingCenter sendMessageAndReceiveReplyName:@"realPath" userInfo:userInfoDict];
- return strdup([[response objectForKey:@"realpath"] UTF8String]);
- }
- //-------functions-------//
- bool wouldAmfidLikeThis(const char* path) {
- // 😏
- NSLog(@"[unescaper] Validating %s", path);
- if (strstr(path, "Flex.dylib")) {
- NSLog(@"[unescaper] %s", "Not valid!");
- return false;
- }
- if (!messagingCenter) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. oof!");
- return true;
- }
- NSDictionary *userInfoDict = [NSDictionary dictionaryWithObject:@(path) forKey:@"path"];
- NSDictionary *response = [messagingCenter sendMessageAndReceiveReplyName:@"validate" userInfo:userInfoDict];
- BOOL isValid = [[response objectForKey:@"isValid"] boolValue];
- NSLog(@"[unescaper] %s", isValid ? "VALID!" : "Not valid!");
- return isValid;
- }
- bool isOutsideSandbox(const char* path) {
- NSLog(@"[unescaper] outside sandbox %s?", path);
- if (path == NULL) {
- printf("[unescaper] Yes!\n");
- return true;
- }
- // legit
- if (strstr(path, ourContainer)) {
- printf("[unescaper] No!\n");
- return false;
- }
- if (strstr(path, ourBundle)) {
- printf("[unescaper] No!\n");
- return false;
- }
- if (strstr(path, "/var/mobile/Library/Caches/com.apple.UIStatusBar")) {
- printf("[unescaper] No!\n");
- return false;
- }
- // smart boi haha
- path = realPath(path);
- if (!path) {
- printf("[unescaper] Yes!\n");
- return true;
- }
- if (!strlen(path)) {
- printf("[unescaper] Yes!\n");
- return true;
- }
- bool rv;
- rv = (
- startsWith(path, "/Library") ||
- startsWith(path, "/private/var/mobile/Library") ||
- startsWith(path, "/private/var/mnt") ||
- startsWith(path, "/private/var/db") ||
- startsWith(path, "/private/var/stash")
- );
- printf("[unescaper][sandbox] returned: %d\n", (int)rv);
- return rv;
- }
- bool shallExist(const char *path) {
- NSLog(@"[unescaper] shall exist %s?", path);
- if (strstr(path, "UNESCAPER")) {
- printf("[unescaper] No!\n");
- return false;
- }
- if (path == NULL) {
- printf("[unescaper] No!\n");
- return false;
- }
- // legit
- if (strstr(path, ourContainer)) {
- printf("[unescaper] Yes!\n");
- return true;
- }
- if (strstr(path, ourBundle)) {
- printf("[unescaper] Yes!\n");
- return true;
- }
- // smart boi haha
- // bypass "//", ".", ".." etc
- path = realPath(path);
- if (!path) {
- printf("[unescaper] No!\n");
- return false;
- }
- if (!strlen(path)) {
- printf("[unescaper] No!\n");
- return false;
- }
- // nothing can decieve us
- if (isMacho(path) || endsWith(path, ".app")) {
- bool rv = wouldAmfidLikeThis(path);
- printf("[unescaper][shall exist] returned: %d\n", rv);
- return rv;
- }
- else {
- bool rv;
- rv = (
- !(strstr(path, "apt") ||
- strstr(path, "dropbear") ||
- strstr(path, "ssh") ||
- strstr(path, "filza") ||
- strstr(path, "git-core") ||
- strstr(path, "gnupg") ||
- strstr(path, "cydia") ||
- strstr(path, "dpkg") ||
- strstr(path, "theos") ||
- strstr(path, "Substrate") ||
- startsWith(path, "/Library/LaunchDaemons") ||
- startsWith(path, "/Library/Themes") ||
- startsWith(path, "/private/var/stash") ||
- startsWith(path, "/var/stash")
- )
- );
- printf("[unescaper][shall exist] returned: %d\n", (int)rv);
- return rv;
- }
- }
- FILE* our_fopen(const char * filename, const char * mode) {
- if (!filename || !mode) return orig_fopen(filename, mode);
- NSLog(@"[unescaper] fopen %s\n", filename);
- if (!shallExist(filename)) {
- errno = ENOENT;
- return NULL;
- }
- if (isOutsideSandbox(filename)) {
- errno = EPERM;
- return NULL;
- }
- return orig_fopen(filename, mode);
- }
- int our_access(const char *pathname, int mode) {
- if (!pathname) return orig_access(pathname, mode);
- NSLog(@"[unescaper] access %s\n", pathname);
- if (!shallExist(pathname)) {
- errno = ENOENT;
- return -1;
- }
- if (mode != F_OK) {
- if (isOutsideSandbox(pathname)) {
- errno = EPERM;
- return -1;
- }
- }
- return orig_access(pathname, mode);
- }
- int our_open(const char *path, int oflags) {
- if (!path) return orig_open(path, oflags);
- NSLog(@"[unescaper] open %s\n", path);
- if (!shallExist(path)) {
- errno = ENOENT;
- return -1;
- }
- if (isOutsideSandbox(path)) {
- errno = EPERM;
- return -1;
- }
- return orig_open(path, oflags);
- }
- DIR *our_opendir(const char *path) {
- if (!path) return orig_opendir(path);
- NSLog(@"[unescaper] opendir %s\n", path);
- if (!shallExist(path)) {
- errno = ENOENT;
- return NULL;
- }
- if (isOutsideSandbox(path)) {
- errno = EPERM;
- return NULL;
- }
- return orig_opendir(path);
- }
- int our_stat(const char *pathname, struct stat *statbuf) {
- if (!pathname) return orig_stat(pathname, statbuf);
- NSLog(@"[unescaper] stat %s\n", pathname);
- if (!shallExist(pathname)) {
- errno = ENOENT;
- return -1;
- }
- if (isOutsideSandbox(pathname)) {
- errno = EPERM;
- return -1;
- }
- return orig_stat(pathname, statbuf);
- }
- int our_lstat(const char *pathname, struct stat *statbuf) {
- if (!pathname || !statbuf) return orig_lstat(pathname, statbuf);
- NSLog(@"[unescaper] lstat %s\n", pathname);
- if (!shallExist(pathname)) {
- errno = ENOENT;
- return -1;
- }
- if (isOutsideSandbox(pathname)) {
- errno = EPERM;
- return -1;
- }
- return orig_lstat(pathname, statbuf);
- }
- int our_statfs(const char *path, struct statfs *buf) {
- if (!path || !buf) return orig_statfs(path, buf);
- NSLog(@"[unescaper] statfs %s\n", path);
- if (!shallExist(path)) {
- errno = ENOENT;
- return -1;
- }
- if (isOutsideSandbox(path)) {
- errno = EPERM;
- return -1;
- }
- return orig_statfs(path, buf);
- }
- int our_getattrlist(const char *path, struct attrlist * attr, void * info, size_t size, unsigned int smth) {
- if (!path || !attr || !info) return orig_getattrlist(path, attr, info, size, smth);
- NSLog(@"[unescaper] getattrlist %s\n", path);
- if (!shallExist(path)) {
- errno = ENOENT;
- return -1;
- }
- if (isOutsideSandbox(path)) {
- errno = EPERM;
- return -1;
- }
- return orig_getattrlist(path, attr, info, size, smth);
- }
- ssize_t our_readlink(const char *path, char *buf, size_t bufsiz) {
- if (!path || !buf) return orig_readlink(path, buf, bufsiz);
- NSLog(@"[unescaper] readlink %s\n", path);
- if (!shallExist(path)) {
- errno = ENOENT;
- return -1;
- }
- if (isOutsideSandbox(path)) {
- errno = EPERM;
- return -1;
- }
- return orig_readlink(path, buf, bufsiz);
- }
- const char* our_dyld_get_image_name(uint32_t image_index) {
- printf("[unescaper] Called _dyld_get_image_name!\n");
- char *buf = (char *)malloc(strlen(ourContainer) + strlen("/tmp/UNESCAPER.txt") + 1);
- strcpy(buf, ourContainer);
- strcat(buf, "/tmp/UNESCAPER.txt");
- FILE *f = orig_fopen(buf, "r");
- free(buf);
- buf = NULL;
- if (!f) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. KK!");
- printf("[unescaper] err %s\n", strerror(errno));
- return orig_dyld_get_image_name(image_index);
- }
- uint32_t index = -1;
- size_t size = 0;
- char ch = fgetc(f);
- loop:;
- while (ch != '\n') {
- if (ch == EOF) {
- fclose(f);
- return NULL;
- }
- ch = fgetc(f);
- size++;
- }
- index++;
- if (index != image_index) {
- ch = fgetc(f);
- size = 0;
- goto loop;
- }
- buf = (char *)malloc(size + 1);
- bzero(buf, size + 1);
- fseek(f, -(size + 1), SEEK_CUR);
- fread(buf, size, 1, f);
- fclose(f);
- char *str = strdup(buf);
- free(buf);
- buf = NULL;
- printf("[unescaper] At index %u we have %s\n", image_index, str);
- return str;
- }
- uint32_t our_dyld_image_count() {
- printf("[unescaper] Getting image count!\n");
- char *buf = (char *)malloc(strlen(ourContainer) + strlen("/tmp/UNESCAPER.txt") + 1);
- strcpy(buf, ourContainer);
- strcat(buf, "/tmp/UNESCAPER.txt");
- FILE *f = orig_fopen(buf, "r");
- free(buf);
- buf = NULL;
- if (!f) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. KK!");
- printf("[unescaper] err %s\n", strerror(errno));
- return orig_dyld_image_count();
- }
- uint32_t count = 0;
- char ch = fgetc(f);
- while (ch != EOF) {
- if (ch == '\n') count++;
- ch = fgetc(f);
- }
- printf("[unescaper] found %u libs\n", count);
- return count;
- }
- void *our_dlopen(const char *filename, int flag) {
- if (!filename) return orig_dlopen(filename, flag);
- // inject anyway
- // so kids can still use their cheats
- void *h = orig_dlopen(filename, flag);
- // in dyld shared cache
- if (h && orig_access(filename, F_OK)) {
- char *buf = (char *)malloc(strlen(ourContainer) + strlen("/tmp/UNESCAPER.txt") + 1);
- strcpy(buf, ourContainer);
- strcat(buf, "/tmp/UNESCAPER.txt");
- FILE *f = orig_fopen(buf, "a+");
- free(buf);
- buf = NULL;
- if (!f) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. Ohi!");
- strcpy(fake_err, orig_dlerror());
- return h;
- }
- buf = (char *)malloc(strlen(filename) + 1);
- bzero(buf, strlen(filename) + 1);
- int off = 0;
- bool found = false;
- while (!feof(f)) {
- fread(buf, strlen(filename), 1, f);
- fseek(f, off, SEEK_SET);
- printf("[-] Found %s and looking for %s\n", buf, filename);
- if (!strcmp(buf, filename)) {
- printf("[unescaper] %s already added!\n", filename);
- found = true;
- break;
- }
- fgetc(f);
- off++;
- }
- if (!found) fprintf(f, "%s\n", filename);
- fclose(f);
- strcpy(fake_err, "");
- return h;
- }
- // loaded & legit
- if (h && wouldAmfidLikeThis(filename)) {
- char *buf = (char *)malloc(strlen(ourContainer) + strlen("/tmp/UNESCAPER.txt") + 1);
- strcpy(buf, ourContainer);
- strcat(buf, "/tmp/UNESCAPER.txt");
- FILE *f = orig_fopen(buf, "a");
- free(buf);
- buf = NULL;
- if (!f) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. Ohi!");
- strcpy(fake_err, orig_dlerror());
- return h;
- }
- fprintf(f, "%s\n", filename);
- fclose(f);
- return h;
- }
- // not legit
- if (!shallExist(filename)) {
- // poor guy
- // he'll never know injection worked
- sprintf(fake_err, "dlopen(%s, %d): image not found", filename, flag);
- return NULL;
- }
- // legit but not loaded
- strcpy(fake_err, orig_dlerror());
- return h;
- }
- char *our_dlerror() {
- if (!strcmp(fake_err, "")) return NULL;
- char *err = strdup(fake_err);
- strcpy(fake_err, "");
- return err;
- }
- char *our_getenv(const char * name) {
- if (!strcmp(name, "DYLD_INSERT_LIBRARIES")) {
- return NULL;
- }
- return orig_getenv(name);
- }
- void *our_dlsym(void *handle, const char *name) {
- if (!strcmp(name, "fopen")) return (void*)our_fopen;
- if (!strcmp(name, "open")) return (void*)our_open;
- if (!strcmp(name, "access")) return (void*)our_access;
- //if (strcmp(name, "lstat")) return (void*)our_lstat;
- if (!strcmp(name, "stat")) return (void*)our_stat;
- if (!strcmp(name, "statfs")) return (void*)our_statfs;
- if (!strcmp(name, "readlink")) return (void*)our_readlink;
- if (!strcmp(name, "dlopen")) return (void*)our_dlopen;
- if (!strcmp(name, "dlsym")) return (void*)our_dlsym;
- if (!strcmp(name, "dlerror")) return (void*)our_dlerror;
- if (!strcmp(name, "_dyld_get_image_name")) return (void*)our_dyld_get_image_name;
- if (!strcmp(name, "getattrlist")) return (void*)our_getattrlist;
- if (!strcmp(name, "_dyld_image_count")) return (void*)our_dyld_image_count;
- return orig_dlsym(handle, name);
- }
- %hook NSFileManager
- -(BOOL)fileExistsAtPath:(NSString *)path {
- if (!path) return %orig;
- NSLog(@"FileExistsAtPath %@", path);
- if (!shallExist(strdup([path UTF8String]))) {
- return NO;
- }
- if (isOutsideSandbox(strdup([path UTF8String]))) {
- return NO;
- }
- return %orig;
- }
- -(BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory {
- if (!path) return %orig;
- NSLog(@"FileExistsAtPath:isDir %@", path);
- if (!shallExist(strdup([path UTF8String]))) {
- return NO;
- }
- if (isOutsideSandbox(strdup([path UTF8String]))) {
- return NO;
- }
- return %orig;
- }
- - (NSArray *)contentsOfDirectoryAtURL:(NSURL *)url error:(NSError **)error {
- if (strstr([[url absoluteString] UTF8String], "://")) return %orig;
- NSLog(@"contentsOfDirAtURL %@", [url absoluteString]);
- if (!shallExist(strdup([[url absoluteString] UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:[url absoluteString] forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"" forKey:@"NSUnderlyingError"];
- [cpy setObject:@[@"Folder"] forKey:@"NSUserStringVariant"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:2 userInfo:cpy];
- return nil;
- }
- if (isOutsideSandbox(strdup([[url absoluteString] UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:[url absoluteString] forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=1 \"Operation not permitted\"" forKey:@"NSUnderlyingError"];
- [cpy setObject:@[@"Folder"] forKey:@"NSUserStringVariant"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:cpy];
- return nil;
- }
- return %orig;
- }
- - (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error {
- NSLog(@"contentsOfDirAtURL %@", path);
- if (!shallExist(strdup([path UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:path forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"" forKey:@"NSUnderlyingError"];
- [cpy setObject:@[@"Folder"] forKey:@"NSUserStringVariant"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:2 userInfo:cpy];
- return nil;
- }
- if (isOutsideSandbox(strdup([path UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:path forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=1 \"Operation not permitted\"" forKey:@"NSUnderlyingError"];
- [cpy setObject:@[@"Folder"] forKey:@"NSUserStringVariant"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:cpy];
- return nil;
- }
- return %orig;
- }
- - (NSDirectoryEnumerator<NSString *> *)enumeratorAtPath:(NSString *)path {
- if (!path) return %orig;
- NSLog(@"Enumerator %@", path);
- if (!shallExist(strdup([path UTF8String]))) {
- return nil;
- }
- if (isOutsideSandbox(strdup([path UTF8String]))) {
- return nil;
- }
- return %orig;
- }
- %end
- %hook UIApplication
- -(BOOL)canOpenURL:(NSURL *)arg1 {
- NSLog(@"canOpenURL %@", [arg1 absoluteString]);
- char *url = strdup([[arg1 absoluteString] UTF8String]);
- return !(strstr(url, "cydia") || strstr(url, "filza") || strstr(url, "activator"));
- }
- - (BOOL)openURL:(NSURL *)arg1 {
- NSLog(@"openURL %@", [arg1 absoluteString]);
- char *url = strdup([[arg1 absoluteString] UTF8String]);
- return !(strstr(url, "cydia") || strstr(url, "filza") || strstr(url, "activator"));
- }
- %end
- %hook NSString
- - (NSString*)initWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error {
- NSLog(@"stringWithFile %@", path);
- if (!shallExist(strdup([path UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:path forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"" forKey:@"NSUnderlyingError"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:2 userInfo:cpy];
- return nil;
- }
- if (isOutsideSandbox(strdup([path UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:path forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=1 \"Operation not permitted\"" forKey:@"NSUnderlyingError"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:cpy];
- return nil;
- }
- return %orig;
- }
- - (NSString*)initWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error {
- if (strstr([[url absoluteString] UTF8String], "://")) return %orig;
- NSLog(@"stringWithFile %@", [url absoluteString]);
- if (!shallExist(strdup([[url absoluteString] UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:[url absoluteString] forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"" forKey:@"NSUnderlyingError"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:2 userInfo:cpy];
- return nil;
- }
- if (isOutsideSandbox(strdup([[url absoluteString] UTF8String]))) {
- NSMutableDictionary *cpy = [NSMutableDictionary dictionary];
- [cpy setObject:[url absoluteString] forKey:@"NSFilePath"];
- [cpy setObject:@"Error Domain=NSPOSIXErrorDomain Code=1 \"Operation not permitted\"" forKey:@"NSUnderlyingError"];
- *error = [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:cpy];
- return nil;
- }
- return %orig;
- }
- %end
- %hook AppsFlyerUtils
- + (id) isJailBreakon {
- return nil;
- }
- %end
- %hook ANSMetadata
- - (BOOL) computeIsJailbroken {
- return NO;
- }
- %end
- %hook QPLibraryConfiguration
- -(NSNumber *)runtimeConfigurationValueForKey:(NSString *)key {
- if ([key isEqualToString:@"REQUIRE_SECURE_DEVICE"]) return [NSNumber numberWithBool:NO];
- return %orig;
- }
- %end
- %hook USParametersProvider
- -(BOOL)isJailbroken {
- return NO;
- }
- %end
- %hook FuseSDK
- -(BOOL)isJailBroken {
- return NO;
- }
- %end
- %hook GTMSessionFetcher
- -(BOOL)appAllowsInsecureRequests {
- return YES;
- }
- %end
- %ctor {
- // setup server
- messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.jakeashacks.unescaperd"]; //setup our message center
- rocketbootstrap_distributedmessagingcenter_apply(messagingCenter); //use rocketbootstrap to get around sandbox
- if (!messagingCenter) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. HHH!");
- return;
- }
- ourBundle = strdup([[[NSBundle mainBundle] bundlePath] UTF8String]);
- ourContainer = strdup([NSHomeDirectory() UTF8String]);
- // setup a list of dylibs
- uint32_t image_index;
- uint32_t count = _dyld_image_count();
- printf("[unescaper] opening %s\n", [[@(ourContainer) stringByAppendingPathComponent:@"tmp/UNESCAPER.txt"] UTF8String]);
- FILE *f = fopen([[@(ourContainer) stringByAppendingPathComponent:@"tmp/UNESCAPER.txt"] UTF8String], "w");
- if (!f) {
- NSLog(@"[unescaper] My dear friend, something's wrong. Expect weird things. bubah!");
- return;
- }
- printf("[unescaper] adding %s on allowed dylibs\n", _dyld_get_image_name(0));
- fprintf(f, "%s\n", _dyld_get_image_name(0));
- for (image_index = 1; image_index < count; image_index ++) {
- if (wouldAmfidLikeThis(_dyld_get_image_name(image_index))) {
- printf("[unescaper] adding %s on allowed dylibs\n", _dyld_get_image_name(image_index));
- fprintf(f, "%s\n", _dyld_get_image_name(image_index));
- }
- }
- fclose(f);
- //fake_err = [NSMutableString stringWithString:@""];
- strcpy(fake_err, "");
- printf("[unescaper] hooking fopen\n");
- MSHookFunction((void *)fopen, (void *)our_fopen, (void **)&orig_fopen);
- printf("[unescaper] hooking open\n");
- MSHookFunction((void *)open, (void *)our_open, (void **)&orig_open);
- printf("[unescaper] hooking access\n");
- MSHookFunction((void *)access, (void *)our_access, (void **)&orig_access);
- printf("[unescaper] hooking stat\n");
- MSHookFunction((void *)stat, (void *)our_stat, (void **)&orig_stat);
- printf("[unescaper] hooking getattrlist\n");
- MSHookFunction((void *)getattrlist, (void *)our_getattrlist, (void **)&orig_getattrlist);
- printf("[unescaper] hooking statfs\n");
- MSHookFunction((void *)statfs, (void *)our_statfs, (void **)&orig_statfs);
- printf("[unescaper] hooking readlink\n");
- MSHookFunction((void *)readlink, (void *)our_readlink,(void **) &orig_readlink);
- printf("[unescaper] hooking getimgname\n");
- MSHookFunction((void *)_dyld_get_image_name, (void *)our_dyld_get_image_name, (void **)&orig_dyld_get_image_name);
- printf("[unescaper] hooking imgcnt\n");
- MSHookFunction((void *)_dyld_image_count, (void *)our_dyld_image_count, (void **)&orig_dyld_image_count);
- printf("[unescaper] hooking dlopen\n");
- MSHookFunction((void *)dlopen, (void *)our_dlopen, (void **)&orig_dlopen);
- printf("[unescaper] hooking dlsym\n");
- MSHookFunction((void *)dlsym, (void *)our_dlsym, (void **)&orig_dlsym);
- printf("[unescaper] hooking dlerror\n");
- MSHookFunction((void *)dlerror, (void *)our_dlerror, (void **)&orig_dlerror);
- printf("[unescaper] hooking getenv\n");
- MSHookFunction((void *)getenv, (void *)our_getenv, (void **)&orig_getenv);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement