Gunnar Posted June 6, 2018 Share Posted June 6, 2018 I'm using the _HexToString Function (included in String.au3 Library). The tool I coded with AutoIt in 2014 worked perfectly, but when I recompile with an actual AutoIt Version the Calculations have wrong results. I digged into and found the root cause, the _HexToString Function does a bad job starting with AutoIt 3.3.14.0 (Released 10th July, 2015) . The Changelog says: "Changed: _HexToString() to _StringToHex() now handles strings and binary as UTF-8 by default." OK, so you changed the internal handling. But in my opinion this should not lead to a wrong result. To demonstrate the problem, I wrot some lines of sample code. What I do is: Convert a Hex to a String, then convert the String to a Hex. I would expect, that the Input-HEX is the same as the output HEX. But you can see, that this is not the case, the output-Hex changes (starting with v3.3.14.0). Workaround: Using my own _HexToStringAnsi and _StringToHexAnsi Functions which to the conversion like it was done ins String.au3 in older Versions. Opt("MustDeclareVars", 1) #include <String.au3> Local $HEX = "08045cb64115eb65e2466e1b5c19065def72e35b5402249e1159f279f9dd02b9" Local $StringUTF8 = _HexToString($HEX) Local $StringAnsi = _HexToStringAnsi($HEX) ConsoleWrite("Demonstrating: AutoIt _HexToString and _StringToHex broken since Version 3.3.14.0 (uses UTF8 instead of ANSI)" & @CRLF) ConsoleWrite("String ANSI: " & $StringAnsi & @CRLF) ConsoleWrite("String UTF8: " & $StringUTF8 & @CRLF) ConsoleWrite("HEX original input: " & $HEX & @CRLF) ; ConsoleWrite("HEX converted from Ansi: " & _StringToHexAnsi($StringAnsi) & @CRLF) ; ConsoleWrite("HEX converted from UTF8: " & _StringToHexAnsi($StringUTF8) & @CRLF) ; ; Instead of using _StringtoHex and _HexToString from String.au3 using this self-made Functions: Func _StringToHexAnsi($sString) Return Hex(StringToBinary($sString, $SB_ANSI)) EndFunc Func _HexToStringAnsi($sHex) If Not (StringLeft($sHex, 2) == "0x") Then $sHex = "0x" & $sHex Return BinaryToString($sHex, $SB_ANSI) EndFunc Attached a Screenshot of the Output with most current AutoIt v3.3.14.5 (Released 16th March, 2018). Link to comment Share on other sites More sharing options...
Gunnar Posted June 6, 2018 Author Share Posted June 6, 2018 Slightly modified, to demonstrate both Conversion Variants: Opt("MustDeclareVars", 1) #include <String.au3> Local $HEX = "08045cb64115eb65e2466e1b5c19065def72e35b5402249e1159f279f9dd02b9" Local $StringUTF8 = _HexToString($HEX) Local $StringAnsi = _HexToStringAnsi($HEX) ConsoleWrite("Demonstrating: AutoIt _HexToString and _StringToHex broken since Version 3.3.14.0 (uses UTF8 instead of ANSI)" & @CRLF) ConsoleWrite("String ANSI: " & $StringAnsi & @CRLF) ConsoleWrite("String UTF8: " & $StringUTF8 & @CRLF) ConsoleWrite("HEX original input: " & $HEX & @CRLF) ; ConsoleWrite("HEX converted from Ansi as Ansi: " & _StringToHexAnsi($StringAnsi) & @CRLF) ; ConsoleWrite("HEX converted from UTF8 as Ansi: " & _StringToHexAnsi($StringUTF8) & @CRLF) ; ConsoleWrite("HEX converted from UTF8 as UTF8: " & _StringToHex($StringUTF8) & @CRLF) ; ; Instead of using _StringtoHex and _HexToString from String.au3 using this self-made Functions: Func _StringToHexAnsi($sString) Return Hex(StringToBinary($sString, $SB_ANSI)) EndFunc Func _HexToStringAnsi($sHex) If Not (StringLeft($sHex, 2) == "0x") Then $sHex = "0x" & $sHex Return BinaryToString($sHex, $SB_ANSI) EndFunc Output: 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