且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从C读取Linux上的ELF字符串表

更新时间:2023-11-07 10:05:04

我自己找到了答案:)。尽管花了很多时间进行编码。如果有人要将来引用它,请按以下步骤进行操作-
每个二进制文件通常包含三个字符串表-

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

在上面问题我们关心的是.shstrtab,当展开时代表-节头STRING TABle。阅读ELF标头后,我们在ELF标头中找到以下字段-e_shstrndx。这是我们可以找到.shstrtab的索引。以下公式可用于计算其完成方式-

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

每个参数的含义-

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.