Funcion AddBytes
Publicado: 25 Feb 2014, 17:50
Hola, Bueno como muchos sabéis hace ya mucho que no programo malware ni nada relacionado. (quizás vuelve algún día) aqui les traigo esta funcion que arme hace mucho cuando necesitaba agregar bytes a un Array pasandole cadenas, longs, bytes o arrays.
Saludos
Private Sub AddBytes(ByRef bArray() As Byte, Data As Variant)
Dim ArraySize As Long
Dim iType As Integer
Dim SizeData As Integer
Dim StrBytes() As Byte
If ((Not bArray) = -1) Then
ArraySize = 0
Else
ArraySize = UBound(bArray()) + 1
End If
iType = VarType(Data)
Select Case iType
Case Is = vbByte, vbInteger
SizeData = 1
ReDim Preserve bArray((ArraySize + SizeData) - 1)
CopyMemory bArray(ArraySize), CByte(Data), SizeData
Exit Sub
Case Is = vbLong
SizeData = 4
ReDim Preserve bArray((ArraySize + SizeData) - 1)
CopyMemory bArray(ArraySize), CLng(Data), SizeData
Exit Sub
Case Is = 8209
StrBytes() = Data
SizeData = UBound(StrBytes()) + 1
ReDim Preserve bArray((ArraySize + SizeData) - 1)
CopyMemory bArray(ArraySize), StrBytes(0), SizeData
Exit Sub
Case Is = vbString
StrBytes() = StrConv(CStr(Data), vbFromUnicode)
SizeData = UBound(StrBytes()) + 1
ReDim Preserve bArray((ArraySize + SizeData) - 1)
CopyMemory bArray(ArraySize), StrBytes(0), SizeData
Exit Sub
Case Else
Exit Sub
End Select
End Sub
Saludos