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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -