How can I be sure that a file passed to my program is a valid exe file ?
actually my program takes a file as input and runs it, but user can input any file so I have
You can check if a file is a valid PE format file using the PE Format DLL.
PE files can contain more than just executable code. The can contain resources as well as code, or just resources and no code. PE files can also be native or managed, or native but linked to managed code etc. Depending on what you want to do, being able to check for these things would be useful.
PE_EXE3 pef;
int ok = FALSE;
if (pef.openFile(fileNameAndPath))
{
if (pef.IsValid())
{
ok = pef.GetHasExecutableCode();
}
pef.closeFile();
}
You may also find the following functions useful:
pef.GetIsOnlyResource()
pef.GetHasExecutableCode()
pef.GetIsPureDotNetModule()