Skip to content

Commit

Permalink
Fix Mach-O address translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Siguza committed Feb 4, 2023
1 parent fd24216 commit aa34c28
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/macho.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void* addr2ptr(void *macho, kptr_t addr)
if(cmd->cmd == MACH_SEGMENT)
{
mach_seg_t *seg = (mach_seg_t*)cmd;
if(addr >= seg->vmaddr && addr < seg->vmaddr + seg->vmsize)
if(addr >= seg->vmaddr && addr < seg->vmaddr + seg->filesize)
{
return (void*)((uintptr_t)macho + seg->fileoff + (addr - seg->vmaddr));
}
Expand All @@ -88,7 +88,7 @@ mach_seg_t* seg4ptr(void *macho, void *ptr)
if(cmd->cmd == MACH_SEGMENT)
{
mach_seg_t *seg = (mach_seg_t*)cmd;
if(p >= (char*)((uintptr_t)macho + seg->fileoff) && p < (char*)((uintptr_t)macho + seg->fileoff + seg->vmsize))
if(p >= (char*)((uintptr_t)macho + seg->fileoff) && p < (char*)((uintptr_t)macho + seg->fileoff + seg->filesize))
{
return seg;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ kptr_t kuntag(kptr_t base, fixup_kind_t fixupKind, kptr_t ptr, bool *bind, bool
}
if(pp.pac.bind) return pp.pac.off & 0xffff;
if(pp.pac.auth) return base + pp.pac.off;
return (kptr_t)pp.raw.lo;
return (kptr_t)pp.raw.lo + (fixupKind == DYLD_CHAINED_PTR_ARM64E ? 0 : base);
}
if(bind) *bind = false;
if(auth) *auth = false;
Expand Down

0 comments on commit aa34c28

Please sign in to comment.