I'm actually recoding the nm and objdump program. I've already finished objdump and it works well, so i'm working on nm now. I'm trying to find the Symbol table, in order to do that i run through the Section header table like this :
while (i < elf->e_shnum)
{
if (shdr[i].sh_type == SHT_SYMTAB)
printf("Symbol table found\n");
i++;
}
I never run through this condition, already tried in my objdump program and same problem, can't find SHT_SYMTAB.
This is how i'm getting the Section header table :
Elf64_Shdr *shdr;
unsigned char *shstrtab;
void *data;
Elf64_Ehdr *elf;
//I reduced the code to make it more readable
data = mmap(NULL, filesize(fd), PROT_READ, MAP_SHARED, fd, 0);
elf = ((Elf64_Ehdr *)data);
shdr = ((Elf64_Shdr *)(data + elf->e_shoff));
shstrtab = ((unsigned char *)(data + shdr[elf->e_shstrndx].sh_offset));
I don't know if i'm doing it right (even if my objdump is working perfectly), or if i didn't understand how nm works
Thanks for help :)