Reading ELF String Table on Linux from C

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:37:50

I was able to find out the answer myself :). Although it took a lot of time to code. Here is how it is done if someone wants to refer it for future - Each Binary generally contains three String tables -

1. .dynstr
2. .shstrtab
3. .strtab

IN the above question we are concerned with .shstrtab which when expanded stands for - Section Header STRing TABle. Upon reading the ELF header we find the following field in ELF header - e_shstrndx. This is the index where we can find .shstrtab. Following formula can be used to calculate how it will be done -

offset = ((elfHdr.e_shstrndx)*elfHdr.e_shentsize)+elfHdr.e_shoff

Meaning of each parameter -

elfHdr.e_shstrndx = index where we can find .shstrtab
elfHdr.e_shentsize = Size of each Section Header
elfHdr.e_shoff = Offset at which section header starts.

In brief, the e_shstrndx field of ELF Executable Header contains the index of the ELF string table holding section names.

The "libelf by Example" tutorial has a lengthier explanation, along with example code showing how to retrieve section names using the functions in the ELF(3) API.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!