header 列表指向哪个字符串 table?
Which string table does the section header list point to?
一个 Elf 文件可以有多个字符串表,但是 Headers sh_name 字段的列表是此 table 的索引。文件如何知道要引用哪个字符串 table?
一个ELF文件中有两个字符串table:
.strtab
,其中包含符号的名称。
.shstrtab
(S节 H标题 String Table),其中包含部分的名称。
如果您想使用 sectionHeader.sh_name
,那么您可能正在 .shstrtab
table 中查找该部分的名称。可以使用以下代码获得(显然是针对 64 位的):
Elf64_Ehdr* header = (Elf64_Ehdr*) map;
Elf64_Shdr* stringTable = (Elf64_Shdr*) (map + header->e_shoff +
header->e_shstrndx * header->e_shentsize);
char* sectionName = map + stringTable->sh_offset + sectionHeader->sh_name;
// 'map' is a pointer to the beginning of your mapped ELF file
感谢 @Employed Russian 指出检索 header 尺寸的更好方法。
一个 Elf 文件可以有多个字符串表,但是 Headers sh_name 字段的列表是此 table 的索引。文件如何知道要引用哪个字符串 table?
一个ELF文件中有两个字符串table:
.strtab
,其中包含符号的名称。.shstrtab
(S节 H标题 String Table),其中包含部分的名称。
如果您想使用 sectionHeader.sh_name
,那么您可能正在 .shstrtab
table 中查找该部分的名称。可以使用以下代码获得(显然是针对 64 位的):
Elf64_Ehdr* header = (Elf64_Ehdr*) map;
Elf64_Shdr* stringTable = (Elf64_Shdr*) (map + header->e_shoff +
header->e_shstrndx * header->e_shentsize);
char* sectionName = map + stringTable->sh_offset + sectionHeader->sh_name;
// 'map' is a pointer to the beginning of your mapped ELF file
感谢 @Employed Russian 指出检索 header 尺寸的更好方法。