【问题标题】:Access ELF string table section header访问 ELF 字符串表节标题
【发布时间】:2010-05-28 02:30:09
【问题描述】:

假设如下:

Elf_Section_Header *sectionHeaderTable //points to the start of a ELF section header table
Elf_Section_Header *symtabHeader  //points to the start of the symtab section header

为什么以下内容没有指向关联的字符串表部分标题?

Elf_Section_Header *strTabSectionHeader = (Elf_Section_Header *)((char *)sectionHeaderTable + (symtabHeader->strtab_index));

strTabSectionHeader->type == SHT_STRTAB 等于假

我应该如何指向关联的字符串表节标题?

【问题讨论】:

    标签: c elf


    【解决方案1】:

    大概->strtab_index 结构成员是指符号表头的sh_name 成员(如ELF 规范中所命名)。

    这实际上是节头字符串表节的索引,而不是字符串表的位置。

    字符串表存储在它们自己的部分中。特别是节头字符串表由 ELF 头的 e_shstrndx 成员定位。这是节头表的索引 - 因此sectionHeaderTable[elf_header->e_shstrndx] 可能是您想要的(节头字符串表的节头)。

    【讨论】:

      【解决方案2】:

      每个Binary一般包含三个String表——

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

      在上面的问题中,我们关心的是 .shstrtab,它在扩展时代表 - Section Header STRing TABle。在读取 ELF 标头后,我们在 ELF 标头中找到以下字段 - e_shstrndx。这是我们可以找到 .shstrtab 的索引。以下公式可用于计算如何完成 -

      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.
      

      如果您需要更多详细信息,请发表评论

      【讨论】:

        【解决方案3】:

        节头的 sh_name 成员保存到节头字符串表节的索引,由 ELF 头的 e_shstrndx 成员指定。 ELF Specification

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-08-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-09-27
          • 1970-01-01
          相关资源
          最近更新 更多