Instantly share code, notes, and snippets.

Embed
What would you like to do?
BOOL is64bit=FALSE;
BOOL is64BitProcess()
{
HANDLE procImageFile;
IMAGE_DOS_HEADER dosHdr;
IMAGE_NT_HEADERS ntHdr;
DWORD read;
HMODULE mod;
wchar_t fname[MAX_PATH] = { 0 };
mod = GetModuleHandle(NULL);
GetModuleFileNameW(mod, fname, MAX_PATH);
procImageFile = CreateFile((LPCWSTR)fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (procImageFile == INVALID_HANDLE_VALUE)
return FALSE;
ReadFile(procImageFile, &dosHdr, sizeof(IMAGE_DOS_HEADER), &read, NULL);
SetFilePointer(procImageFile, dosHdr.e_lfanew, NULL, FILE_BEGIN);
ReadFile(procImageFile, &ntHdr, sizeof(IMAGE_NT_HEADERS), &read, NULL);
CloseHandle(procImageFile);
is64bit = ntHdr.FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64;
return is64bit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment