0

So I was able to get the sh_name using the Elf tutorial here: http://wiki.osdev.org/ELF_Tutorial and this question: getting the sh_name member in a section header elf file, but when using the same method to get the rest of the fields in the section header, I don't get the same output as I do when I call readelf -S on the object file I'm analyzing. I'm printing out a casted string of the following:

sh_strtab_p + shdr[i].sh_offset

and I'm getting nothing when I do. Is it an issue of casting? Am I supposed to be casting it as an int instead or something similar? I thought it was going to be a string format since I assumed sh_strtab was the associated string table to the section header.

Community
  • 1
  • 1
srujzs
  • 340
  • 3
  • 14

1 Answers1

1

So, it turns out I'm being silly, and the answer is just to convert the Elf_Shdr.sh_offset (which is a uint32_t) to hex, and you'll get the same value as when you use readelf. There is no need to use a string index for anything besides name. All the other fields can be processed the same way, and if you want the string representation of the flags and type, there's a table here mapping the value to the name of the flag/type: https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-94076/index.html.

srujzs
  • 340
  • 3
  • 14