Dougiefresh Posted September 18, 2012 Share Posted September 18, 2012 (edited) I found the thread "Check if EXE is x64?" at Neowin forums and decided to see if I could translate the code into AutoIt..... Here's the new function for all to use!#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** MsgBox(0, "", _File_Is_X64("C:\Windows\system32\calc.exe")) MsgBox(0, "", _File_Is_X64("C:\Windows\SysWOW64\wscript.exe")) MsgBox(0, "", _File_Is_X64("C:\Windows\System32\shell32.dll")) MsgBox(0, "", _File_Is_X64("C:\Windows\SysWOW64\shell32.dll")) Func _File_Is_X64($file) Local $handle = FileOpen($file, 16) If $handle = -1 Then Return SetError(-2, -2, "Invalid") If BinaryToString(FileRead($handle, 2)) = 'MZ' Then FileSetPos($handle, 60, 0) FileSetPos($handle, Int(FileRead($handle, 4)) + 4, 0) Local $in = FileRead($handle, 2) FileClose($handle) If $in = "0x6486" Then Return "AMD64" If $in = "0x4c01" Then Return "i386" If $in = "0x0002" Then Return "IA64" EndIf Return "Unknown" EndFunc ;==>_File_Is_X64Note that if you are checking a file in the system32 folder and running the Autoit script as a 32-bit application, it will always report "i386" because of the 64-bit OS's redirection mechanism that sends those requests to the SysWOW64 folder.Hope this helps somebody!Is_X64.au3 Edited September 18, 2012 by Dougiefresh Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 19, 2012 Moderators Share Posted September 19, 2012 (edited) Neat.Just curious, have you checked out:http://msdn.microsoft.com/en-us/library/aa364819%28VS.85%29.aspx which the link above the reference post you provided also notedIf you looked at:You could have possibly used:_WinAPI_GetBinaryType()Which you can probably find references on use here:https://www.google.com/search?q=_WinAPI_GetBinaryType+site%3Ahttp%3A%2F%2Fautoitscript.comEdit:Played around with yours a bit, I noticed you only close the handle if a successful PE header.I didn't thoroughly test this, but might give you different perspective, since you're function says you're testing for x64, I was unsure why you returning strings, so I included the types in the @extended portion:Func _PE_Isx64($s_pe) ; extended: 1 = amd64, 2 = ia64, 4 = i386 Local $h_pe = FileOpen($s_pe, 16) If $h_pe = -1 Then Return SetError(1, 0, 0) If BinaryToString(FileRead($h_pe, 2)) <> "MZ" Then FileClose($h_pe) Return SetError(2, 0, 0) EndIf FileSetPos($h_pe, 60, 0) Local $sz_type = FileRead($h_pe, 4) FileSetPos($h_pe, Number($sz_type) + 4, 0) $sz_type = FileRead($h_pe, 2) FileClose($h_pe) Switch $sz_type Case "0x6486" Return SetExtended(1, 1) Case "0x0002" Return SetExtended(2, 1) Case "0x4C01" Return SetExtended(4, 0) EndSwitch Return SetError(3, 0, 0) EndFunc Edited September 19, 2012 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now