Advertisement
manman89

x32 x86 x64 - HOW TO DETECT PROCESS BITNESS

Jan 7th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Detection Matrix
  2.  
  3. The general idea is to check the following environment variables:
  4.  
  5. PROCESSOR_ARCHITECTURE - reports the native processor architecture EXCEPT for WOW64, where it reports x86.
  6. PROCESSOR_ARCHITEW6432 - not used EXCEPT for WOW64, where it reports the original native processor architecture.
  7.  
  8. Visually, it looks like:
  9.  
  10. Environment Variable \ Program Bitness ----- 32bit Native ---- 64bit Native ------ WOW64
  11. PROCESSOR_ARCHITECTURE --------------------- x86 ------------- AMD64 ------------- x86
  12. PROCESSOR_ARCHITEW6432 --------------------- undefined ------- undefined --------- AMD64
  13.  
  14. WOW64 = 32bit Program on 64bit OS
  15. Replace AMD64 with IA64 for Itaniums
  16.  
  17. Detection Logic
  18.  
  19. The logic that I use from a program to detect whether the OS is 32bit or 64bit looks like this:
  20.  
  21. IF PROCESSOR_ARCHITECTURE == amd64 OR
  22. PROCESSOR_ARCHITEW6432 == amd64 THEN
  23. // OS is 64bit
  24. ELSE
  25. // OS is 32bit
  26. END IF
  27.  
  28. Another way to test for the same thing is:
  29.  
  30. IF PROCESSOR_ARCHITECTURE == x86 AND
  31. PROCESSOR_ARCHITEW6432 NOT DEFINED THEN
  32. // OS is 32bit
  33. ELSE
  34. // OS is 64bit
  35. END IF
  36.  
  37. While detection for whether a process is in WOW64 mode is to simply check for the presence of the PROCESSOR_ARCHITEW6432 environment variable.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement