• Welcome to Valhalla Legends Archive.
 

packet display function

Started by Camel, June 25, 2003, 03:30 PM

Previous topic - Next topic

Camel

I wrote this little function in vb to aid debugging of packets

Quote[16:25:23] SEND 0x50
(DWORD) 0x00000000
(DWORD) IX86
(DWORD) W2BN
(DWORD) 0x0000004F
(DWORD) 0x00000000
(DWORD) 0x00000583
(DWORD) 0x0000012C
(DWORD) 0x00000409
(DWORD) 0x00000409
(NTString) USA
(NTString) United States

The function as is should be called without the packet header. To call it with the packet header, change Spot=1 to Spot=5.

Public Enum fTypes
   fDWORD
   fDWORDStr
   fNTString
   fHash
End Enum

Public Function FormatPacketDisplay(str As String, ParamArray Format()) As String
   Dim T
   Dim Spot As Long
   Spot = 1
   For Each T In Format
       Select Case CLng(T)
           Case fTypes.fDWORD
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & "(DWORD) 0x" & Zero(Hex(CVL(Mid(str, Spot, 4))), 8)
               Spot = Spot + 4
           Case fTypes.fDWORDStr
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & "(DWORD) " & StrReverse(Mid(str, Spot, 4))
               Spot = Spot + 4
           Case fTypes.fNTString
               Dim X As Long
               X = InStr(Spot, str, Chr(0))
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & "(NTString) " & Mid(str, Spot, X - Spot)
               Spot = X + 1
           Case fTypes.fHash
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & "(HASH) " & HexDump(Mid(str, Spot, 20), "")
               Spot = Spot + 20
           Case Else
               Debug.Assert False
       End Select
   Next
End Function


Case &H50: Format = FormatPacketDisplay(Data, fDWORD, fDWORDStr, fDWORDStr, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fNTString, fNTString)
Case &H51: Format = FormatPacketDisplay(Data, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fDWORD, fhash, fNTString, fNTString)
...


comments/suggestions welcome :)

[edit] added StrReverse for fDWORDStr

Yoni

+1 to Camel.

Suggestion: Add some more types (WORD, BYTE seem missing... FILETIME might be useful too).

Camel

Ah yes; right now, I've only got it set up for the first five or six outgoing packets. I will add those, Yoni.

Grok

Nice Camel.  Although I am sad to see yet another same-looking user interface.  Where has creativity gone?  Chat box, userlist, text input.  All so boring.

Camel

Quote from: Grok on June 26, 2003, 03:11 PMWhere has creativity gone?
My bot was unorigional long before any of yours were. =P
And its primary function is to hold ops, so i dont really care. :)

anyways, here's some updated code
i still have yet to do realm packets

Option Explicit

Public Enum fTypes
   fByte
   fWord
   fDWord
   fDWordStr
   fNTString
   fMultiNTString
   fHash
   fFileTime
End Enum

Public Function FormatPacketDisplay(str As String, ParamArray Format()) As String
   Dim t
   Dim Spot As Long, X As Long
   Spot = 1
   For Each t In Format
       Select Case CLng(t)
           Case fTypes.fByte
               X = Asc(Mid(str, Spot, 1))
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(BYTE) 0x" & Zero(Hex(X), 2) & " (" & X & ")"
               Spot = Spot + 1
           Case fTypes.fWord
               X = CVI(Mid(str, Spot, 2))
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(DWORD) 0x" & Zero(Hex(X), 4) & " (" & X & ")"
               Spot = Spot + 2
           Case fTypes.fDWord
               X = CVL(Mid(str, Spot, 4))
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(DWORD) 0x" & Zero(Hex(X), 8) & " (" & X & ")"
               Spot = Spot + 4
           Case fTypes.fDWordStr
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(DWORD) " & StrReverse(Mid(str, Spot, 4))
               Spot = Spot + 4
           
           Case fTypes.fNTString
               X = InStr(Spot, str, Chr(0))
               If X = 0 Then Debug.Assert False 'it didn't find a null!
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(NTString) " & Mid(str, Spot, X - Spot)
               Spot = X + 1
           Case fTypes.fMultiNTString
               X = InStr(Spot, str, Chr(0))
               While X > 0
                   FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                       "(NTString) " & Mid(str, Spot, X - Spot)
                   Spot = X + 1
                   X = InStr(Spot, str, Chr(0))
               Wend
           
           Case fTypes.fHash
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(HASH) " & HexDump(Mid(str, Spot, 20), "")
               Spot = Spot + 20
           Case fTypes.fFileTime
               FormatPacketDisplay = FormatPacketDisplay & vbCrLf & _
                   "(FileTime) " & FTtoDate(Mid(str, Spot, 8))
               Spot = Spot + 8
           Case Else
               Debug.Assert False
       End Select
   Next
End Function


outgoing packets
                   Case &H0: Format = FormatPacketDisplay(Data) 'nothing to see here!
                   Case &HA: Format = FormatPacketDisplay(Data, fNTString, fNTString)
                   Case &HC: Format = FormatPacketDisplay(Data, fDWord, fNTString)
                   Case &HE: Format = FormatPacketDisplay(Data, fNTString)
                   Case &H14: Format = FormatPacketDisplay(Data, fDWordStr)
                   Case &H25: Format = FormatPacketDisplay(Data, fDWord)
                   Case &H26: Format = FormatPacketDisplay(Data, fDWord, fDWord, fDWord, fMultiNTString)
                   Case &H27: Format = FormatPacketDisplay(Data, fDWord, fDWord, fMultiNTString)
                   Case &H29: Format = FormatPacketDisplay(Data, fDWord, fDWord, fHash, fNTString)
                   Case &H2E: Format = FormatPacketDisplay(Data, fDWordStr, fDWord, fDWord, fDWord, fDWord)
                   Case &H46: Format = FormatPacketDisplay(Data, fDWord)
                   Case &H50: Format = FormatPacketDisplay(Data, fDWord, fDWordStr, fDWordStr, fDWord, fDWord, fDWord, fDWord, fDWord, fDWord, fNTString, fNTString)
                   Case &H51: Format = FormatPacketDisplay(Data, fDWord, fDWord, fDWord, fDWord, fDWord, fDWord, fDWord, fDWord, fDWord, fHash, fNTString, fNTString)


incoming packets:
                   Case &H0: Format = FormatPacketDisplay(Format) 'nothing! :)
                   Case &HA: Format = FormatPacketDisplay(Format, fNTString, fNTString, fNTString)
                   Case &HF: Format = FormatPacketDisplay(Format, fDWord, fDWord, fDWord, fDWord, fDWord, fDWord, fNTString, fNTString)
                   Case &H25: Format = FormatPacketDisplay(Format, fDWord)
                   Case &H26: Format = FormatPacketDisplay(Format, fDWord, fDWord, fDWord, fMultiNTString)
                   Case &H29: Format = FormatPacketDisplay(Format, fDWord)
                   Case &H2E: Format = FormatPacketDisplay(Format, fDWordStr) 'there is WAAAAAAY more, too much to display it all
                   Case &H46: Format = FormatPacketDisplay(Format, fByte, fDWord, fDWord, fDWord, fDWord, fNTString)
                   Case &H50: Format = FormatPacketDisplay(Format, fDWord, fDWord, fDWord, fDWord, fDWord, fNTString, fNTString)
                   Case &H51: Format = FormatPacketDisplay(Format, fDWord, fNTString)

Skywing

If it's primarily an op bot, why are you making a GUI that will only slow it down?

Camel

Quote from: Skywing on June 27, 2003, 07:00 PM
If it's primarily an op bot, why are you making a GUI that will only slow it down?

#If DEBUG_ Then
...
#End If

VB isn't that ghetto...yet. :)