Author | Message | Time |
---|---|---|
Stealth | I went to rewrite a big chunk of StealthBot code on Friday and Saturday (parts were hideous -- I actually had two entirely separate BNCS packet handler subroutines, one for BNLS-enabled connections and one for locally-hashed ones) and I remembered a little packet debuffer class written by Sorc.Polgara. I had really liked the idea at the time, but lacked motivation to install it. This time around, however, it got done. For the benefit of others who want to use this neat little debuffer class, I'm going to post my modified version of Sorc's class. There were some problems with Sorc's class; namely, the CopyMemory calls had some IDE-crashing issues, and some stuff was being done with too much complexity, which is fixed. I also added some bounds-checking code to it, which can never hurt. Here's the result. Enjoy, and feel free to comment. [code]'================================================= '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 '================================================= 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 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 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 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 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) 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 =) '======================================================= [/code] | March 7, 2005, 5:56 AM |
bethra | lmao, I totally forgot about this class I wrote! Lost it when my harddrive screwed up! kekekeke | March 8, 2005, 3:53 PM |
QwertyMonster | Sorc.Polgara is happy! :o Stealth; It all seems good peice of coding! :) And its good you have put who its by, and you thank them ect.. Now people cant come and say "Code Stealer", like most newbs would do ** No Names Mentioned ** ::) :P | March 8, 2005, 3:56 PM |
Ban | Very nice work | March 8, 2005, 4:04 PM |
bethra | [quote author=QwertyMonster link=topic=10844.msg102846#msg102846 date=1110297383] Stealth; It all seems good peice of coding! :) And its good you have put who its by, and you thank them ect.. Now people cant come and say "Code Stealer", like most newbs would do ** No Names Mentioned ** ::) :P [/quote] Yeah that is the right way of doing things. The GM (Good mannar) way. keke, it is also nice to know that Stealth is using my class for his well known bot =) I use SB heh atm, while I program mine. kekeke | March 10, 2005, 2:02 PM |
QwertyMonster | [quote author=Sorc.Polgara link=topic=10844.msg103171#msg103171 date=1110463373] [quote author=QwertyMonster link=topic=10844.msg102846#msg102846 date=1110297383] Stealth; It all seems good peice of coding! :) And its good you have put who its by, and you thank them ect.. Now people cant come and say "Code Stealer", like most newbs would do ** No Names Mentioned ** ::) :P [/quote] Yeah that is the right way of doing things. The GM (Good mannar) way. keke, it is also nice to know that Stealth is using my class for his well known bot =) I use SB heh atm, while I program mine. kekeke [/quote] You will only get accused of "stealing code" if you just take it without the authors permission, or without naming whos it by or anything. Doing this is extremely lame, and it takes the fun out of programming :-\ | March 10, 2005, 3:29 PM |
Mephisto | Too bad it was coded in VB... | March 10, 2005, 7:59 PM |
UserLoser. | [quote author=Mephisto link=topic=10844.msg103218#msg103218 date=1110484759] Too bad it was coded in VB... [/quote] ...otherwise you'd copy it? :P | March 10, 2005, 8:29 PM |
Mephisto | [quote author=UserLoser link=topic=10844.msg103224#msg103224 date=1110486596] [quote author=Mephisto link=topic=10844.msg103218#msg103218 date=1110484759] Too bad it was coded in VB... [/quote] ...otherwise you'd copy it? :P [/quote] Why would you say/think that? | March 10, 2005, 11:39 PM |
UserLoser. | [quote author=Mephisto link=topic=10844.msg103237#msg103237 date=1110497985] [quote author=UserLoser link=topic=10844.msg103224#msg103224 date=1110486596] [quote author=Mephisto link=topic=10844.msg103218#msg103218 date=1110484759] Too bad it was coded in VB... [/quote] ...otherwise you'd copy it? :P [/quote] Why would you say/think that? [/quote] You took this the wrong way. But anyways, because I know you don't code in VB and you said what you said with a trailing "..." meaning there's probably more to what you said ;) | March 10, 2005, 11:49 PM |
Quarantine | <attempt to put us back on topic> Good job Stealth </attempt to put us back on topic> | March 11, 2005, 8:27 PM |
QwertyMonster | [quote author=Warrior link=topic=10844.msg103362#msg103362 date=1110572877] <attempt to put us back on topic> Good job Stealth </attempt to put us back on topic> [/quote] Attempt worked. Nice stealth. 8) | March 12, 2005, 5:50 PM |
Zakath | Booo! Down with debuffering class! Gogo pointer typecasting! :P | March 12, 2005, 11:04 PM |