ELF Header 大小大于 52 字节
ELF Header Size Greater than 52 bytes
根据给定的Elf32_Ehdr结构(page9),在linkelf-formatelfheader中大小应该是52字节并且是固定的。但是还有字段e_ehsize,可以大于52字节。在第一节 header 开始之前定义那些额外字节的位置?
如其所说,也在第 9 页:
Some object file control structures can grow, because the ELF header contains their actual sizes. If the object file format changes, a program may encounter control structures that are larger or smaller than expected. Programs might therefore ignore ‘‘extra’’ information. The treatment of ‘‘missing’’ information depends on context and will be specified when and if extensions are defined.
(强调)。目前没有定义任何额外字节的语义;他们将包括一个扩展。此外,文本暗示如果您发现 Elf32_Ehdr
部分的文件长度超过 52 字节,您可以安全地忽略多余的字节。
请注意,ELF Header 在 32 位机器上通常为 52 字节,在 64 位机器上为 64 字节。
旧规范 [1] 的描述中不包含 64 位 header。这可能是您一直在使用的规范。
[1] http://www.skyfree.org/linux/references/ELF_Format.pdf
您可以检查访问文档 [2] 的 64 位 ELF headers。
[2] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf
32位和64位ELF的区别header在前:
typedef struct{
........ // struct Elf32_Ehdr
Elf64_Addr e_entry; //[8 bytes] Elf32_Addr [4 bytes]
Elf64_Off e_phoff; //[8 bytes] Elf32_Off [4 bytes]
Elf64_Off e_shoff; //[8 bytes] Elf32_Off [4 bytes]
.......
} Elf64_Ehdr;
因此,从 32 位到 64 位 ELF,大小差异为 (4*3)=12 个字节 header。另请注意,header 可能会按照规范的指示在末尾包含额外的位。
解析 ELF 二进制文件时,请确保先读取前 16 个字节,以确定文件是 32 位还是 64 位 elf。
根据给定的Elf32_Ehdr结构(page9),在linkelf-formatelfheader中大小应该是52字节并且是固定的。但是还有字段e_ehsize,可以大于52字节。在第一节 header 开始之前定义那些额外字节的位置?
如其所说,也在第 9 页:
Some object file control structures can grow, because the ELF header contains their actual sizes. If the object file format changes, a program may encounter control structures that are larger or smaller than expected. Programs might therefore ignore ‘‘extra’’ information. The treatment of ‘‘missing’’ information depends on context and will be specified when and if extensions are defined.
(强调)。目前没有定义任何额外字节的语义;他们将包括一个扩展。此外,文本暗示如果您发现 Elf32_Ehdr
部分的文件长度超过 52 字节,您可以安全地忽略多余的字节。
请注意,ELF Header 在 32 位机器上通常为 52 字节,在 64 位机器上为 64 字节。 旧规范 [1] 的描述中不包含 64 位 header。这可能是您一直在使用的规范。 [1] http://www.skyfree.org/linux/references/ELF_Format.pdf
您可以检查访问文档 [2] 的 64 位 ELF headers。 [2] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf
32位和64位ELF的区别header在前:
typedef struct{
........ // struct Elf32_Ehdr
Elf64_Addr e_entry; //[8 bytes] Elf32_Addr [4 bytes]
Elf64_Off e_phoff; //[8 bytes] Elf32_Off [4 bytes]
Elf64_Off e_shoff; //[8 bytes] Elf32_Off [4 bytes]
.......
} Elf64_Ehdr;
因此,从 32 位到 64 位 ELF,大小差异为 (4*3)=12 个字节 header。另请注意,header 可能会按照规范的指示在末尾包含额外的位。
解析 ELF 二进制文件时,请确保先读取前 16 个字节,以确定文件是 32 位还是 64 位 elf。