Program to check process architecture
Here is a small command line program written in C++ to check whether executable process architecture is 64 bit or 32 bit.
// IS64.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <Imagehlp.h>
#include <shlwapi.h>
#pragma comment (lib, "Imagehlp.lib")
#pragma comment (lib, "shlwapi.lib")
#include <iostream>
#include <vector>
#ifndef countof
#define countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
#endif
using namespace std;
/////////////////////////////////////////////////////////////
//Function for checking the PE file whether its 64 bit or not
/////////////////////////////////////////////////////////////
int IsX64(const char* pstrFilePath)
{
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
char dirpath[_MAX_PATH];
char filename[_MAX_FNAME];
memset(drive, '\0', sizeof(drive));
memset(dir, '\0', sizeof(dir));
memset(fname, '\0', sizeof(fname));
memset(ext, '\0', sizeof(ext));
memset(dirpath, '\0', sizeof(dirpath));
memset(filename, '\0', sizeof(filename));
_splitpath_s( pstrFilePath, drive, countof(drive), dir, countof(dir), fname, countof(fname), ext, countof(ext) );
_makepath_s( dirpath, countof(dirpath), drive, dir, NULL, NULL);
_makepath_s( filename, countof(filename), NULL, NULL, fname, ext);
LOADED_IMAGE *pImg = ImageLoad(filename, dirpath);
if(pImg)
{
if(IMAGE_FILE_MACHINE_I386 == pImg->FileHeader->FileHeader.Machine)
{
//printf("\nx86\n");
return 1;
}
else if(IMAGE_FILE_MACHINE_AMD64 == pImg->FileHeader->FileHeader.Machine)
{
//printf("\nx64\n");
return 2;
}
else if(IMAGE_FILE_MACHINE_IA64 == pImg->FileHeader->FileHeader.Machine)
{
printf("\nIntel IPF\n");
}
else
{
printf("Other\n");
}
}
return -1;
}
int main(int argc, char* argv[])
{
if(argc <=1 )
{
printf("\n\tAuthor: Manoj Jangid");
printf("\n\tVisit www.topfivesoftware.com for more tools");
printf("\n\tDetect whether EXE or DLL is 64 bit or Not");
printf("\n\t\tUsage: C:\\>IS64 <FilePath or Directory Path>\n");
}
else
{
string str(argv[1]);
if(PathIsDirectory(str.c_str()))
{
vector<string> str32;
vector<string> str64;
}
else if(2 == IsX64(str.c_str()))
{
printf("\n\n%s is 64 bit\n\n",str.c_str());
}
else if(1 == IsX64(str.c_str()))
{
printf("\n\n%s is 32 bit\n\n",str.c_str());
}
else
{
printf("\n\n%s Check path or exe/dll name \n\n",str.c_str());
}
}
return 0;
}
Download
Click here to download the source code
Question OR Feedback?
Note
If you want to ask anything related this post, please tweet your question or feedback @JangidUK I will try to respond as soon as possible.