'================================================= 'PacketDebuffer Class 'By Bethra, aka. Sorc.Polgara =) '================================================= 'Modified/Fixed March 4-5, 2005 ' by Andy T, aka Stealth ' stealth@stealthbot.net ' ' Changes: ' - Added bounds checking code ' - Removed unnecessary CopyMemory calls ' - Fixed existing CopyMemory calls ' - Added Advance(), DebuffRaw() and HasBytes() ' functions '================================================= 'Modified February 11, 2008 ' by Ben, aka Victim ' victim@forbiddenlegacy.com ' Changes: ' - Added DebuffPacketID(), DebuffMCPPacketID() - I'm a lazy bastard ' - Edited GetFILETIME() ' - Added DebuffLength() '================================================= 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) 'Uncomment these lines if you don't already have FILETIME declared 'IIRC, vb won't like this inside a class module, so move it into a module 'Private Type FILETIME ' dwLowDateTime As Long ' dwHighDateTime As Long 'End Type Private DeBuffer As String '// Debuffering string 'Returns the Debuffer string's length '(Added by Victim) Public Function DebuffLength() As Long DebuffLength = Len(DeBuffer) End Function 'Sets the Debuffer string Public Function DebuffPacket(PacketData As String) DeBuffer = PacketData End Function 'Resets/clears the Debuffer Public Function Clear() DeBuffer = vbNullString End Function '======================================================= '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 a BNCS packet id '(I really don't give a shit about the echo'd packet length, 'so I just remove the whole BNCS header in the process) '(Added by Victim) Public Function DebuffPacketID() As Byte If HasBytes(4) Then DebuffPacketID = GetPacketID RemovePacketID End If End Function 'Debuffers a Master Control Program packet id '(Again removed the whole header...) '(Added by Victim) Public Function DebuffMCPPacketID() As Byte If HasBytes(3) Then DebuffMCPPacketID = GetMCPPacketID RemoveMCPPacketID 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 a BNCS packet id from the Debuffer Public Sub RemovePacketID() DeBuffer = Mid$(DeBuffer, 5) End Sub 'Removes an MCP packet id from the Debuffer Public Sub RemoveMCPPacketID() DeBuffer = Mid$(DeBuffer, 4) 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 Call 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 '(Edited by Victim: For purposes of my own bot, I put it in the format that 0x26 'sends so I can use a universal function for FILETIME structure) Function GetFILETIME() As String Dim FT As FileTime Dim sTemp As String * 8 sTemp = Mid$(DeBuffer, 1, 8) CopyMemory FT, ByVal sTemp, 8 GetFILETIME = FT.dwHighDateTime & Space$(1) & FT.dwLowDateTime 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) NTString = Mid$(DeBuffer, 1, pos - 1) GetNTString = NTString End Function Function GetPacketID() As Byte Dim PBYTE As Byte PBYTE = Asc(Mid$(DeBuffer, 2, 1)) GetPacketID = PBYTE End Function Function GetMCPPacketID() As Byte Dim PBYTE As Byte PBYTE = Asc(Mid$(DeBuffer, 3, 1)) GetMCPPacketID = PBYTE 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 =) '=======================================================