Skip to content

Commit

Permalink
Undo MH_EXECUTE -> MH_DYLIB patch
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Jul 16, 2023
1 parent 584813b commit b4c9403
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions LCRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ static void patchPageZero(const char *path) {
void *map = mmap(NULL, s.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

struct mach_header_64 *header = (struct mach_header_64 *)map;
if (header->magic == MH_MAGIC_64) {
// Undo MH_EXECUTE -> MH_DYLIB patch
if (header->magic == MH_MAGIC_64 && header->filetype == MH_DYLIB) {
//assert(header->flags & MH_PIE);
header->filetype = MH_DYLIB;
header->flags &= ~MH_PIE;
header->filetype = MH_EXECUTE;
header->flags |= MH_PIE;
}

// Patch __PAGEZERO to map just a single zero page, fixing "out of address space"
Expand Down Expand Up @@ -125,6 +126,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
if (!info[@"LCDataUUID"]) {
info[@"LCDataUUID"] = NSUUID.UUID.UUIDString;
[info writeToFile:infoPath atomically:YES];
}
if ([info[@"LCPatchRevision"] intValue] < 1) {
info[@"LCPatchRevision"] = @(1);
[info writeToFile:infoPath atomically:YES];
NSString *execPath = [NSString stringWithFormat:@"%@/%@", appPath, info[@"CFBundleExecutable"]];
patchPageZero(execPath.UTF8String);
}
Expand Down

0 comments on commit b4c9403

Please sign in to comment.