I am trying to print the symbol table from an elf file. I got the offsets of sections .symtab and .strtab ( I crosschecked with readelf). but the program is giving segmentation fault. Here is the code in question:
printf("\n\nSymbol table:");
for(i=0;i<symtab.sh_size/symtab.sh_entsize ;i++)
{
fseek(ElfFile,symtab.sh_offset+i*symtab.sh_entsize,SEEK_SET);
fread(&elfSym,1,sizeof elfSym,ElfFile);
printf("\nSymbol:%s,size:%u",elfSym.st_name+strtab.sh_offset,elfSym.st_size);
}