#include <mach-o/dyld.h> extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile( const char *pathName, NSObjectFileImage *objectFileImage); extern NSObjectFileImageReturnCode NSCreateCoreFileImageFromFile( const char *pathName, NSObjectFileImage *objectFileImage); extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory( void *address, unsigned long size, NSObjectFileImage *objectFileImage); extern enum DYLD_BOOL NSDestroyObjectFileImage( NSObjectFileImage objectFileImage); extern unsigned long NSSymbolDefinitionCountInObjectFileImage( NSObjectFileImage objectFileImage); extern const char * NSSymbolDefinitionNameInObjectFileImage( NSObjectFileImage objectFileImage, unsigned long ordinal); extern unsigned long NSSymbolReferenceCountInObjectFileImage( NSObjectFileImage objectFileImage); extern const char * NSSymbolReferenceNameInObjectFileImage( NSObjectFileImage objectFileImage, unsigned long ordinal, enum DYLD_BOOL *tentative_definition); /* can be NULL */ extern enum DYLD_BOOL NSIsSymbolDefinedInObjectFileImage( NSObjectFileImage objectFileImage, const char *symbolName); extern void * NSGetSectionDataInObjectFileImage( NSObjectFileImage objectFileImage, const char *segmentName, const char *sectionName);
These routines are the programmatic interface for working with Mach-O files. They bring the Mach-O file into memory and the API allows the file to be inspected or loaded into the program. On creation of an object file image it is checked to insure it is a valid format and it is compatible with the host machine's cpu architecture.
NSCreateObjectFileImageFromFile takes the parameter pathName as the path name to the file name in the file system and creates and returns an NSObjectFileImage. Currently only MH_BUNDLE files can be used with NSCreateObjectFileImageFromFile which can then be loaded into the program using NSLinkModule(3). If the file is valid an NSObjectFileImage is returned and the return code is NSObjectFileImageSuccess.
NSCreateCoreFileImageFromFile takes the parameter pathName as the path name to a core file in the file system and creates and returns an NSObjectFileImage. This NSObjectFileImage can then can be loaded into a task with _dyld_debug_task_from_core(3) to determine what libraries were loaded and which modules were linked.