Skip to content

Instantly share code, notes, and snippets.

@ropo
Created March 23, 2012 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ropo/2168401 to your computer and use it in GitHub Desktop.
Save ropo/2168401 to your computer and use it in GitHub Desktop.
64bit実行ファイルかどうか
#include <windows.h>
#include <stdio.h>
int main( int argc, char **argv )
{
if( argc < 2 )
return -1;
FILE *fp = fopen( argv[1], "rb" );
if( fp==NULL )
return -1;
IMAGE_DOS_HEADER idh;
if( fread( &idh, sizeof(idh), 1, fp ) != 1 )
return -1;
if( idh.e_magic != 0x5a4d )
return -1;
fseek( fp, idh.e_lfanew, SEEK_SET );
IMAGE_NT_HEADERS inh;
if( fread( &inh, sizeof(inh), 1, fp ) != 1 )
return -1;
fclose( fp );
return inh.FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment