#include "ft_nm.h" int nm32(t_mapped_file mapped_file) { (void)mapped_file; return FT_NM_SUCCESS; } char *get_sym_char(Elf64_Sym sym) { if (sym.st_shndx == SHN_ABS) { if (ELF64_ST_BIND(sym.st_info) == STB_LOCAL) { return ("a"); } else if (ELF64_ST_BIND(sym.st_info) == STB_GLOBAL) { return ("A"); } } return ("T"); } int nm64(t_mapped_file mapped_file) { Elf64_Ehdr header; if (get_header64(mapped_file, &header) == FT_NM_FAILURE) { return FT_NM_FAILURE; } printf("Header:\n"); printf("Version: %d\n", header.e_version); printf("Entry point: %ld\n", header.e_entry); printf("Program header offset: "); fflush(stdout); ft_printf("X", header.e_phoff); ft_putchar('\n'); printf("Section header offset: "); fflush(stdout); ft_printf("X", header.e_shoff); ft_putchar('\n'); printf("Header size: %d\n", header.e_ehsize); printf("Program header entry size: %d\n", header.e_phentsize); printf("Program header num: %d\n", header.e_phnum); printf("Section header entry size: %d\n", header.e_shentsize); printf("Section header num: %d\n", header.e_shnum); printf("Section header string table index: %d\n", header.e_shstrndx); /* for (int i = 0; i < header.e_phnum; i++) { uint64_t addr = header.e_phoff + header.e_phentsize * i; Elf64_Phdr phstr; ft_memcpy(&phstr, mapped_file.ptr + addr, header.e_phentsize); ft_printf("X", phstr.p_offset); ft_putchar('\n'); char *str = ft_strdup(mapped_file.ptr + phstr.p_offset + 1); ft_putstr(str); ft_putchar('\n'); } */ uint64_t addr = header.e_shoff + header.e_shentsize * header.e_shstrndx; //ft_printf("sX", "addr: ", addr); Elf64_Shdr shstrtb; ft_memcpy(&shstrtb, mapped_file.ptr + addr, header.e_shentsize); //ft_printf("sX", "offset: ", shstrtb.sh_offset); for (int i = 0; i < header.e_shnum; i++) { uint64_t addr = header.e_shoff + header.e_shentsize * i; Elf64_Shdr sh; ft_memcpy(&sh, mapped_file.ptr + addr, header.e_shentsize); if (sh.sh_type == SHT_SYMTAB) { uint64_t addr2 = header.e_shoff + header.e_shentsize * sh.sh_link; Elf64_Shdr strtab; ft_memcpy(&strtab, mapped_file.ptr + addr2, header.e_shentsize); ft_printf("sdsds", "SYMTAB Size: ", sh.sh_size, " Entity size: ", sh.sh_entsize, "\n"); for (uint64_t j = 0; j < sh.sh_size; j += sh.sh_entsize) { Elf64_Sym sym; ft_memcpy(&sym, mapped_file.ptr + sh.sh_offset + j, sh.sh_entsize); char *str = ft_strdup(mapped_file.ptr + strtab.sh_offset + sym.st_name); //if (str[ft_strlen(str) - 1] == 'c') { printf("st_name: %d\n", sym.st_name); printf("st_info: %d\n", sym.st_info); printf("st_other: %d\n", sym.st_other); printf("st_shndx: %d\n", sym.st_shndx); printf("st_value: %ld\n", sym.st_value); printf("st_size: %ld\n", sym.st_size); //} if (sym.st_value) { ft_printf("X s ss", sym.st_value, get_sym_char(sym), str, "\n"); } else { ft_printf("P s ss", get_sym_char(sym), mapped_file.ptr + strtab.sh_offset + sym.st_name, "\n"); } } } /*ft_printf("X", sh.sh_offset); ft_putchar('\n'); ft_printf("X", sh.sh_name); ft_putchar('\n');*/ char *str = ft_strdup(mapped_file.ptr + shstrtb.sh_offset + sh.sh_name); //ft_putstr(str); ft_printf("x x x ss", sh.sh_name, sh.sh_offset, addr, str, "\n"); free(str); //ft_putchar('\n'); } return FT_NM_SUCCESS; }