#i nclude <stdio.h>
#i nclude <windows.h>
#i nclude <winnt.h>
BOOL IsPEfile(LPVOID ImageBase);
int main(void)
{
HMODULE HINSTAN=NULL;
HINSTAN = GetModuleHandle(NULL);//获取文件实例句柄
if (IsPEfile(HINSTAN))
{
printf("Is a Protable Executable File!\n");
return 0;
}
printf("not is a protable Executable File!\n");
return 0;
}
// 1 //
////////////////////////判断文件是否为PE文件/////////////////////////////////////
BOOL IsPEfile(LPVOID ImageBase)
{
PIMAGE_DOS_HEADER PDH;
PIMAGE_NT_HEADERS32 PNTH;
if (!ImageBase)
{
return false;
}
PDH=(PIMAGE_DOS_HEADER)ImageBase;
if (PDH->e_magic!=IMAGE_DOS_SIGNATURE)
{
return false;
}
PNTH=(PIMAGE_NT_HEADERS32)((DWORD)PDH+PDH->e_lfanew);
if (PNTH->Signature != IMAGE_NT_SIGNATURE)
{
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////