Option Explicit
'====================================
' º Name : cConcatenator.cls
' º Version : 1.0
' º Author : Psyke1
' º Twitter : @SoyAbsurdo
' º Country : Spain
' º Date : 10/10/11
' º Reference : http://goo.gl/cylbd
' º Dedicated : BlackZeroX & coco
' º Visit :
' * http://foro.h-sec.org
' * http://infrangelux.sytes.net
'====================================
Private Declare Function SysAllocStringByteLen Lib "oleaut32.dll" (ByVal oleStr As Long, ByVal BLen As Long) As Long
Private Declare Sub RtlMoveMemory Lib "ntdll.dll" (ByVal lpDestination As Long, ByVal lpSource As Long, ByVal Length As Long)
Private Const CHUNK_SIZE As Long = &H4000
Private sRetStr As String
Private lCountB As Long
Private lSize As Long
'// Add a string fastly in the buffer, you can especify the position too.
Friend Static Sub AddStr(ByRef sText As String, Optional ByVal lPosition As Long = 0)
Dim lLenB As Long
Dim lpStrPos As Long
Dim lTmpC As Long
lLenB = LenB(sText)
If lLenB Then
lTmpC = lCountB + lLenB
If lTmpC > lSize Then
Do
lSize = lSize + CHUNK_SIZE
sRetStr = sRetStr & AllocString
Loop While lTmpC > lSize
End If
If lPosition > 0 Then
lPosition = lPosition + lPosition
If lPosition <= lCountB Then
lpStrPos = StrPtr(sRetStr) + lPosition
RtlMoveMemory (lpStrPos + lLenB), lpStrPos, (lCountB - lPosition)
RtlMoveMemory lpStrPos, StrPtr(sText), lLenB
End If
Else
RtlMoveMemory (StrPtr(sRetStr) + lCountB), StrPtr(sText), lLenB
End If
lCountB = lTmpC
End If
End Sub
'// It deletes a specific part of the buffer.
Public Static Sub RemoveStr(ByVal lPosition As Long, ByVal lLength As Long)
Dim lpStrPos As Long
If lPosition > 0 Then
If lLength > 0 Then
lLength = lLength + lLength
lPosition = lPosition + lPosition
If lPosition + lLength <= lCountB Then
lCountB = lCountB - lLength
lpStrPos = StrPtr(sRetStr) + lPosition
RtlMoveMemory lpStrPos, (lpStrPos + lLength), lCountB
ElseIf (lPosition = 2) And (lLength = lCountB) Then
ResetAll
End If
End If
End If
End Sub
'// Reset all values.
Friend Sub ResetAll()
lCountB = 0
lSize = CHUNK_SIZE
sRetStr = AllocString
End Sub
Private Function AllocString() As String
RtlMoveMemory VarPtr(AllocString), VarPtr(SysAllocStringByteLen(0&, CHUNK_SIZE)), 4&
End Function
'// Get the string of the buffer.
Friend Property Get GetString() As String
If lCountB Then
GetString = LeftB$(sRetStr, lCountB)
End If
End Property
'// Return the length in Bytes.
Friend Static Property Get LengthB() As Long
LengthB = lCountB
End Property
'// Return the length.
Friend Static Property Get Length() As Long
Length = lCountB \ 2
End Property
'// Return the size of the buffer in bytes.
Friend Static Property Get CapacityB() As Long
CapacityB = lSize
End Property
'// Return the size of the buffer.
Friend Static Property Get Capacity() As Long
Capacity = lSize \ 2
End Property
Private Sub Class_Initialize()
ResetAll
End Sub