I have to write a C program that prints an ELF file. I\'m having trouble figuring out where the section header string table is.
Let\'s say I have a file that gave me
The section header table starts at starting point of your file
+ e_shoff
. The elf.h
file already has Elfxx_Shdr
struct and a Elfxx_Ehdr
struct, where xx above is either 32
or 64
for 32 bit or 64 bit respectively.
You can use e_shentsize
from the Elfxx_Ehdr
to get the section header string table index and then use sh_name
and sh_offset
from the Elfxx_Shdr
. sh_name
will give you an index of strtab
in which if you add the sh_offset
. That will give you the full name of the section. Same for the type, flag and others by using sh_type
, sh_flag
etc.
I would suggest you to go over executable and linkable format wikipedia article and the efl.h file man page.