【发布时间】:2017-10-27 00:19:17
【问题描述】:
我正在开发一个使用内存映射mmap 实现基本nm 的项目。我已经能够使用代码解析 64 位二进制文件:
void handle_64(char *ptr)
{
int ncmds;
struct mach_header_64 *header;
struct load_command *lc;
struct symtab_command *sym;
int i;
i = 0;
header = (struct mach_header_64 *)ptr;
ncmds = header->ncmds;
lc = (void *)ptr + sizeof(*header);
while (i < ncmds)
{
if (lc->cmd == LC_SYMTAB)
{
sym = (struct symtab_command *)lc;
build_list (sym->nsyms, sym->symoff, sym->stroff, ptr);
break;
}
lc = (void *) lc + lc->cmdsize;
i++;
}
}
根据这个link,mach-o 和胖二进制文件之间的唯一区别是它上面的fat_header 结构,但只是跳过了
lc = (void *)ptr + sizeof(struct fat_header) + sizeof(struct mach_header_64);
没有让我进入 load_command 区域(段错误)。如何访问胖/通用二进制文件的加载命令。
我正在开发运行 macOS High Sierra 的 64 位 Mac。谢谢。
【问题讨论】:
标签: c mach-o fat universal-binary fat-binaries