diff --git a/dyld_bypass_validation.m b/dyld_bypass_validation.m index 90cf165..5ce0b26 100644 --- a/dyld_bypass_validation.m +++ b/dyld_bypass_validation.m @@ -86,29 +86,15 @@ static bool searchAndPatch(char *name, char *base, char *signature, int length, } static void* hooked_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { - char filePath[PATH_MAX]; - bzero(filePath, PATH_MAX); - - // Check if the file is our "in-memory" file - if (fd && __fcntl(fd, F_GETPATH, filePath) != -1) { - const char *homeDir = LCHomePath(); - if (!strncmp(filePath, homeDir, strlen(homeDir))) { - int newFlags = MAP_PRIVATE | MAP_ANONYMOUS; - if (addr != 0) { - newFlags |= MAP_FIXED; - } - void *alloc = __mmap(addr, len, PROT_READ | PROT_WRITE, newFlags, 0, 0); - - void *memoryLoadedFile = __mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, offset); - memcpy(alloc, memoryLoadedFile, len); - munmap(memoryLoadedFile, len); - mprotect(alloc, len, prot); - return alloc; - } + void *map = __mmap(addr, len, prot, flags, fd, offset); + if (map == MAP_FAILED && (prot & PROT_EXEC)) { + map = __mmap(addr, len, PROT_READ | PROT_WRITE, flags | MAP_PRIVATE | MAP_ANON, 0, 0); + void *memoryLoadedFile = __mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, offset); + memcpy(map, memoryLoadedFile, len); + munmap(memoryLoadedFile, len); + mprotect(map, len, prot); } - - // If for another file, we pass through - return __mmap(addr, len, prot, flags, fd, offset); + return map; } static int hooked___fcntl(int fildes, int cmd, void *param) {