Jump to content

Autoit v3 script has stopped working


Tippex
 Share

Go to solution Solved by Tippex,

Recommended Posts

My script fails when I try to run it natively under 64bit but works if emulating 32bit.

It's from a large script so I have reduced it to just an example with the failing function (found from a google search to decode Base64 data). 

Setting

#AutoIt3Wrapper_UseX64=n

allows the script to work OK

Setting

#AutoIt3Wrapper_UseX64=y

crashes the script in a way that I cannot trap the error.

I suspect the use of "user32.dll" when running natively (no 32bit emulation) is what's causing AutoIt to dramatically crash out.

I'd like very much to know how to amend the function to work with 64bit so that I can test which to call using:

If @AutoItX64 = 1 Then

Any ideas please?

#AutoIt3Wrapper_UseX64=n
;#AutoIt3Wrapper_UseX6=n - Script works OK and the MsgBox gives "oxA1A2A3A4B1B2B3B4"
;#AutoIt3Wrapper_UseX6=y - Script crashes and AutoIT3.exe ended. rc:- 1073741819 (Win 7 gives "AutoIt v3 Script has stopped working")
MsgBox(0,"Base64Decode",_Base64Decode("oaKjpLGys7R="))
Func _Base64Decode($Data)
    Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000"
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    Local $Ouput = DllStructCreate("byte[" & BinaryLen($Data) & "]")
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
            "str", $Data, _
            "ptr", DllStructGetPtr($Ouput), _
            "int", 0, _
            "int", 0)
    Return BinaryMid(DllStructGetData($Ouput, 1), 1, $Ret[0])
EndFunc   ;==>_Base64Decode
Link to comment
Share on other sites

  • Solution

Problem solved!

After posting I spotted:

with replacement:

Func _B64Decode($sSource)

    Local Static $Opcode, $tMem, $tRevIndex, $fStartup = True

    If $fStartup Then
        If @AutoItX64 Then
            $Opcode = '0xC800000053574D89C74C89C74889D64889CB4C89C89948C7C10400000048F7F148C7C10300000048F7E14989C242807C0EFF3D750E49FFCA42807C0EFE3D750349FFCA4C89C89948C7C10800000048F7F14889C148FFC1488B064989CD48C7C108000000D7C0C0024188C349C1E30648C1E808E2EF49C1E308490FCB4C891F4883C7064883C6084C89E9E2CB4C89D05F5BC9C3'
        Else
            $Opcode = '0xC8080000FF75108B7D108B5D088B750C8B4D148B06D7C0C00288C2C1E808C1E206D7C0C00288C2C1E808C1E206D7C0C00288C2C1E808C1E206D7C0C00288C2C1E808C1E2060FCA891783C70383C604E2C2807EFF3D75084F807EFE3D75014FC6070089F85B29D8C9C21000'
        EndIf

        Local $aMemBuff = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", BinaryLen($Opcode), "dword", 4096, "dword", 64)
        $tMem = DllStructCreate('byte[' & BinaryLen($Opcode) & ']', $aMemBuff[0])
        DllStructSetData($tMem, 1, $Opcode)

        Local $aRevIndex[128]
        Local $aTable = StringToASCIIArray('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')
        For $i = 0 To UBound($aTable) - 1
            $aRevIndex[$aTable[$i]] = $i
        Next
        $tRevIndex = DllStructCreate('byte[' & 128 & ']')
        DllStructSetData($tRevIndex, 1, StringToBinary(StringFromASCIIArray($aRevIndex)))

        $fStartup = False
    EndIf

    Local $iLen = StringLen($sSource)
    Local $tOutput = DllStructCreate('byte[' & $iLen + 8 & ']')
    DllCall("kernel32.dll", "bool", "VirtualProtect", "struct*", $tOutput, "dword_ptr", DllStructGetSize($tOutput), "dword", 0x00000004, "dword*", 0)

    Local $tSource = DllStructCreate('char[' & $iLen + 8 & ']')
    DllStructSetData($tSource, 1, $sSource)

    Local $aRet = DllCallAddress('uint', DllStructGetPtr($tMem), 'struct*', $tRevIndex, 'struct*', $tSource, 'struct*', $tOutput, 'uint', (@AutoItX64 ? $iLen : $iLen / 4))

    Return BinaryMid(DllStructGetData($tOutput, 1), 1, $aRet[0])

EndFunc   ;==>_B64Decode
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...