When running readelf -S
I get:
[27] .strtab STRTAB 0000000000000000 00001630
00000000000001d7 0000000000000000 0 0 1
[28] .shstrtab STRTAB 0000000000000000 00001807
0000000000000103 0000000000000000 0 0 1
How can I get the index of .strtab
?
At first I tried to detect it using the Type
field, but that won't work as you can see (27 and 28 have same type). Plus I can't be sure that it will be the first of type STRTAB to appear.
My struct with some explanations:
/*
* Section header.
*/
typedef struct {
Elf64_Word sh_name; /* Section name (index into the
section header string table). */
Elf64_Word sh_type; /* Section type. */
Elf64_Xword sh_flags; /* Section flags. */
Elf64_Addr sh_addr; /* Address in memory image. */
Elf64_Off sh_offset; /* Offset in file. */
Elf64_Xword sh_size; /* Size in bytes. */
Elf64_Word sh_link; /* Index of a related section. */
Elf64_Word sh_info; /* Depends on section type. */
Elf64_Xword sh_addralign; /* Alignment in bytes. */
Elf64_Xword sh_entsize; /* Size of each entry in section. */
} Elf64_Shdr;