IMAGE_DOS_HEADER
typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
WORD e_cp; // Pages in file
WORD e_crlc; // Relocations
WORD e_cparhdr; // Size of header in paragraphs
WORD e_minalloc; // Minimum extra paragraphs needed
WORD e_maxalloc; // Maximum extra paragraphs needed
WORD e_ss; // Initial (relative) SS value
WORD e_sp; // Initial SP value
WORD e_csum; // Checksum
WORD e_ip; // Initial IP value
WORD e_cs; // Initial (relative) CS value
WORD e_lfarlc; // File address of relocation table
WORD e_ovno; // Overlay number
WORD e_res[4]; // Reserved words
WORD e_oemid; // OEM identifier (for e_oeminfo)
WORD e_oeminfo; // OEM information; e_oemid specific
WORD e_res2[10]; // Reserved words
LONG e_lfanew; // File address of new exe header
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
DOS头
- DOS头由两部分组成:DOS MZ文件头和DOS块。
- DOS块不是结构体,而是由单个字节组成的数据,可以填写任何内容。
- 但是DOS MZ文件头是一个结构体。
WORD e_magic; // Magic number
LONG e_lfanew; // File address of new exe header
- 该结构体 IMAGE_DOS_HEADER 是给16位的程序使用的,现在的程序都是在32或者64位的平台上。
- 现在的程序已经不再使用该结构体中的成员,但是有两个成员例外。
- 它们分别是:WORD e_magic 和 LONG e_lfanew,它们是标识和Windows寻找PE头的位置的。
- 其他的成员可以使用0x00填充,程序不受影响可以正常运行,但是它们两个(WORD e_magic 和 LONG e_lfanew)不可以。
DOS块
DOS块中的内容是由链接器填写的,也可以自己填写任何东西,置零或修改并不会影响程序运行。
如下图,将DOS块中的内容使用00填充修改后保存,程序依然可以正常运行,没有任何影响。