Skip to content

Instantly share code, notes, and snippets.

@wjx0912
Created October 19, 2021 07:29
Show Gist options
  • Save wjx0912/8e349c093e5960e7e615b40a86035e14 to your computer and use it in GitHub Desktop.
Save wjx0912/8e349c093e5960e7e615b40a86035e14 to your computer and use it in GitHub Desktop.
isDifferentArch
/*
* XXX: Mixed architecture don't quite work. See also
* http://www.corsix.org/content/dll-injection-and-wow64
*/
static BOOL
isDifferentArch(HANDLE hProcess)
{
typedef BOOL (WINAPI *PFNISWOW64PROCESS)(HANDLE, PBOOL);
PFNISWOW64PROCESS pfnIsWow64Process;
pfnIsWow64Process = (PFNISWOW64PROCESS)
GetProcAddress(GetModuleHandleA("kernel32"), "IsWow64Process");
if (!pfnIsWow64Process) {
return FALSE;
}
// NOTE: IsWow64Process will return false on 32-bits Windows
BOOL isThisWow64;
BOOL isOtherWow64;
if (!pfnIsWow64Process(GetCurrentProcess(), &isThisWow64) ||
!pfnIsWow64Process(hProcess, &isOtherWow64)) {
logLastError("IsWow64Process failed");
return FALSE;
}
return bool(isThisWow64) != bool(isOtherWow64);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment