//获取macho链接库(这里获取的库文件列表仅限在macho看到的,并不全面)
typedef unsigned long zaddr;
typedef unsigned long zsize;
void macho_get_load_cmd_name(const struct mach_header_64 *header)
{
struct load_command *load_cmd;
load_cmd = (struct load_command *)((zaddr)header + sizeof(struct mach_header_64));
for (zsize i = 0; i < header->ncmds;i++, load_cmd = (struct load_command *)((zaddr)load_cmd + load_cmd->cmdsize))
{
if (load_cmd->cmd == LC_LOAD_DYLIB||load_cmd->cmd == LC_LOAD_WEAK_DYLIB)
{
struct dylib_command * dy_cmd =(struct dylib_command *)load_cmd;
struct dylib * lib = &dy_cmd->dylib;
union lc_str * lc_name = &lib->name;
uint32_t name = lc_name->offset;
char * s = (char *)((zaddr)dy_cmd + name);
NSLog(@"--%s-",s);
}
}
}