我正在尝试重新编码nm,并且正在努力解析胖头。似乎胖结构的偏移有一些问题。我可能无法很好地进入内存,但无法弄清楚。我想知道我是如何使用指针的,还是我不太了解胖头的工作原理。 当我尝试使用胖文件执行程序时,我获得了ppc架构的良好输出,但是如果i386架构失败,我的函数将检查在特定偏移量处是否存在有效的mach_header。 这是一些代码。 谢谢您的帮助。
void process_fat_header_32(t_map *file,
t_arch *arch, t_header *header)
{
struct fat_arch *fat_arch;
struct fat_header *fat_header;
uint32_t val;
uint32_t i;
const char *cpu;
char *tmp;
i = 0;
fat_header = header->fat_header;
val = should_swap_32(arch, fat_header->nfat_arch);
fat_arch = (struct fat_arch *)(fat_header + 1);
while (i < val)
{
fat_arch = (void *)file->ptr + sizeof(struct fat_header) +
(i * sizeof(struct fat_arch));
cpu = cpu_type_name(should_swap_32(arch, fat_arch->cputype));
if (!ft_strcmp(cpu, "unknown"))
return ;
print_architecture(cpu, file->file[g_idx]);
printf("offset = %d\n", should_swap_32(arch, fat_arch->offset));
tmp = file->ptr;
file->ptr = file->ptr + should_swap_32(arch, fat_arch->offset);
launch_process(file, arch, header);
file->ptr = tmp;
i++;
}
}