3
3652595
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟我写个QQ协议的,这里有个VB的挂机源代码。UDP的,但是VB看不懂,请大虾把主要的转换一下delphi的,最好用UdpSocket等写个例子。希望大虾帮帮小弟。
Attribute VB_Name = "OutPacket"
'头部:
'0 = 0x02
'1-2 = 客户端版本号码
'3-4 = 命令类型
'5-6 = 包序号 * <li>包序号, 0x05~0x06.
'7-10 = 用户 QQ 号 * <li>用户QQ号, 0x07~0x0A
'
'尾部: 0x03
Option Explicit
Public Function LoginToken(ByVal QQNum As Long) As Byte()
On Error Resume Next
Dim Packet(12) As Byte
Dim QQBuff(3) As Byte
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H62
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
Packet(11) = &H0 '请求登陆令牌
Packet(12) = &H3 '结尾
LoginToken = Packet
End Function
Public Function LoginPacket(ByVal QQNum As Long, ByVal QQHide As Boolean, LoginKey() As Byte, PasswordKey() As Byte, LoginToken() As Byte) As Byte()
On Error Resume Next
Dim Packet(459) As Byte, Plain(415) As Byte, Crypt() As Byte, QQBuff(3) As Byte, PasswordEncode() As Byte, Free() As Byte
Dim Tea As New clsTea
If UBound(LoginKey) <> 15 Then Exit Function
If UBound(PasswordKey) <> 15 Then Exit Function
If UBound(LoginToken) <> 23 Then Exit Function
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H22
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
'初始密钥
CopyMemory Packet(11), LoginKey(0), 16
'密码密钥
PasswordEncode = Tea.Encrypt(Free, PasswordKey)
CopyMemory Plain(0), PasswordEncode(0), 16
'固定字节
Plain(35) = &H13: Plain(36) = &HF1: Plain(37) = &HCD: Plain(38) = &H6E: Plain(39) = &H3
Plain(40) = &H1F: Plain(41) = &H2D: Plain(42) = &H73: Plain(43) = &H5E: Plain(44) = &HCD
Plain(45) = &H33: Plain(46) = &HDB: Plain(47) = &H5F: Plain(48) = &HD0: Plain(49) = &HC5
Plain(50) = &HB: Plain(51) = &H1
'状态: 在线/隐身
If QQHide = True Then Plain(52) = &H28 Else Plain(52) = &HA
'固定字节
Plain(53) = &HDF: Plain(54) = &HB2: Plain(55) = &H81: Plain(56) = &HD3: Plain(57) = &HF2
Plain(58) = &HA0: Plain(59) = &H32: Plain(60) = &H46: Plain(61) = &H93: Plain(62) = &HEE
Plain(63) = &H6: Plain(64) = &HB8: Plain(65) = &H50: Plain(66) = &H2B: Plain(67) = &HC9
Plain(68) = &HFE: Plain(69) = &H18
'登陆令牌
CopyMemory Plain(70), LoginToken(0), 24
'固定字节
Plain(94) = &H1: Plain(95) = &H40
'加密数据包
Crypt = Tea.Encrypt(Plain, LoginKey)
CopyMemory Packet(27), Crypt(0), 432
'包尾
Packet(459) = &H3
LoginPacket = Packet
End Function
Public Function SendIMPacket(ByVal FromQQNum As Long, ByVal ToQQNum As Long, SessionKey() As Byte, ByVal NowTime As Long, ByVal StrSend As String) As Byte()
On Error Resume Next
Dim Packet() As Byte, Plain() As Byte, Crypt() As Byte, QQBuff(3) As Byte, ToQQBuff(3) As Byte
Dim b(19) As Byte, c() As Byte
Dim Tea As New clsTea, MD5 As New clsMD5
Dim TickCount As Long, TickCountBuff(3) As Byte
Dim I As Long, bit As Integer, bytesCount As Long
Dim SendBuff() As Byte
If UBound(SessionKey) <> 15 Then Exit Function
TickCount = NowTime
CopyMemory QQBuff(0), FromQQNum, 4
CopyMemory ToQQBuff(0), ToQQNum, 4
CopyMemory TickCountBuff(0), TickCount, 4
ReDim Packet(10) As Byte
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H16
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
bytesCount = -1
For I = 1 To Len(StrSend)
bit = Asc(Mid(StrSend, I, 1))
If bit > -1 And bit < 256 Then
bytesCount = bytesCount + 1
ReDim Preserve SendBuff(bytesCount) As Byte
SendBuff(bytesCount) = CByte(bit)
Else
bytesCount = bytesCount + 2
ReDim Preserve SendBuff(bytesCount) As Byte
SendBuff(bytesCount - 1) = HiByte(bit)
SendBuff(bytesCount) = LowByte(bit)
End If
Next I
ReDim Plain(67 + bytesCount) As Byte
Plain(0) = QQBuff(3)
Plain(1) = QQBuff(2)
Plain(2) = QQBuff(1)
Plain(3) = QQBuff(0)
Plain(4) = ToQQBuff(3)
Plain(5) = ToQQBuff(2)
Plain(6) = ToQQBuff(1)
Plain(7) = ToQQBuff(0)
Plain(8) = &HD
Plain(9) = &H51
Plain(10) = QQBuff(3)
Plain(11) = QQBuff(2)
Plain(12) = QQBuff(1)
Plain(13) = QQBuff(0)
Plain(14) = ToQQBuff(3)
Plain(15) = ToQQBuff(2)
Plain(16) = ToQQBuff(1)
Plain(17) = ToQQBuff(0)
'18 - 33 MD5
b(0) = QQBuff(3)
b(1) = QQBuff(2)
b(2) = QQBuff(1)
b(3) = QQBuff(0)
CopyMemory b(4), SessionKey(0), 16
c = MD5.DigestBAryToArray(b)
CopyMemory Plain(18), c(0), 16
Plain(34) = 0
Plain(35) = 11
Plain(36) = Int(Rnd * 256)
Plain(37) = Int(Rnd * 256)
Plain(38) = TickCountBuff(3)
Plain(39) = TickCountBuff(2)
Plain(40) = TickCountBuff(1)
Plain(41) = TickCountBuff(0)
Plain(42) = 0
Plain(43) = 0
Plain(44) = 0
Plain(45) = 0
Plain(46) = 0
Plain(47) = 1
Plain(48) = 1
Plain(49) = 0
Plain(50) = Int(Rnd * 256)
Plain(51) = Int(Rnd * 256)
Plain(52) = 2
CopyMemory Plain(53), SendBuff(0), UBound(SendBuff) + 1
Plain(UBound(Plain) - 13) = 32
Plain(UBound(Plain) - 12) = 0
Plain(UBound(Plain) - 11) = 9
Plain(UBound(Plain) - 10) = frmMain.hsRed.value
Plain(UBound(Plain) - 9) = frmMain.hsGreen.value
Plain(UBound(Plain) - 8) = frmMain.hsBlue.value
Plain(UBound(Plain) - 7) = 0
Plain(UBound(Plain) - 6) = 134
Plain(UBound(Plain) - 5) = 0
Plain(UBound(Plain) - 4) = &HCB
Plain(UBound(Plain) - 3) = &HCE
Plain(UBound(Plain) - 2) = &HCC
Plain(UBound(Plain) - 1) = &HE5
Plain(UBound(Plain)) = 13
Crypt = Tea.Encrypt(Plain, SessionKey)
ReDim Preserve Packet(12 + UBound(Crypt))
CopyMemory Packet(11), Crypt(0), UBound(Crypt) + 1
Packet(UBound(Packet)) = 3
SendIMPacket = Packet
End Function
Public Function KeepAlivePacket(ByVal QQNum As Long, SessionKey() As Byte) As Byte()
On Error Resume Next
Dim QQBuff() As Byte, Crypt() As Byte
Dim Packet() As Byte
Dim I As Long
Dim Tea As New clsTea
ReDim QQBuff(Len(Trim(Str(QQNum))) - 1) As Byte
For I = 1 To Len(Trim(Str(QQNum)))
QQBuff(I - 1) = Asc(Mid(Trim(Str(QQNum)), I, 1))
Next I
Crypt = Tea.Encrypt(QQBuff, SessionKey)
ReDim Packet(UBound(Crypt) + 12)
ReDim QQBuff(3) As Byte
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H2
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
CopyMemory Packet(11), Crypt(0), UBound(Crypt) + 1
Packet(UBound(Packet)) = 3
KeepAlivePacket = Packet
End Function
Public Function LogoutPacket(ByVal QQNum As Long, SessionKey() As Byte, PasswordKey() As Byte) As Byte()
On Error Resume Next
Dim QQBuff(3) As Byte, Packet(43) As Byte, Crypt() As Byte
Dim Tea As New clsTea
Crypt = Tea.Encrypt(PasswordKey, SessionKey)
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H1
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
CopyMemory Packet(11), Crypt(0), 32
Packet(43) = 3
LogoutPacket = Packet
End Function
Attribute VB_Name = "OutPacket"
'头部:
'0 = 0x02
'1-2 = 客户端版本号码
'3-4 = 命令类型
'5-6 = 包序号 * <li>包序号, 0x05~0x06.
'7-10 = 用户 QQ 号 * <li>用户QQ号, 0x07~0x0A
'
'尾部: 0x03
Option Explicit
Public Function LoginToken(ByVal QQNum As Long) As Byte()
On Error Resume Next
Dim Packet(12) As Byte
Dim QQBuff(3) As Byte
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H62
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
Packet(11) = &H0 '请求登陆令牌
Packet(12) = &H3 '结尾
LoginToken = Packet
End Function
Public Function LoginPacket(ByVal QQNum As Long, ByVal QQHide As Boolean, LoginKey() As Byte, PasswordKey() As Byte, LoginToken() As Byte) As Byte()
On Error Resume Next
Dim Packet(459) As Byte, Plain(415) As Byte, Crypt() As Byte, QQBuff(3) As Byte, PasswordEncode() As Byte, Free() As Byte
Dim Tea As New clsTea
If UBound(LoginKey) <> 15 Then Exit Function
If UBound(PasswordKey) <> 15 Then Exit Function
If UBound(LoginToken) <> 23 Then Exit Function
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H22
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
'初始密钥
CopyMemory Packet(11), LoginKey(0), 16
'密码密钥
PasswordEncode = Tea.Encrypt(Free, PasswordKey)
CopyMemory Plain(0), PasswordEncode(0), 16
'固定字节
Plain(35) = &H13: Plain(36) = &HF1: Plain(37) = &HCD: Plain(38) = &H6E: Plain(39) = &H3
Plain(40) = &H1F: Plain(41) = &H2D: Plain(42) = &H73: Plain(43) = &H5E: Plain(44) = &HCD
Plain(45) = &H33: Plain(46) = &HDB: Plain(47) = &H5F: Plain(48) = &HD0: Plain(49) = &HC5
Plain(50) = &HB: Plain(51) = &H1
'状态: 在线/隐身
If QQHide = True Then Plain(52) = &H28 Else Plain(52) = &HA
'固定字节
Plain(53) = &HDF: Plain(54) = &HB2: Plain(55) = &H81: Plain(56) = &HD3: Plain(57) = &HF2
Plain(58) = &HA0: Plain(59) = &H32: Plain(60) = &H46: Plain(61) = &H93: Plain(62) = &HEE
Plain(63) = &H6: Plain(64) = &HB8: Plain(65) = &H50: Plain(66) = &H2B: Plain(67) = &HC9
Plain(68) = &HFE: Plain(69) = &H18
'登陆令牌
CopyMemory Plain(70), LoginToken(0), 24
'固定字节
Plain(94) = &H1: Plain(95) = &H40
'加密数据包
Crypt = Tea.Encrypt(Plain, LoginKey)
CopyMemory Packet(27), Crypt(0), 432
'包尾
Packet(459) = &H3
LoginPacket = Packet
End Function
Public Function SendIMPacket(ByVal FromQQNum As Long, ByVal ToQQNum As Long, SessionKey() As Byte, ByVal NowTime As Long, ByVal StrSend As String) As Byte()
On Error Resume Next
Dim Packet() As Byte, Plain() As Byte, Crypt() As Byte, QQBuff(3) As Byte, ToQQBuff(3) As Byte
Dim b(19) As Byte, c() As Byte
Dim Tea As New clsTea, MD5 As New clsMD5
Dim TickCount As Long, TickCountBuff(3) As Byte
Dim I As Long, bit As Integer, bytesCount As Long
Dim SendBuff() As Byte
If UBound(SessionKey) <> 15 Then Exit Function
TickCount = NowTime
CopyMemory QQBuff(0), FromQQNum, 4
CopyMemory ToQQBuff(0), ToQQNum, 4
CopyMemory TickCountBuff(0), TickCount, 4
ReDim Packet(10) As Byte
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H16
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
bytesCount = -1
For I = 1 To Len(StrSend)
bit = Asc(Mid(StrSend, I, 1))
If bit > -1 And bit < 256 Then
bytesCount = bytesCount + 1
ReDim Preserve SendBuff(bytesCount) As Byte
SendBuff(bytesCount) = CByte(bit)
Else
bytesCount = bytesCount + 2
ReDim Preserve SendBuff(bytesCount) As Byte
SendBuff(bytesCount - 1) = HiByte(bit)
SendBuff(bytesCount) = LowByte(bit)
End If
Next I
ReDim Plain(67 + bytesCount) As Byte
Plain(0) = QQBuff(3)
Plain(1) = QQBuff(2)
Plain(2) = QQBuff(1)
Plain(3) = QQBuff(0)
Plain(4) = ToQQBuff(3)
Plain(5) = ToQQBuff(2)
Plain(6) = ToQQBuff(1)
Plain(7) = ToQQBuff(0)
Plain(8) = &HD
Plain(9) = &H51
Plain(10) = QQBuff(3)
Plain(11) = QQBuff(2)
Plain(12) = QQBuff(1)
Plain(13) = QQBuff(0)
Plain(14) = ToQQBuff(3)
Plain(15) = ToQQBuff(2)
Plain(16) = ToQQBuff(1)
Plain(17) = ToQQBuff(0)
'18 - 33 MD5
b(0) = QQBuff(3)
b(1) = QQBuff(2)
b(2) = QQBuff(1)
b(3) = QQBuff(0)
CopyMemory b(4), SessionKey(0), 16
c = MD5.DigestBAryToArray(b)
CopyMemory Plain(18), c(0), 16
Plain(34) = 0
Plain(35) = 11
Plain(36) = Int(Rnd * 256)
Plain(37) = Int(Rnd * 256)
Plain(38) = TickCountBuff(3)
Plain(39) = TickCountBuff(2)
Plain(40) = TickCountBuff(1)
Plain(41) = TickCountBuff(0)
Plain(42) = 0
Plain(43) = 0
Plain(44) = 0
Plain(45) = 0
Plain(46) = 0
Plain(47) = 1
Plain(48) = 1
Plain(49) = 0
Plain(50) = Int(Rnd * 256)
Plain(51) = Int(Rnd * 256)
Plain(52) = 2
CopyMemory Plain(53), SendBuff(0), UBound(SendBuff) + 1
Plain(UBound(Plain) - 13) = 32
Plain(UBound(Plain) - 12) = 0
Plain(UBound(Plain) - 11) = 9
Plain(UBound(Plain) - 10) = frmMain.hsRed.value
Plain(UBound(Plain) - 9) = frmMain.hsGreen.value
Plain(UBound(Plain) - 8) = frmMain.hsBlue.value
Plain(UBound(Plain) - 7) = 0
Plain(UBound(Plain) - 6) = 134
Plain(UBound(Plain) - 5) = 0
Plain(UBound(Plain) - 4) = &HCB
Plain(UBound(Plain) - 3) = &HCE
Plain(UBound(Plain) - 2) = &HCC
Plain(UBound(Plain) - 1) = &HE5
Plain(UBound(Plain)) = 13
Crypt = Tea.Encrypt(Plain, SessionKey)
ReDim Preserve Packet(12 + UBound(Crypt))
CopyMemory Packet(11), Crypt(0), UBound(Crypt) + 1
Packet(UBound(Packet)) = 3
SendIMPacket = Packet
End Function
Public Function KeepAlivePacket(ByVal QQNum As Long, SessionKey() As Byte) As Byte()
On Error Resume Next
Dim QQBuff() As Byte, Crypt() As Byte
Dim Packet() As Byte
Dim I As Long
Dim Tea As New clsTea
ReDim QQBuff(Len(Trim(Str(QQNum))) - 1) As Byte
For I = 1 To Len(Trim(Str(QQNum)))
QQBuff(I - 1) = Asc(Mid(Trim(Str(QQNum)), I, 1))
Next I
Crypt = Tea.Encrypt(QQBuff, SessionKey)
ReDim Packet(UBound(Crypt) + 12)
ReDim QQBuff(3) As Byte
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H2
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
CopyMemory Packet(11), Crypt(0), UBound(Crypt) + 1
Packet(UBound(Packet)) = 3
KeepAlivePacket = Packet
End Function
Public Function LogoutPacket(ByVal QQNum As Long, SessionKey() As Byte, PasswordKey() As Byte) As Byte()
On Error Resume Next
Dim QQBuff(3) As Byte, Packet(43) As Byte, Crypt() As Byte
Dim Tea As New clsTea
Crypt = Tea.Encrypt(PasswordKey, SessionKey)
CopyMemory QQBuff(0), QQNum, 4
Packet(0) = &H2 '头部
Packet(1) = &HD '客户端版本号码
Packet(2) = &H51
Packet(3) = &H0 '命令类型
Packet(4) = &H1
Packet(5) = Int(Rnd * 256) '包序号
Packet(6) = Int(Rnd * 256)
Packet(7) = QQBuff(3) '用户 QQ 号
Packet(8) = QQBuff(2)
Packet(9) = QQBuff(1)
Packet(10) = QQBuff(0)
CopyMemory Packet(11), Crypt(0), 32
Packet(43) = 3
LogoutPacket = Packet
End Function