2010-05-28 35 views
2

假設如下:訪問ELF字符串表節頭

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等於假

我應該如何指向關聯的字符串表節頭?

回答

2

推測->strtab_index結構成員指的是符號表頭中的成員(如ELF規範中的名稱)。

這實際上是一個索引,在的段標題字符串表部分,而不是字符串表的位置。

字符串表存儲在他們自己的部分。部分標題字符串表格特別位於ELF標題的e_shstrndx成員之中。這是段頭表的索引 - 因此sectionHeaderTable[elf_header->e_shstrndx]可能就是你想要的(段頭字符串表的段頭)。

0

每個二進制通常包含三個字符串表 -

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

在上面的問題,我們關心的是.shstrtab其當擴大看臺 - 節頭字符串表。在閱讀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. 

請評論,如果u需要更多的細節

0

節頭的sh_name成員持有索引到節標題字符串表部分,由ELF標題的e_shstrndx成員指定。 ELF Specification