typedef struct _IMAE_DOS_HEADER { WORD e_magic; //Magic number 0x00,”MZ“ WORD e_cblp; //Bytes on last page of file 0x02 WORD e_cp; //Pages in file 0x04 WORD e_crlc; //Relocations 0x06 WORD e_cparhdr; //Size of header in paragraphs 0x08 WORD e_minalloc; //Minimum extra paragraphs needed 0x0A WORD e_maxalloc; //Maximum extra paragraphs needed 0x0C WORD e_ss; //Initial (relative) SS value 0x0E WORD e_sp; //Initial SP value 0x10 WORD e_csum; //Checksum 0x12 WORD e_ip; //Initial IP value 0x14 WORD e_cs; //Initial (relative) CS value 0x16 WORD e_lfarlc; //File address of relocation table 0x18 WORD e_ovno; //Overlay number 0x1A WORD e_res[4]; //Reserved words 0x1C WORD e_oemid; //OEM identifier (for e_oeminfo) 0x24 WORD e_oeminfo; //OEM information; e_oemid specific 0x26 WORD e_res2[10]; //Reserved words 0x28 LONG e_lfanew; //offset to NT header } IMAGE_DOS-HEADER, *PIMAGE_DOS_HEADER;
e_magic:DOS签名(”MZ“,也就是”4D5A“)
e_lfanew:指示NT头(IMAGE_NT_HEADER)的偏移(000000E0)
DOS存根(stub):可选项,大小不固定
NT头:IMAGE_NT_HEADER(NT头):F8字节,有以下三个成员
Signature:50450000h(“PE”00)
File Header:IMAGE_FILE_HEADER,文件头
1 2 3 4 5 6 7 8 9
typedef struct _IMAGE_FILE_HEADER { WORD Machine; //计算机的体系结构类型,比如x86的值就是0x014c WORD NumberOfSections;//节数->文件中存在的节区数量,大于0,数量要和实际节区一致,否则会运行错误 DWORD TimeDateStamp;//文件时间戳的低32位,编译器创建此文件的时间 DWORD PointerToSymbolTable;//符号表的偏移量,以字节为单位,如果不存在 COFF 符号表,则为零。 DWORD NumberOfSymbols;//符号表中的符号数。 WORD SizeOfOptionalHeader;//指出Optional Header结构体的长度 WORD Characteristics;//特征,比如文件是否可运行(0x0002),是否是dll文件(0x2000)等 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;