How to find the offset of the section header string table of an elf file?

前端 未结 4 1570
醉酒成梦
醉酒成梦 2020-12-08 17:48

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

4条回答
  •  一整个雨季
    2020-12-08 18:19

    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.

提交回复
热议问题