-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsPacketDebuffer.cls
218 lines (181 loc) · 5.95 KB
/
clsPacketDebuffer.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsPacketDebuffer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'=================================================
'PacketDebuffer Class
'By Bethra, aka. Sorc.Polgara =)
'=================================================
'Modified/Fixed March 4-5, 2005
' by Andy T, aka Stealth
'
' Changes:
' - Added bounds checking code
' - Removed unnecessary CopyMemory calls
' - Fixed existing CopyMemory calls
' - Added Advance(), DebuffRaw() and HasBytes()
' functions
'=================================================
Option Explicit
' Uncomment this line if you don't already have CopyMemory declared
'Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByVal Source As Any, ByVal numBytes As Long)
Public Debuffer As String '// Debuffering string
'Sets the Debuffer string
Public Sub DebuffPacket(PacketData As String)
Debuffer = PacketData
End Sub
'Resets/clears the Debuffer
Public Sub Clear()
Debuffer = vbNullString
End Sub
'=======================================================
'Public Functions that debuffer a part from the Debuffer
'=======================================================
'Debuffers a DWORD from the Debuffer
Public Function DebuffDWORD() As Long
If HasBytes(4) Then
DebuffDWORD = GetDWORD
RemoveDWORD
End If
End Function
'Debuffers a WORD from the Debuffer
Public Function DebuffWORD() As Integer
If HasBytes(2) Then
DebuffWORD = GetWORD
RemoveWORD
End If
End Function
'Debuffers a BYTE from the Debuffer
Public Function DebuffBYTE() As Byte
If HasBytes(1) Then
DebuffBYTE = GetBYTE
RemoveBYTE
End If
End Function
'Debuffers a FILETIME from the Debuffer
' Edit by Andy: Returns the 8 bytes of the FILETIME struct
' The end-location will have to typecast this via CopyMemory into a FILETIME
' VB didn't like using a user-defined type as a return type or parameter type
' in a public class object
Public Function DebuffFILETIME() As String
If HasBytes(8) Then
DebuffFILETIME = GetFILETIME
RemoveFILETIME
End If
End Function
'Debuffers a null-terminating string from the Debuffer
Public Function DebuffNTString() As String
If HasBytes(1) Then
DebuffNTString = GetNTString
RemoveNTString
Else
DebuffNTString = ""
End If
End Function
'Debuffers x bytes -- for those times when you want it straight-up
'(added by Andy)
Public Function DebuffRaw(ByVal nBytes As Long) As String
If HasBytes(nBytes) Then
DebuffRaw = Mid$(Debuffer, 1, nBytes)
Call Advance(nBytes)
End If
End Function
'=====================================================
'Public Functions that remove a part from the Debuffer
'=====================================================
'Removes a BYTE from the Debuffer
Public Sub RemoveBYTE()
Debuffer = Mid$(Debuffer, 2)
End Sub
'Removes a WORD from the Debuffer
Public Sub RemoveWORD()
Debuffer = Mid$(Debuffer, 3)
End Sub
'Removes a DWORD from the Debuffer
Public Sub RemoveDWORD()
Debuffer = Mid$(Debuffer, 5)
End Sub
'Removes a FILETIME structure from the Debuffer
Public Sub RemoveFILETIME()
Debuffer = Mid$(Debuffer, 9)
End Sub
'Removes a null-terminating string from the Debuffer
Public Sub RemoveNTString()
Dim Pos As Integer
Pos = InStr(1, Debuffer, Chr(0), vbBinaryCompare)
If Len(Debuffer) > Pos Then
Debuffer = Mid$(Debuffer, Pos + 1)
Else
Call Clear
End If
End Sub
'Removes nBytes bytes from the buffer
' For those times when you just don't care what's there..
'(added by Andy)
Public Sub Advance(ByVal nBytes As Long)
If Len(Debuffer) > nBytes Then
Debuffer = Mid$(Debuffer, nBytes + 1)
Else
Clear
End If
End Sub
'=======================================================
'Functions that get parts from the front of the Debuffer
'=======================================================
'Gets a BYTE from the Debuffer
Function GetBYTE() As Byte
Dim PBYTE As Byte
PBYTE = Asc(Mid$(Debuffer, 1, 1))
GetBYTE = PBYTE
End Function
'Gets a WORD from the Debuffer
Function GetWORD() As Integer
Dim WORD As Integer
Dim sTemp As String * 2
sTemp = Mid$(Debuffer, 1, 2)
CopyMemory WORD, ByVal sTemp, 2
GetWORD = WORD
End Function
'Gets a DWORD from the Debuffer
Function GetDWORD() As Long
Dim DWORD As Long
Dim sTemp As String * 4
sTemp = Mid$(Debuffer, 1, 4)
CopyMemory DWORD, ByVal sTemp, 4
GetDWORD = DWORD
End Function
'Gets a FILETIME from the Debuffer
Function GetFILETIME() As String
GetFILETIME = Mid$(Debuffer, 1, 8)
End Function
'Gets a null-terminating string from the Debuffer
Function GetNTString() As String
Dim NTString As String
Dim Pos As Integer
Pos = InStr(1, Debuffer, Chr(0), vbBinaryCompare)
If Pos > 0 Then NTString = Mid$(Debuffer, 1, Pos - 1)
GetNTString = NTString
End Function
'Returns TRUE if the debuffer has >= X bytes in it, else FALSE
'(added by Andy)
Function HasBytes(ByVal x As Integer) As Boolean
HasBytes = (Len(Debuffer) >= x)
End Function
' (Sorc.Polgara's)
'=====================Credits============================
'DarkMinion for using his PacketBuffer class as a guide,
'this is the first class I have ever made =)
'-----------------
'Bot Developement Forum members who helped me understand
'some stuff that I need to know inorder to make this =)
'=======================================================