segmentation fault - Printing the symbol table from elf file -
i trying print symbol table elf file. got offsets of sections .symtab , .strtab ( crosschecked readelf). program giving segmentation fault. here 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); }
this bug:
printf("\nsymbol:%s,size:%u",elfsym.st_name+strtab.sh_offset,elfsym.st_size); the sym.st_name gives offset .strtab section symbol name begins, , strtab.sh_offset gives offset into file section begins.
but adding 2 offsets not give memory location can print %s, gives offset file string is. still need read file @ offset memory, , then able print it.
Comments
Post a Comment