Is there a way to detect if the code being compiled is in a Framework, a Bundle, or a Dynamic Library?
The reason is because of a crash reporter library that needs to know if a struct variable exists before taking the address of it..
IE:
#ifdef MH_EXECUTE_SYM
return (uint8_t*)&_mh_execute_header;
#else
return (uint8_t*)&_mh_dylib_header;
#endif
The problem is that MH_EXECUTE_SYM
, MH_BUNDLE_SYM
, MH_DYLIB_SYM
is always defined for every kind of executable, bundle, framework..
So I need a way of determining which struct variable to take the address of.. Any ideas?
It looks like you really just want to get a pointer to the appropriate
mach_header_64
(ormach_header
on 32-bit systems).If you have a pointer, you can use the
dladdr
function to find out which (if any) mach-o it was loaded from. That function fills in aDl_info
structure which includes, amongst other things, a pointer to themach_header_64
for the mach-o.