# EncodeHex() in Windows crashes with Einhugur binary string

**URL:** <https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618>\
**Category:** Windows\
**Created:** [August 31, 2013, 9:13pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618 "2013-08-31T21:13:32Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [August 31, 2013, 9:13pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/1 "2013-08-31T21:13:32Z")

</div>

\<[https://xojo.com/issue/29250](https://xojo.com/issue/29250)\>

This bug is only a problem in Windows, not in Mac, Linux or Web Edition. It is not an error in Einhugur’s plugin (I used the latest v10.2.1) but in Xojo. I was using Xojo 2013 b5, but it was there in previous non-beta versions. It was not a problem in RS that I remember as I have this code in the current app.

Convert a string to an encrypted binary string using Einhugur’s plugin:

Dim returnString, tempString As String  
Dim tempInt, tempInt2 As Integer

returnString = Encrypt(Salt + OriginalText, PassKey, 0) 'This part works OK  
returnString = EncodeHex(returnString, True) 'this is where Windows gives an ‘XYZ application has stopped working’ error. EncodeHex inserts spaces and makes the Hex uppercase

I am not sure if there is something funny in the Einhugur binary string, but it seems OK in the debugger and as I said above it works fine in Mac, Web and Linux.

Workarounds:  
The workaround is to Hex the binary string manually  this works in Windows:

'EncodeHex crashes in Windows, so manually Hex the binary string  
returnString = “”  
tempInt2 = LenB(tempString)  
For tempInt = 1 to tempInt2  
returnString = returnString + Right(“0” + Hex(Asc(Mid(tempString, tempInt, 1))), 2) + " "  
next  
if right(returnString, 1) = " " then returnString = left(returnString, len(returnString) - 1) 'remove trailing space

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [August 31, 2013, 10:20pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/2 "2013-08-31T22:20:27Z")

</div>

Maybe you ask Björn about how he builds the string…

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [August 31, 2013, 10:25pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/3 "2013-08-31T22:25:04Z")

</div>

Your case occurs for any string or just one specific string? EncodeHex() hangs even with EncodeHex(returnString, False) ? As you know the result of the Encryt(), can you replace this line (to check if the guilt comes from there) by a DecodeHex() to obtain the same result and check if the following EncodeHex() will hang?

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [August 31, 2013, 11:33pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/4 "2013-08-31T23:33:13Z")

</div>

The string is raw binary data without encoding since its encrypted. I am guessing the EncodeHex function does something internally that assumes encoding. So you would get random crashes passing in binary data to it.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [September 1, 2013, 2:04am UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/5 "2013-09-01T02:04:05Z")

</div>

I recall reporting something similar on the mailing list a few months ago.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [September 1, 2013, 4:37am UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/6 "2013-09-01T04:37:13Z")

</div>

Well I have no idea whats wrong but the following encodes every byte value just fine  
This suggest something else is going on - but I’m not sure what

Dim returnString As String

dim mb as new memoryblock(256)

for i as integer = 0 to 255  
mb.byte(i) = i  
next

returnString = EncodeHex(mb, True)

break

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [September 1, 2013, 5:02am UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/7 "2013-09-01T05:02:27Z")

</div>

Could be great trying to isolate the origin as I told, with few tests.  
If we can’t reproduce the problem without the Encrypt() part (a specific content causing the problem), Björn will need to check the case more deeply.

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [September 1, 2013, 6:14am UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/8 "2013-09-01T06:14:59Z")

</div>

Is usually character combination that means something in some text encoding and not a specific byte code that creates such crash. Win32 API calls are very sensitive to getting different encoding than expected.

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [September 1, 2013, 6:16am UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/9 "2013-09-01T06:16:09Z")

</div>

I suppose he could give us the hex codes of the string that crashes ?

And better yet, try to execute that string on his system. A string created from the hex codes.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [September 1, 2013, 1:08pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/10 "2013-09-01T13:08:46Z")

</div>

Remember this only has a problem with Windows (tests OK on Mac, Linux and WE).

Try the following under Windows:

tempString = Encrypt("!VRkZ$$t4#_Rstest123", "v6mX??+q0Q)B_", 0) 'This returns ‘??{%\<??bJ??t??\*??z+?’

tempString = EncodeHex(tempString, True) 'this returns Hex ‘CF CF 7B 25 3C D1 81 62 4A 04 BB 74 BD 89 2A C9 F2 7A 2B BD’ on Mac, but crashes under Windows

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [September 1, 2013, 1:10pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/11 "2013-09-01T13:10:23Z")

</div>

In the debugger, what is the encoding of tempString before you try to run EncodeHex?

(Both platforms would be helpful)

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [September 1, 2013, 1:15pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/12 "2013-09-01T13:15:01Z")

</div>

No encoding, just:

Dim returnString, tempString As String

I tried to place a DefineEncoding command after the encrypt plus a MidB(tempString, 0) but neither helped.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [September 1, 2013, 1:17pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/13 "2013-09-01T13:17:20Z")

</div>

For a bug report and attach a sample project. I’d really like us to see this in action.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [September 1, 2013, 9:41pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/14 "2013-09-01T21:41:38Z")

</div>

I have added an attachment to the FeedBack report. Run it under Windows and click the ‘EncodeHex’ button a couple of times and Windows will complain that the app has stopped working. Clicking the ‘non-EncodeHex’ button does a manual EncodeHex().

Interestingly, placing the code directly in the button rather than calling a method doesn’t seem to cause the crash.

It might also be the particular Salt, PassKey and password I am using, but I don’t think so, since they are normal ASCII characters.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [September 1, 2013, 11:00pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/15 "2013-09-01T23:00:47Z")

</div>

Remove the calls to the plugin & see what happens  
If you get no crashes without using the plugin then you’ve probably isolated it to something about using the plugin

The code I pasted above I’ve run in a loop about 100000 times and it encodes it all possible byte values each time in that loop with out problems.

Some thing else is the issue

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 4:49pm UTC](https://forum.xojo.com/t/encodehex-in-windows-crashes-with-einhugur-binary-string/10618/16 "2020-10-29T16:49:43Z")

</div>


