#include “pch.h”
#include
#include
#include<Windows.h>
IMAGE_DOS_HEADER myDosHeader;
IMAGE_NT_HEADERS myNTHeader;
IMAGE_FILE_HEADER myFileHeader;
IMAGE_OPTIONAL_HEADER myOptionHeader;
IMAGE_SECTION_HEADER* pmySectionHeader;
LONG e_lfanew;
int main(int argc, char* argv[])
{
FILE* pfile;
errno_t error;
DWORD fileSize = 0;
if ((error = fopen_s(&pfile, "文件路径", "r")) != 0)
{
printf("打开文件错误!");
getchar();
}
//DOS头部分
printf("================IMAGE_DOS_HEADER================\n");
fread(&myDosHeader, 1, sizeof(IMAGE_DOS_HEADER), pfile);
if (myDosHeader.e_magic != 0x5A4D)
{
printf("不是MZ开头的文件!");
fclose(pfile);
exit(0);
}
printf("WORD e_magic: %04X\n", myDosHeader.e_magic);
printf("DOWRD e_lfaner: %08X\n\n", myDosHeader.e_lfanew);
e_lfanew = myDosHeader.e_lfanew;
//NT头部分
printf("================IMAGE_NT_HEADER================\n");
fseek(pfile, e_lfanew, SEEK_SET);
fread(&myNTHeader, 1, sizeof(IMAGE_NT_HEADERS), pfile);
if (myNTHeader.Signature !=