Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


detecting OS bitness with Lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
mgr.inz.Player
I post too much
Reputation: 148

Joined: 07 Nov 2008
Posts: 4155
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jul 28, 2013 6:25 am    Post subject: detecting OS bitness with Lua Reply with quote

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.

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites