Reputation:
An Elf file can have multiple String Tables however the list of Section Headers sh_name field is an index into this table. How does the file know which string table to refer to?
Upvotes: 0
Views: 397
Reputation: 5148
There are two string tables in an ELF file:
.strtab
, which contains the symbols' names..shstrtab
(Section Header String Table), which contains the sections' names.If you want to use sectionHeader.sh_name
, then you're probably looking for the section's name in the .shstrtab
table. It can be obtained using the following code (obviously for 64 bit):
Elf64_Ehdr* header = (Elf64_Ehdr*) map;
Elf64_Shdr* stringTable = (Elf64_Shdr*) (map + header->e_shoff +
header->e_shstrndx * header->e_shentsize);
char* sectionName = map + stringTable->sh_offset + sectionHeader->sh_name;
// 'map' is a pointer to the beginning of your mapped ELF file
Thank you @Employed Russian for pointing a better way to retrieve the header's size.
Upvotes: 1