Search code examples
c++macosdyldmach-o

Get __TEXT and __DATA Dyld address mapping from within an executable


To find the dyld address mapping of __TEXT and __DATA for my mach-o executable I set the environment variable DYLD_PRINT_SEGMENTS=1. This logs on the console where in memory the executable is mapped.

However, I need to find the address mapping of __TEXT and __DATA internally from within my executable. Is there some API for elegantly obtaining this information?


Solution

  • You can obtain this information with the getsectbyname() function from the <mach-o/getsect.h> header.