1.节区头
节区头中定义了各节区的属性。PE文件中的code(代码)、data(数据)、resource(资源)等按照属性分类存储在不同节区,这样可以保证程序的安全性。
IMAGE_SECTION_HEADER
节区头是由IMAGE_SECTION_HEADER结构体构成的数组,每个结构体对应一个节区。
代码 IMAGE_SECTION_HEADER结构体
#define IMAGE_SIZEOF_SHORT_NAME
typedef struct _IMAGE_SECTION_HEADER{
BYTE NAME[IMAGE_SIZEOF_SHORT_NAME];
union {
DWORD PhysicalAddress;
DWORD VirtualSize;
}Misc;
DWORD VirtualAddress;
DWORD SizeOfRawData;
DWORD PointerToRawData;
DWORD PointerToLinenumbers;
DWORD NumberOfRelocations;
DWORD NumberOfLinenumbers;
DWORD Characteristics;
} IMAGE_SECTION_HEADER, *.PIMAGE_SECTION_HEADER;
IMAGE_SECTION_HEADER结构体的重要成员
项目
含义
VirtualSize
内存中节区所占大小
VirtualAddress
内存中节区起始地址(RVA)
SizeOfRawData
磁盘文件中节区所占大小
PointerToRawData
磁盘文件中节区起始位置
Characteristics
节区属性(bit OR)
VirtualAddress与PointerToRawData不带有任何值,分别由(定义在IMAGE_OPTIONAL_HEADER32)SectionAlignment和FileAlignment确定。
VirtualSize与SizeOfRawData一般具有不同的值(即磁盘文件中节区的大小与加载到内存中的节区大小是不同的)。
Characteristics显示值的组合(bit OR)而成
#define IMAGE_SCN_CNT_CODE
0x00000020 //Section contains code.
#define IMAGE_SCN_CNT_INITIALIZED
0x00000040 //Section contains initialized data.
#define IMAGE_SCN_CNT_UNINITIALIZED
0x00000080 //Section contains unitialized data.
#define IMAGE_SCN_MEN_EXECUTE
0x20000000 //Section is executable.
#define IMAGE_SCN_MEN_READ
0x40000000
//Section is readable.
#define IMAGE_SCN_MEN_WRITE
0x80000000
//Section is writable.
Name字段
Name成员不像C语言中的字符串一样以NULL结束(没有“必须使用ASCII值”的限制,对Name未明确规定),所以可以放入任何值,甚至可以填充NULL值。(数据节区的名称也可以叫做.code)
使用010 Editor查看notepad.exe的节区头数组(共有3个节区)。