#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)\n", pImageDosHeader->e_magic, *uFileMap, *(uFileMap + 1));
	printf("e_lfanew:	0x%08X\n",pImageDosHeader->e_lfanew);
	UnmapViewOfFile(uFileMap);
	CloseHandle(hMapObject);
	CloseHandle(hFile);
	return 0;
}

相关文章:

  • 2021-04-25
  • 2021-12-02
  • 2021-07-07
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
猜你喜欢
  • 2022-01-25
  • 2022-01-17
  • 2022-01-29
  • 2021-05-19
  • 2021-12-03
  • 2021-09-15
  • 2021-10-28
相关资源
相似解决方案