From 38d29c235bc34b90aedce75af731925323956f30 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 14 Nov 2020 12:16:51 +0200 Subject: [PATCH] - fixed incorrect autosegs section addresses on macOS It appeared that getsectbyname() returns address stored in executable header as is, i.e. without adjusting it for ASLR --- src/common/objects/autosegs.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/objects/autosegs.cpp b/src/common/objects/autosegs.cpp index 4840d1319..4d5bdba74 100644 --- a/src/common/objects/autosegs.cpp +++ b/src/common/objects/autosegs.cpp @@ -49,6 +49,7 @@ #include #elif defined __MACH__ #include +#include #endif @@ -101,10 +102,12 @@ void FAutoSeg::Initialize() #elif defined __MACH__ - if (const struct section_64 *const section = getsectbyname(AUTOSEG_MACH_SEGMENT, name)) + unsigned long size; + + if (uint8_t *const section = getsectiondata(&_mh_execute_header, AUTOSEG_MACH_SEGMENT, name, &size)) { - begin = reinterpret_cast(section->addr); - end = reinterpret_cast(section->addr + section->size); + begin = reinterpret_cast(section); + end = reinterpret_cast(section + size); } #else // Linux and others with ELF executables