Created
March 23, 2012 08:38
-
-
Save ropo/2168401 to your computer and use it in GitHub Desktop.
64bit実行ファイルかどうか
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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