• Welcome to Valhalla Legends Archive.
 

How do I........?

Started by Nub_1, November 20, 2003, 04:41 PM

Previous topic - Next topic

Nub_1

How would I break a packet down, sent to me from B.net, into all the DWORDS and things, like I see on the site...?

Kp

Quote from: Nub_1 on November 20, 2003, 04:41 PM
How would I break a packet down, sent to me from B.net, into all the DWORDS and things, like I see on the site...?

The answer to this question depends upon what language you're coding in.  For cutting edge "safe" languages, which protect you from your own stupidity by denying pointers (among other things), it's a bit of a pain.  For older languages that trust you to know what you're doing, it's trivial.  What language are you using?  There's enough different solutions I'm not going to enumerate all possibilities.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Nub_1

sorry, forgot to include that...
I'm doing it in VB

Kp

Quote from: Nub_1 on November 20, 2003, 05:04 PM
sorry, forgot to include that...
I'm doing it in VB

Which VB?  6 or .Net?  VB6 isn't cutting edge, but it still denies you pointers in an attempt to keep stupid people from hurting themselves.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!


Hazard

Quote from: Kp on November 20, 2003, 05:38 PM
VB6 isn't cutting edge, but it still denies you pointers in an attempt to keep stupid people from hurting themselves.

Make something idiot proof and somebody will invent a better idiot.

"Courage is being scared to death - but saddling up anyway." --John Wayne

Nub_1

#6
... :'(

MyndFyre

Quote from: Nub_1 on November 24, 2003, 02:52 PM
... :'(

Well I'm not exactly certain about how to actually DO it in VB6, but think about it this way...

When you send packet 0x50 to Bnet, there is a response you know you should get back.  If you know what the response is, you can use various functions, such as CopyMemory from the Windows API, to copy the memory into each variable (that's how a lot of VB bots do it, IIRC).  If you're using VB.NET, you can use the BitConverter class and all of the shared methods it provides; unfortunately, that's only available through .NET (and is the way that I wrote my bot).  When you (for example) use a socket and get back a huge array of bytes, you know that four bytes will be coming in little-endian order for a DWORD.

Hope this helps.

--Rob
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Nub_1

#8
Quote from: Myndfyre on November 24, 2003, 04:04 PM

you can use various functions, such as CopyMemory from the Windows API, to copy the memory into each variable (that's how a lot of VB bots do it, IIRC

If you can, code would be appreciated...

ObsidianWolf

Copy memory code

Option Explicit

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal numbytes As Long)


Receiving data code

Private Sub Socket_DataArrival(ByVal bytesTotal As Long)
   Static strBuffer As String
   Dim strTemp As String, lngLen As Long
   
   Socket.GetData strTemp, vbString
   
   strBuffer = strBuffer & strTemp
   
   While Len(strBuffer) > 4
   
       lngLen = Val("&H" & Login.SringTohex(RevString(Mid(strBuffer, 3, 2))))
       
       If Len(strBuffer) < lngLen Then Exit Sub
       
       Login.ParseP Left(strBuffer, lngLen)
     
       strBuffer = Mid(strBuffer, lngLen + 1)
       
   Wend
End Sub


Need More, Its all over this forum, perhaps utilize the search funtion?

Nub_1

I don't think that answers my origional question  :-\

ObsidianWolf

Or perhaps you dont know what your looking for?  The Copymemory segment would be part of what you seek. the other part is kinda useless if you dont have the rest of it. None the less you could really look around the vL site and find what you need.  The question you should really be asking is, are you too lazy to look for it?  There is a packet buffer code on the Documents section of Botdev.

But Heres the Parse code you are looking for, note this code is not my work.

Public Sub ParseP(ByVal Data As String)

   On Error Resume Next
   
   Dim D As String
   Dim tmp As String
   Dim mpqend As Long
   Dim ping As Long, Username As String, message As String
   
   Select Case Asc(Mid(Data, 2, 1))
 
      'Case &H1C
      '    If PreBoolean = False Then
      '
      '         If Asc(Mid(Data, 5, 1)) = &H0 Then
      '
      'Authorizing Map...
      '
      '             Game.Authorize
      '
      '         Else
      '
      'Game start failed!
      '
      '         End If
      '
      '     End If
      ' Case &H3C
      '
      '     If PreBoolean = False Then
      '
      '         If Asc(Mid(Data, 5, 1)) = &H2 Then
      '
      'Game Started
      '
      '            Packet.SendPacket Index, &H0
      '
      'Game Playing
      '
      '         Else
      '
      'Game start failed
      '
      '         End If
      '
      '     End If
       Case &H2E
       Dim num As Long
       Dim str As String * 4
       
       Dim splituser() As String
       Dim X As Integer
           Data = Mid(Data, 1, Len(Data))
           splituser() = Split(Data, Chr(1))
           For X = 0 To UBound(splituser)
           str = Right(splituser(X), 8)
           CopyMemory num, ByVal str, 4
           Dim spltstrs() As String
               spltstrs() = Split(Hex(num), " ")
               num = spltstrs(3) & " " & spltstrs(2) & " " & spltstrs(1) & " " & spltstrs(0)
           AddTextMChat num & vbCrLf, vbGreen
           AddTextMChat splituser(X) & vbCrLf, vbRed
           Next X
       
       Case &H25
           If varPing = "" Then
               Packet.InsertDWORD 0
               Packet.SendPacket &H25
               ElseIf varPing = "1" Then
               
           End If
     
       Case &H6
           D = Data
           MPQName = Mid(D, InStr(D, "I"), Len(D) - InStr(InStr(D, "I"), D, Chr(0)))
           mpqend = InStr(InStr(D, "I"), D, Chr(0))
           MPQName = Left(MPQName, InStr(MPQName, Chr(0)) - 1)
           Hash = Mid(D, mpqend + 1, InStr(mpqend + 1, D, Chr(0)) - 1)
           Hash = Left(Hash, InStr(Hash, Chr(0)) - 1)
           
           Dim version As Long
           Dim Checksum As Long
           Dim ExeInfo As String
           Dim Result As Long
           
           Packet.InsertNonNTString "68XI" & StrReverse(varProduct)
           Packet.InsertDWORD &HC7
                   ExeInfo = Space(256)
                   Result = CheckRevision(App.Path & "\" & varProduct & "\StarCraft.exe", App.Path & "\" & varProduct & "\storm.dll", App.Path & "\" & varProduct & "\battle.snp", Hash, version, Checksum, ExeInfo, MPQName)
                   AddChat vbMagenta, App.Path & "\" & varProduct & "\StarCraft.exe"
           Packet.InsertDWORD version
           Packet.InsertDWORD Checksum
                   NullTruncString ExeInfo
                   If ExeInfo = Space(256) Then
                       AddChat vbRed, ExeInfo
                       AddChat vbRed, "-Hashes Could Not Be Located"
                       Exit Sub
               
                   End If
           Packet.InsertNTString ExeInfo
           AddTextMChat "-Sending Product Version" & vbCrLf, vbYellow
           Packet.SendPacket 7
           
   
       Case &H7
           Select Case Mid(Data, 5, 1)
       
               Case Chr(2)
                   Packet.SendPacket &H2D
                   If varPing = "2" Then
                   Else
                   Packet.InsertNonNTString "tenb"
                   Packet.SendPacket &H14
                   End If
               AddTextMChat "-Product Version Accepted" & vbCrLf, vbGreen
   
               Case Else
               
               AddTextMChat "-Product versions rejected" & vbCrLf, vbRed
   
           End Select
         
       Case &H1D
       
           ServerHash = Right(Data, 4)
   
       Case &H2D
       
              AddTextMChat "-Sending CD-Key" & vbCrLf, vbYellow
           
           SendCDKey
       
       Case &H30, &H36
   
           Select Case Mid(Data, 5, 1)
           
               Case Chr(1)
                   AddTextMChat "-CD-Key Accepted" & vbCrLf, vbGreen
                   AddTextMChat "-Sending Username & Password" & vbCrLf, vbYellow
                   SendUsernamePassword
                   
               Case Else
                   AddTextMChat "-CD-Key rejected on bot" & vbCrLf, vbRed
               
           End Select
           
       Case &H29
       
           If Mid(Data, 5, 1) = Chr(1) Then
             
               AddTextMChat "-Logged on as " & varAccount & vbCrLf, vbGreen
                   
               Packet.InsertNTString varAccount
               Packet.InsertBYTE 0
               Packet.SendPacket &HA
               
               Packet.InsertNonNTString varProduct
               Packet.SendPacket &HB
               
               Packet.InsertDWORD 2
               Packet.InsertNTString varHome
               Packet.SendPacket &HC
           
           Else
           
               AddTextMChat "Account authorization failed" & vbCrLf, vbRed
   
           End If
           
       Case &HA
           With Packet
               .InsertNTString "/f l"
               .SendPacket &HE
           End With
               
       Case &HF
           
           frmMain.ParseR Data
           
       Case &HB
       frmChannel.ListView1.ListItems.Clear
           Dim Icon As String
           Dim SplitChan() As String
           Dim i As Integer
               Data = Mid(Data, 1, Len(Data))
               SplitChan() = Split(Data, Chr(0))
           For i = 0 To UBound(SplitChan) - 2
           If InStr(SplitChan(i), "ÿ") Or InStr(SplitChan(i), "þ") Then
           Else
           If InStr(SplitChan(i), "Blizzard") Then
           Icon = "blizz"
           Else
           Icon = "bnet"
           End If
               frmChannel.ListView1.ListItems.Add , , SplitChan(i), , Icon
           End If
           Next i
           
       Case &H9
           Dim SplitGame() As String
           Dim a As Integer
               frmGamelist.ListView1.ListItems.Clear
               Data = Mid(Data, 99, Len(Data))
               SplitGame() = Split(Data, Chr(0))
           For a = 0 To UBound(SplitGame) - 2
               frmGamelist.ListView1.ListItems.Add , , SplitGame(a)
           Next a
   End Select

End Sub


And even at that your probally going to be like...wha???  So I suggest taking some time and reading, if you cannot find out what you are looking for then read more.   or you could play the role of lazy and use CSB.

Nub_1

eh, I'm trying to move on from CSB...
and I relieze that there's a packet buffer class

ObsidianWolf

Well I am trying to help, but how much can one help a Llama?

MyndFyre

Wolf, how long have you been on these forums?  I've only seen you the past couple days, but man! 16 posts already?!?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.