void handle_fat(char *ptr, char *file, int from, t_opt opt) { struct fat_header *header; struct fat_arch *arch; int size; uint32_t offset; int find; header = (struct fat_header*)ptr; size = swap_uint32(header->nfat_arch); arch = (void*)ptr + sizeof(header); find = find_x86_64(size, arch); offset = 0; if (find != 0) { while (size != find) { arch += sizeof(arch) / sizeof(void*); size--; } if (swap_uint32(arch->cputype) == CPU_TYPE_X86_64) offset = arch->offset; ft_otool(ptr + swap_uint32(offset), file, from, opt); } else other_arch(arch, ptr, file, opt); }
void print_art(uint32_t off, char *ptr, char *file) { int size_fuck; struct ar_hdr *arch; char *name; arch = (void*)ptr + off; name = catch_name(arch->ar_name); size_fuck = catch_size(arch->ar_name); ft_printf("\n%s(%s):\n", file, name); ft_otool((void*)arch + sizeof(*arch) + size_fuck, file); }
static void other_arch(struct fat_arch *arch, char *ptr, char *file, t_opt opt) { int size; size = swap_uint32(((struct fat_header*)ptr)->nfat_arch); while (size) { ft_putstr(file); if (swap_uint32(arch->cputype) == CPU_TYPE_POWERPC) ft_putendl(" (architecture ppc):"); else if (swap_uint32(arch->cputype) == CPU_TYPE_I386) ft_putendl(" (architecture i386):"); ft_otool(ptr + swap_uint32(arch->offset), file, FROM_AR, opt); arch += sizeof(arch) / sizeof(void*); size--; } }
int prepare_file(char *ofile) { int fd; int ret; struct stat stt; char *ptr; if ((fd = open(ofile, O_RDONLY, O_SYMLINK)) < 0) return (ft_exit(ofile, ": can't open file")); if ((ret = fstat(fd, &stt)) < 0) return (ft_exit(ofile, ": can't fstat file")); if ((ptr = mmap(0, stt.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) return (ft_exit(ofile, ": can't mmap file")); ft_otool(ofile, ptr); ft_putstr("\n"); if (munmap(ptr, stt.st_size) < 0) return (ft_exit(ofile, ": can't munmap file")); if (close(fd) < 0) return (ft_exit(ofile, ": can't close file")); return (EXIT_SUCCESS); }