From 3ee3777174b26c77a41fb3b6912fa00ccc2bc7d6 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Thu, 4 Apr 2024 13:30:59 +0200 Subject: [PATCH] feat(nm): 64 bits passes /usr/lib/ --- src/nm.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/nm.c b/src/nm.c index f6f92b1..4a67513 100644 --- a/src/nm.c +++ b/src/nm.c @@ -5,10 +5,10 @@ void print_section(Elf64_Shdr sec); void print_symbol(Elf64_Sym sym); char *get_sym_char(Elf64_Sym sym, Elf64_Shdr sec) { -// ppp(sym, sec); - if ((sec.sh_flags & SHF_COMPRESSED) == SHF_COMPRESSED) { - return ("N"); - } + // ppp(sym, sec); + // if ((sec.sh_flags & SHF_COMPRESSED) == SHF_COMPRESSED) { + // return ("N"); + // } if (sym.st_shndx == SHN_ABS) { if (ELF64_ST_BIND(sym.st_info) == STB_LOCAL) { return ("a"); @@ -17,6 +17,9 @@ char *get_sym_char(Elf64_Sym sym, Elf64_Shdr sec) { return ("A"); } } + if (ELF64_ST_BIND(sym.st_info) == STB_GNU_UNIQUE) { + return ("u"); + } if (ELF64_ST_TYPE(sym.st_info) == STT_GNU_IFUNC) { return ("i"); } @@ -101,6 +104,7 @@ char *get_sym_char(Elf64_Sym sym, Elf64_Shdr sec) { } } if (sym.st_shndx == SHN_UNDEF) { +//return ("U"); if (ELF64_ST_BIND(sym.st_info) == STB_LOCAL) { return ("u"); } @@ -130,8 +134,6 @@ char *get_sym_char(Elf64_Sym sym, Elf64_Shdr sec) { return ("w"); } else { - print_symbol(sym); - print_section(sec); return ("W"); } } @@ -198,29 +200,29 @@ int nm64(t_mapped_file mapped_file) { ft_memcpy(&sec, mapped_file.ptr + header.e_shoff + header.e_shentsize * sym.st_shndx, header.e_shentsize); } char *str; + char *sec_str; + Elf64_Shdr shdr; + if (sym.st_shndx != SHN_ABS) { + ft_memcpy(&shdr, mapped_file.ptr + header.e_shoff + header.e_shentsize * sym.st_shndx, header.e_shentsize); + sec_str = ft_strdup(mapped_file.ptr + shstrtb.sh_offset + shdr.sh_name); + } else { + sec_str = ft_strdup(""); + } if (sym.st_name) { str = ft_strdup(mapped_file.ptr + strtab.sh_offset + sym.st_name); } else { - //printf("good\n"); - Elf64_Shdr shdr; - //print_symbol(sym); - if (sym.st_shndx != SHN_ABS) { - ft_memcpy(&shdr, mapped_file.ptr + header.e_shoff + header.e_shentsize * sym.st_shndx, header.e_shentsize); - //print_section(shdr); - //ft_printf("sxs", "sh string table ", shstrtb.sh_offset, "\n"); - str = ft_strdup(mapped_file.ptr + shstrtb.sh_offset + shdr.sh_name); - //str = ft_strdup("TOTOTOTOTO"); - //str = ft_strdup(mapped_file.ptr + shdr.sh_offset + sec.sh_name); - } else { - str = ft_strdup(""); - } + str = sec_str; } //if (str[ft_strlen(str) - 1] == 'c') { /* */ //} char *sym_char = ft_strdup(get_sym_char(sym, sec)); + if (ft_strnstr(sec_str, ".debug", 6) && ft_strequ(sym_char, "n")) { + free(sym_char); + sym_char = ft_strdup("N"); + } if (sym.st_value) { ft_printf("X s ss", sym.st_value, sym_char, str, "\n"); } else {