Skip to content

Commit

Permalink
Fix mmap incorrectly setting prot
Browse files Browse the repository at this point in the history
Sadly this fixes only PojavLauncher fishhook page permission, many apps are still broken
  • Loading branch information
khanhduytran0 committed Oct 29, 2023
1 parent e3b25bb commit f2a3c18
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions dyld_bypass_validation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f2a3c18

Please sign in to comment.