范例:区分32位、64位 结构:
// 32位struct mach_header { uint32_t magic; /* mach magic number identifier */ cpu_type_t cputype; /* cpu specifier */ cpu_subtype_t cpusubtype; /* machine specifier */ uint32_t filetype; /* type of file */ uint32_t ncmds; /* number of load commands */ uint32_t sizeofcmds; /* the size of all the load commands */ uint32_t flags; /* flags */};// 64位 struct mach_header_64 { uint32_t magic; /* mach magic number identifier */ cpu_type_t cputype; /* cpu specifier */ cpu_subtype_t cpusubtype; /* machine specifier */ uint32_t filetype; /* type of file */ uint32_t ncmds; /* number of load commands */ uint32_t sizeofcmds; /* the size of all the load commands */ uint32_t flags; /* flags */ uint32_t reserved; /* reserved */};解释:
magic:确定Mach-O文件运行框架,如64位/32位
cputype:CPU范例,如arm
cpusubtype:对应CPU范例的具体型号
filetype:文件范例
ncmds:加载下令条数
sizeofcmds:全部加载下令的巨细
flags:保存字段
reserved:标志位
LoadCommand
cmd:指令范例
cmdsize: 指令长度
以下是load_command的结构:
struct load_command { uint32_t cmd; /* type of load command */ uint32_t cmdsize; /* total size of command in bytes */};command 指令范例阐明