Valhalla Legends Forums Archive | Battle.net Bot Development | 0x65 parsing help

AuthorMessageTime
CrAz3D
I've looked through BnetDocs & know what each little thing is, I'm just not sure as how to go about seperating each little part on it's own.


[quote]0000  FF 65 46 00 04 65 2D 33 37 37 00 00 00 00 00 00    .eF..e-377......
0010  00 00 5A 65 74 68 33 44 00 00 00 00 00 00 00 00    ..Zeth3D........
0020  43 72 41 7A 33 44 5B 78 4C 5D 00 01 02 50 58 45    CrAz3D[xL]...PXE
0030  53 4F 70 20 45 78 69 6C 65 00 41 6C 61 6E 00 00    SOp Exile.Alan..
0040  02 4E 42 32 57 00                                  .NB2W.[/quote]
I know I have 4 friends.
February 28, 2005, 4:37 AM
UserLoser.
Grab first byte, loop that many times through the remaining data grabbing each part at a time.  It's not even close to being hard.  Same way you extract the 4 bytes from a chat event for id, ping, flags, the remaining bytes for username, and text.  Except in this case, you're looping X (where X is the amount of friends) amount of times
February 28, 2005, 4:47 AM
CrAz3D
[quote author=UserLoser link=topic=10750.msg101924#msg101924 date=1109566066]
Grab first byte, loop that many times through the remaining data grabbing each part at a time.  It's not even close to being hard.  Same way you extract the 4 bytes from a chat event for id, ping, flags, the remaining bytes for username, and text.  Except in this case, you're looping X (where X is the amount of friends) amount of times
[/quote]

Ok, I loop through it 4 times (in mycase), but how do I know when to start at the top again?  When I've found 5 items?
February 28, 2005, 5:07 AM
Kp
After going through X times, you should have exhausted the packet and you can quit parsing.  There's no need to loop around.
February 28, 2005, 5:45 AM
CrAz3D
K, I've gone through the packet X times, but I am obviouslyt seperating the info incorrectly.

This is "DATA"
[quote]0000  FF 65 49 00 02 69 6C 6C 69 6E 69 6D 6F 6E 65 79    .eI..illinimoney
0010  31 33 00 00 02 50 58 45 53 42 72 6F 6F 64 20 57    13...PXESBrood W
0020  61 72 20 55 53 41 2D 31 00 68 65 6E 6B 79 31 39    ar USA-1.henky19
0030  39 32 00 00 02 50 58 45 53 42 72 6F 6F 64 20 57    92...PXESBrood W
0040  61 72 20 55 53 41 2D 31 00                        ar USA-1.[/quote]


This is how I parse "DATA"
[code]Public Sub ParseFList(ByVal Data As String)
Dim d() As String, s As String, i As Byte, iPos As Integer
Dim Account As String, Status As Byte, Location As Byte, ProductID As Long, Channel As String

d = Split(Mid(Data, 6), Chr(0))
s = Mid(Data, 6)
If s = vbNullString Then Exit Sub
iPos = 1

For i = 0 To Asc(Mid(Data, 5, 1)) - 1
    Account = BN.KillNull(Mid(s, iPos, InStr(iPos, s, Chr(0))))
        iPos = iPos + Len(Account)
    Status = Asc(Mid(s, iPos, 2))
        iPos = iPos + Len(Status)
    Location = Asc(Mid(s, iPos, 2))
        iPos = iPos + Len(Location)
    ProductID = BN.GetDWORD(Mid(s, iPos, 4))
        iPos = iPos + Len(ProductID)
    Channel = BN.KillNull(Mid(s, iPos, InStr(iPos, s, Chr(0))))
        iPos = iPos + Len(Channel)
    FN.Chat vbGreen, Account & " " & Status & " " & Location & " " & ProductID & " " & Channel
Next i
End Sub[/code]


This is what I get returned
[quote][10:57:01 PM] illinimoney13 0 0 1163415554 SBrood War USA-1
[10:57:02 PM]  0 104 2037083749 1992[/quote]

[s]I'm doing something wrong somewhere, but I'm not sure where, could anyone point it out to me?[/s]

I JUST found something, I don't know why I was messing with it but I increased iPos by 1.  Now I get the correct username, however I am missing the client.

Also, the large number is the ProductID, SHOULD it be like that?
[quote][11:01:12 PM] illinimoney13 0 0 1163415554 SBrood War USA-1
[11:01:12 PM] henky1992 0 0 1163415554 SBrood War USA-1[/quote]

February 28, 2005, 5:55 AM
CrAz3D
Somehow I've managed to almost make it work.

New problem is that when a user becomes offline, my parsing is thrown off

[quote] 0000:  FF 65 5B 00 04 69 6C 6C 69 6E 69 6D 6F 6E 65 79  ÿe[.illinimoney
0010:  31 33 00 00 02 50 58 45 53 42 72 6F 6F 64 20 57  13..PXESBrood W
0020:  61 72 20 55 53 41 2D 31 00 68 65 6E 6B 79 31 39  ar USA-1.henky19
0030:  39 32 00 00 03 50 58 45 53 43 41 54 53 00 43 72  92..PXESCATS.Cr
0040:  61 7A 33 64 5B 78 6C 5D 00 00 00 00 00 00 00 00  az3d[xl]........
0050:  6A 69 6D 00 00 00 00 00 00 00 00                  jim.............
[11:51:38 PM] illinimoney13  0 PXES Brood War USA-1
[11:51:38 PM] henky1992  0 PXES CATS
[11:51:38 PM] Craz3d[xl]  0 
[11:51:38 PM]  0  [/quote]

[code]For i = 0 To Asc(Mid(Data, 5, 1)) - 1
    Account = BN.KillNull(Mid(s, iPos, InStr(iPos, s, Chr(0))))
        iPos = iPos + Len(Account) + 1
    Status = Asc(Mid(s, iPos, 2))
        iPos = iPos + Len(Status)
    Location = Asc(Mid(s, iPos, 2))
        iPos = iPos + Len(Location)
    ProductID = BN.KillNull(Mid(s, iPos, 4))
        iPos = iPos + Len(ProductID)
    Channel = BN.KillNull(Mid(s, iPos, InStr(iPos, s, Chr(0))))
        iPos = iPos + Len(Channel)
        iPos = iPos + 1
    FN.Chat vbGreen, Account & " " & Str(Status) & " " & ProductID & " " & Channel
    frmMain.lvFriends.ListItems.ADD , , Account, , FLIcon(StrReverse(ProductID), Status)
    frmMain.lvFriends.ListItems(frmMain.lvFriends.ListItems.Count).Tag = "Logged on: " & GetClient(StrReverse(ProductID)) & vbCrLf & _
        "Currently in: " & Channel & vbCrLf & "Status is currently: " & FLStatus(Status)
Next i[/code]
February 28, 2005, 6:50 AM
HdxBmx27
[quote][code]....
    Status = Asc(Mid(s, iPos, 2))
...
    Location = Asc(Mid(s, iPos, 2))
.....[/code][/quote]
Byte = 1, Word = 2, it should be 1 not 2.
~-~(HDX)~-~
February 28, 2005, 8:59 AM
CrAz3D
[code]For i = 0 To Asc(Mid(Data, 5, 1)) - 1

    Account = BN.KillNull(Mid(s, iPos, InStr(iPos, s, Chr(0)) - 1))
        iPos = iPos + Len(Account) + 1
    Status = Asc(Mid(s, iPos, 1))
        iPos = iPos + Len(Status)
    Location = Asc(Mid(s, iPos, 1))
        iPos = iPos + Len(Location)
    ProductID = BN.KillNull(Mid(s, iPos, 4))
        iPos = iPos + 4
    Channel = BN.KillNull(Mid(s, iPos, InStr(iPos, s, Chr(0)) - 1))
        iPos = iPos + Len(Channel)
        iPos = iPos + 1
   
Next i[/code]

That is what I ended up with.  Thanks all, I'm thinking sleep helped, it took me less time to realize mistakes this morning.
February 28, 2005, 4:38 PM
UserLoser.
[code]
Dim I As Byte

For I = 1 to m_Parse.ExtractByte
    Username = m_Parse.ExtractString
    Status = m_Parse.ExtractByte
    Location = m_Parse.ExtractByte
    Product = m_Parse.ExtractLong
    Channel = m_Parse.ExtractString

    'Todo: stuff

Next I
[/code]
February 28, 2005, 8:06 PM
HdxBmx27
Hurm You could do that.. If you had those functions.
Witch I don't and nither does he i'm guessing. So. I'll write up some code and post it when I get home tonight.
~-~(HDX)~-~
February 28, 2005, 10:43 PM
kamakazie
[quote author=HdxBmx27 link=topic=10750.msg101999#msg101999 date=1109630626]
Hurm You could do that.. If you had those functions.
Witch I don't and nither does he i'm guessing. So. I'll write up some code and post it when I get home tonight.
~-~(HDX)~-~
[/quote]

So then create those functions.  I'm sure you don't have to because people have posted packet buffers on this forum before.
February 28, 2005, 11:28 PM
Myndfyr
[quote author=UserLoser link=topic=10750.msg101978#msg101978 date=1109621219]
[code]
Dim I As Byte

For I = 1 to m_Parse.ExtractByte
    Username = m_Parse.ExtractString
    Status = m_Parse.ExtractByte
    Location = m_Parse.ExtractByte
    Product = m_Parse.ExtractLong
    Channel = m_Parse.ExtractString

    'Todo: stuff

Next I
[/code]
[/quote]

[off-topic] That code raises some interesting questions about VB in my mind.  I'm not sure about the semantics of VB, but I noticed this:
[code]For I = 1 to m_Parse.ExtractByte[/code]
I assume m_Parse is something that parses incoming data and then advances an internal indexer.  Now, my question is this -- does VB evaluate the To expression only once, at the beginning of the loop, or at each iteration?  If it evaluates the expression at each iteration, wouldn't that mess up the loop?
February 28, 2005, 11:40 PM
kamakazie
[quote author=MyndFyre link=topic=10750.msg102013#msg102013 date=1109634049]
[off-topic] That code raises some interesting questions about VB in my mind.  I'm not sure about the semantics of VB, but I noticed this:
[code]For I = 1 to m_Parse.ExtractByte[/code]
I assume m_Parse is something that parses incoming data and then advances an internal indexer.  Now, my question is this -- does VB evaluate the To expression only once, at the beginning of the loop, or at each iteration?  If it evaluates the expression at each iteration, wouldn't that mess up the loop?
[/quote]

Here's your answer:
[code]
Public Sub Test()
    Dim I As Integer
   
    For I = 1 To GetMax()
        Debug.Print ("I = " & I)
    Next I
End Sub

Public Function GetMax() As Integer
    Debug.Print ("GetMax()")
    GetMax = 4
End Function

Outputs:
GetMax()
I = 1
I = 2
I = 3
I = 4
[/code]

Most languages do this as for-loops are for the most part simply syntactic sugar for while-loops.
February 28, 2005, 11:45 PM
Myndfyr
[quote author=dxoigmn link=topic=10750.msg102014#msg102014 date=1109634355]
[quote author=MyndFyre link=topic=10750.msg102013#msg102013 date=1109634049]
[off-topic] That code raises some interesting questions about VB in my mind.  I'm not sure about the semantics of VB, but I noticed this:
[code]For I = 1 to m_Parse.ExtractByte[/code]
I assume m_Parse is something that parses incoming data and then advances an internal indexer.  Now, my question is this -- does VB evaluate the To expression only once, at the beginning of the loop, or at each iteration?  If it evaluates the expression at each iteration, wouldn't that mess up the loop?
[/quote]

Here's your answer:
[code]
Public Sub Test()
    Dim I As Integer
   
    For I = 1 To GetMax()
        Debug.Print ("I = " & I)
    Next I
End Sub

Public Function GetMax() As Integer
    Debug.Print ("GetMax()")
    GetMax = 4
End Function

Outputs:
GetMax()
I = 1
I = 2
I = 3
I = 4
[/code]

Most languages do this as for-loops are for the most part simply syntactic sugar for while-loops.
[/quote]

Okay, but what if there is a state change during the loop?  I could see it if the function was declared const, but since it's VB.... I dunno.  Thanks for the clarification though!
March 1, 2005, 12:30 AM
HdxBmx27
[code]Option Explicit
Private strBuffer As String
   
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (ByRef destination As Any, ByRef Source As Any, ByVal numbytes As Long)
   
Private Type FILETIME
  dwLowDateTime  As Long
  dwHighDateTime As Long
End Type

Public Sub SetData(Data As String)
    strBuffer = Data
End Sub

Public Function GetData() As String
    GetData = strBuffer
End Function

Public Sub ClearData()
    strBuffer = vbNullString
End Sub

Public Function removeFILETIME() As String
    Dim strFT(1) As String
    strFT = Split(removeNTString & Space(1), Space(1))
    If strFT(0) > 2147483647 Then strFT(0) = (strFT(0) - 4294967296#)
    If strFT(1) > 2147483647 Then strFT(1) = (strFT(1) - 4294967296#)
    removeFILETIME = strFT(0) & Space(1) & strFT(1)
End Function
Public Function removeNonNTString() As String
    removeNonNTString = Left(strBuffer, 4)
    strBuffer = Mid(strBuffer, 5)
End Function

Public Function removeATString() As String
    removeATString = Left(strBuffer, InStr(strBuffer, Chr(&HA)) - 1)
    strBuffer = Mid(strBuffer, Len(removeATString) + 2)
End Function

Public Function removeNTString() As String
    removeNTString = Left(strBuffer, InStr(strBuffer, Chr(&H0)) - 1)
    strBuffer = Mid(strBuffer, Len(removeNTString) + 2)
End Function

Public Function removeDWORD() As Long
    Dim lReturn As Long, strTmp As String
    strTmp = Left(strBuffer, 4)
    Call CopyMemory(lReturn, ByVal strTmp, 4)
    removeDWORD = lReturn
    strBuffer = Mid(strBuffer, 5)
End Function

Public Function removeWORD() As Long
    Dim lReturn As Long, strTmp As String
    strTmp = Left(strBuffer, 2)
    Call CopyMemory(lReturn, ByVal strTmp, 2)
    removeWORD = lReturn
    strBuffer = Mid(strBuffer, 3)
End Function

Public Function removeBYTE() As Byte
    removeBYTE = Asc(Left(strBuffer, 1))
    strBuffer = Mid(strBuffer, 2)
End Function
Public Function removeVOID(Leng As Integer) As String
    removeVOID = Left(strBuffer, Leng)
    strBuffer = Mid(strBuffer, Leng + 1)
End Function
[/code]
Hurm, thers a small class mod i wrote up real quick. Seems to work fine for 0x65.
Please post suggestions and comments, BUT ONLY if there helpfull, no "that code sucks" crap -.- its annoying.
~-~(HDX)~-~
March 1, 2005, 1:11 AM
kamakazie
[quote author=MyndFyre link=topic=10750.msg102017#msg102017 date=1109637045]
Okay, but what if there is a state change during the loop?  I could see it if the function was declared const, but since it's VB.... I dunno.  Thanks for the clarification though!
[/quote]

You mean something like:

[code]
Public Sub Test()
    Dim I as Integer

    For I = 0 to 1
        Debug.Print("I = " & I)
        I = 0
    Next I
End Sub
[/code]

That would result in an infinite loop.
March 1, 2005, 1:23 AM
tA-Kane
Changing your counter variables inside the loop can be dangerous if you don't know what you're doing.

But it's also a very common and useful feature of any half-way decent language.
March 1, 2005, 2:27 AM

Search