ELF Section Header的结构还是要从/usr/include/elf.h中看。
同样,可以算出来Elf32_Shdr的大小是40B。其结构中的各个元素数据类型在elf.h中同样可以找到,含义见注释。整个section header table就是一个数组,数组的每一个元素就是Elf32_Shdr。Elf32_Shdr仅仅是section的一个索引,包括一些属性信息,并不是section本省。简单的介绍一下各个元素的含义。
sh_name: section name。[color=red]不过其实sh_name中存放的是index,不是字符串,这一点从sh_name是定长应该能看出来,那么index又是什么意思呢?index的含义是在string tabl总的第几个字节数。其实是这样的,所有的section name都存放在一个叫做string table的表中,index就是该section名字的第一个字符在表中的位置,名字一直到遇到一个'\0'为止结束[/color]。至于string table怎么找,还记得上一篇中提到的elf header中的e_shstrndx成员吗,它就指明了string table是在section header table中的第几个入口。
sh_offset:这个元素就指明了这个Elf32_Shdr描述的section在文件中的偏移量。
其他各个变量可以查询《Executable and Linkable Format(ELF)》这个文档。
typedef struct
{
Elf32_Word sh_name; /* Section name (string tbl index) */
Elf32_Word sh_type; /* Section type */
Elf32_Word sh_flags; /* Section flags */
Elf32_Addr sh_addr; /* Section virtual addr at execution */
Elf32_Off sh_offset; /* Section file offset */
Elf32_Word sh_size; /* Section size in bytes */
Elf32_Word sh_link; /* Link to another section */
Elf32_Word sh_info; /* Additional section information */
Elf32_Word sh_addralign; /* Section alignment */
Elf32_Word sh_entsize; /* Entry size if section holds table */
} Elf32_Shdr;
同样,可以算出来Elf32_Shdr的大小是40B。其结构中的各个元素数据类型在elf.h中同样可以找到,含义见注释。整个section header table就是一个数组,数组的每一个元素就是Elf32_Shdr。Elf32_Shdr仅仅是section的一个索引,包括一些属性信息,并不是section本省。简单的介绍一下各个元素的含义。
sh_name: section name。[color=red]不过其实sh_name中存放的是index,不是字符串,这一点从sh_name是定长应该能看出来,那么index又是什么意思呢?index的含义是在string tabl总的第几个字节数。其实是这样的,所有的section name都存放在一个叫做string table的表中,index就是该section名字的第一个字符在表中的位置,名字一直到遇到一个'\0'为止结束[/color]。至于string table怎么找,还记得上一篇中提到的elf header中的e_shstrndx成员吗,它就指明了string table是在section header table中的第几个入口。
sh_offset:这个元素就指明了这个Elf32_Shdr描述的section在文件中的偏移量。
其他各个变量可以查询《Executable and Linkable Format(ELF)》这个文档。