Sign in to follow this  
Followers 0
BeBoP

Binary data to string issues.

2 posts in this topic

I'm trying to convert binary data to a string however I am running into problems.

0x0D00000065426F7420737461727465642110000000654D6F76696E6720746F20616374203110000000654865616C206E6F74206E65656465641D00000065446F6E2774206E65656420746F2073686F702C20736B697070696E67100000006553656C6C206E6F74206E656564656409000000655374617368696E67

Just using BinaryToString() on the above data the function returns null. However removing certain characters from the binary data yields this.

$rcv = 0x0D00000065426F7420737461727465642110000000654D6F76696E6720746F20616374203110000000654865616C206E6F74206E65656465641D00000065446F6E2774206E65656420746F2073686F702C20736B697070696E67100000006553656C6C206E6F74206E656564656409000000655374617368696E67
    $sLeft = StringTrimLeft($rcv,12)
    $sReplace1065 = StringReplace ( $sLeft, "1000000065", "20")
    $sReplace1D65 = StringReplace ( $sReplace1065, "1D00000065", "20")
    $sReplaceD065 = StringReplace ( $sReplace1D65, "0D00000065", "20")
    $sReplace1065 = StringReplace ( $sReplaceD065, "1000000065", "20")
    $sReplace0065 = StringReplace ( $sReplace1065, "00000065", "20")
    $sReplace00 = StringReplace ( $sReplace0065, "00", "20")
    $sFixed = $sReplace00
    IniWrite("test.txt","test","test",BinaryToString("0x" & $sFixed))

Output:

Bot started! Moving to act 1 Heal not needed Don't need to shop, skipping Sell not needed    Stashing

The problem is that with some of the binary data I get weird characters and in complete strings. All I really did was replace all the data that BinaryToString() got stuck on with a space(20). This is pretty half-assed and I don't really know how to do it properly any help is greatly appreciated.

Share this post


Link to post
Share on other sites



I'm trying to convert binary data to a string however I am running into problems.

0x0D00000065426F7420737461727465642110000000654D6F76696E6720746F20616374203110000000654865616C206E6F74206E65656465641D00000065446F6E2774206E65656420746F2073686F702C20736B697070696E67100000006553656C6C206E6F74206E656564656409000000655374617368696E67

Just using BinaryToString() on the above data the function returns null. However removing certain characters from the binary data yields this.

$rcv = 0x0D00000065426F7420737461727465642110000000654D6F76696E6720746F20616374203110000000654865616C206E6F74206E65656465641D00000065446F6E2774206E65656420746F2073686F702C20736B697070696E67100000006553656C6C206E6F74206E656564656409000000655374617368696E67
    $sLeft = StringTrimLeft($rcv,12)
    $sReplace1065 = StringReplace ( $sLeft, "1000000065", "20")
    $sReplace1D65 = StringReplace ( $sReplace1065, "1D00000065", "20")
    $sReplaceD065 = StringReplace ( $sReplace1D65, "0D00000065", "20")
    $sReplace1065 = StringReplace ( $sReplaceD065, "1000000065", "20")
    $sReplace0065 = StringReplace ( $sReplace1065, "00000065", "20")
    $sReplace00 = StringReplace ( $sReplace0065, "00", "20")
    $sFixed = $sReplace00
    IniWrite("test.txt","test","test",BinaryToString("0x" & $sFixed))

Output:

Bot started! Moving to act 1 Heal not needed Don't need to shop, skipping Sell not needed Stashing

The problem is that with some of the binary data I get weird characters and in complete strings. All I really did was replace all the data that BinaryToString() got stuck on with a space(20). This is pretty half-assed and I don't really know how to do it properly any help is greatly appreciated.

The problem is that th ebinary data consists of more than one string, and each string is terminated with "00". So when you convert to a string the first "00" marks the end of the string and unfortunately the first string is just a carriage return. So first replace all the NULL characters and then you will see the strings.

$rcv1 = "0x0D00000065426F7420737461727465642110000000654D6F7" & _
    "6696E6720746F20616374203110000000654865616C206E6F7" & _
                "4206E65656465641D00000065446F6E2774206E65656420746" & _
                "F2073686F702C20736B697070696E67100000006553656C6C2" & _
                "06E6F74206E656564656409000000655374617368696E67"
$rcv = ''
For $n = 1 To StringLen($rcv1) Step 2
    $s = StringMid($rcv1, $n, 2)
    If $s <> "00" Then
     $rcv &= $s
 Else
     $rcv &= "20";use a space?
 EndIf

Next

ConsoleWrite(BinaryToString($rcv) & @CRLF)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
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
Sign in to follow this  
Followers 0