源码:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
int main(int argc, char* argv[])
{
char *FileName = argv[1];
HANDLE hFile = CreateFile(FileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
if (hFile == INVALID_HANDLE_VALUE)
{
cout<<"文件打开失败!"<<endl;
return -1;
}
IMAGE_DOS_HEADER dosHeader;
bool bRet;
DWORD readSize;
bRet = ReadFile(hFile,&dosHeader,sizeof(dosHeader),&readSize,NULL);
if (!bRet)
{
cout<<"读取文件失败!"<<endl;
return -1;
}
cout<<hex<<dosHeader.e_lfanew<<endl;
IMAGE_NT_HEADERS peHeader;
SetFilePointer(hFile,dosHeader.e_lfanew,NULL,FILE_BEGIN);
bRet = ReadFile(hFile,&peHeader,sizeof(peHeader),&readSize,NULL);
if (!bRet)
{
cout<<"读取文件失败!"<<endl;
return -1;
}
IMAGE_OPTIONAL_HEADER imOpHeader;
imOpHeader = peHeader.OptionalHeader;
cout<<imOpHeader.AddressOfEntryPoint<<endl;
CloseHandle(hFile);
return 0;
}