[a101] FileObject problem Topic is solved

Report problems with documented functionality
User avatar
aseiot
Posts: 63
Joined: 05 Mar 2017, 04:25

[a101] FileObject problem

07 May 2019, 08:16

FileObject Seems cause crash.
Found when run GetExeMachine function in Ahk2exe

Code: Select all

GetExeMachine(exepath)
{
	exe := FileOpen(exepath, "r")
	if !exe
		return

	exe.Seek(60), exe.Seek(exe.ReadUInt()+4)
	return exe.ReadUShort()
}
Crash at:

Code: Select all

exe.Seek(60)
Change to "File.Pos := Distance" could not resolve the problem
User avatar
Alguimist
Posts: 371
Joined: 05 Oct 2015, 16:41
Contact:

Re: [a101] FileObject problem

07 May 2019, 16:03

Code for AHK v1:

Code: Select all

ExeFile:= "..."
MsgBox % GetExeMachine(ExeFile) ; 0x8664 (34404) = 64-bit, 0x014C (332) = 32-bit
MsgBox % GetBinaryType(ExeFile) ; 6 = 64-bit, 0 = 32-bit

GetExeMachine(ExeFile) {
    f := FileOpen(ExeFile, "r")
    If (!IsObject(f)) {
        MsgBox 0x10, Error, % GetErrorMessage(A_LastError)
        Return 0
    }

    f.Seek(60)
    f.Seek(f.ReadUInt() + 4)
    Return f.ReadUShort(), f.Close()
}

GetErrorMessage(ErrorCode, LanguageId := 0) {
    VarSetCapacity(ErrorMsg, 8192)
    DllCall("Kernel32.dll\FormatMessage"
        , "UInt", 0x1200 ; FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS
        , "UInt", 0
        , "UInt", ErrorCode + 0
        , "UInt", LanguageId
        , "Str" , ErrorMsg
        , "UInt", 8192)
    Return StrGet(&ErrorMsg)
}

GetBinaryType(ExeFile) {
    Return DllCall("Kernel32.dll\GetBinaryTypeW", "WStr", ExeFile, "Ptr*", BinaryType) ? BinaryType : -1
}
Code for AHK v2:

Code: Select all

ExeFile:= "..."
MsgBox GetExeMachine(ExeFile) ; 0x8664 (34404) = 64-bit, 0x014C (332) = 32-bit
MsgBox GetBinaryType(ExeFile) ; 6 = 64-bit, 0 = 32-bit

GetExeMachine(ExeFile) {
    Local f, Machine
    f := FileOpen(ExeFile, "r")
    If (!IsObject(f)) {
        MsgBox(GetErrorMessage(A_LastError), "Error", 0x10)
        Return 0
    }

    f.Seek(60)
    f.Seek(f.ReadUInt() + 4)
    Machine := f.ReadUShort()
    f.Close()
    Return Machine
}

GetErrorMessage(ErrorCode, LanguageId := 0) {
    VarSetCapacity(ErrorMsg, 8192)
    DllCall("Kernel32.dll\FormatMessage"
        , "UInt", 0x1200 ; FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS
        , "UInt", 0
        , "UInt", ErrorCode + 0
        , "UInt", LanguageId
        , "Str" , ErrorMsg
        , "UInt", 8192)
    Return StrGet(&ErrorMsg)
}

GetBinaryType(ExeFile) {
    Return DllCall("Kernel32.dll\GetBinaryTypeW", "WStr", ExeFile, "Ptr*", BinaryType) ? BinaryType : -1
}
lexikos
Posts: 7058
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [a101] FileObject problem  Topic is solved

09 May 2019, 22:34

Fixed in v2.0-a102.
User avatar
aseiot
Posts: 63
Joined: 05 Mar 2017, 04:25

Re: [a101] FileObject problem

10 May 2019, 10:14

Thanks, cheers :bravo:

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 2 guests