#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int _tmain(int argc, TCHAR *argv[])
{
PIMAGE_DOS_HEADER pImageDosHeader;
HANDLE hFile;
HANDLE hMapObject;
PUCHAR uFileMap;
DWORD dw;
if (argc<2)
{
return -1;
}
if (!(hFile=CreateFile(argv[1],GENERIC_READ,0,NULL,OPEN_EXISTING,0,0)))
{
return -1;
}
if (!(hMapObject = CreateFileMapping((hFile),NULL,PAGE_READONLY,0,0,NULL)))
{
dw = GetLastError();
return -1;
}
if (!(uFileMap=MapViewOfFile(hMapObject,FILE_MAP_READ,0,0,0)))
{
return -1;
}
pImageDosHeader = (PIMAGE_DOS_HEADER)uFileMap;
if (pImageDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
{
return -1;
}
printf("e_magic: 0x%04X(%c%c)
", pImageDosHeader->e_magic, *uFileMap, *(uFileMap + 1));
printf("e_lfanew: 0x%08X
",pImageDosHeader->e_lfanew);
UnmapViewOfFile(uFileMap);
CloseHandle(hMapObject);
CloseHandle(hFile);
return 0;
}