mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Jul 28, 2013 6:25 am Post subject: detecting OS bitness with Lua |
|
|
Code: | OsIs64Bit = cheatEngineIs64Bit() or ( os.getenv("PROCESSOR_ARCHITEW6432")~=nil ) |
How does it work?
Above code checks presence of the PROCESSOR_ARCHITEW6432 environment variable. It reports the original native processor architecture.
This variable is present only for 32 bit processes running on 64 bit OS.
Code: |
| 32 bit OS | 64 bit OS |
+---------------------------------------------------------------------|
| CE is a | CE is a | CE is a 32 bit process |
| 32 bit process | 64 bit process | (WOW64) |
-------------------------+------------------+------------------+-------------------------------|
PROCESSOR_ARCHITEW6432 | DOESN'T EXIST | DOESN'T EXIST | AMD64 or IA64 |
|
Lua os.getenv return nil if variable doesn't exist.
You know how logical OR works. If we use 64bit CE, we are 100% sure we have 64bit OS
We can easily change OsIs64Bit to OsIs32Bit:
Code: | OsIs32Bit = (not cheatEngineIs64Bit() ) and ( os.getenv("PROCESSOR_ARCHITEW6432")==nil ) |
As functions:
function OsIs64Bit() return cheatEngineIs64Bit() or ( os.getenv("PROCESSOR_ARCHITEW6432")~=nil ) end
function OsIs32Bit() return (not cheatEngineIs64Bit() ) and ( os.getenv("PROCESSOR_ARCHITEW6432")==nil ) end
Note:
cheat engine has those functions: cheatEngineIs64Bit() and targetIs64Bit().
targetIs64Bit() give us true if attached process is 64bit and false if 32bit. This is not enough because:
we can use 32 bit CE and attach to 32bit process on 64 bit OS. So, we have to attach to system process first (e.g. alg.exe) and then to our real target.
Method above doesn't require attaching to process.
Note2:
I used this trick for new CE menu entry - "Switch to 32/64 bit" (here)
OsIs32Bit variable prevents switching from 32bit CE to 64bit CE on 32 bit OS. _________________
|
|