Commit a85d3a62 authored by Him188's avatar Him188

Use receivers

parent 56f1c9a6
......@@ -24,6 +24,10 @@
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
......
......@@ -112,11 +112,11 @@ fun DataOutputStream.encryptAndWrite(byteArray: ByteArray, key: ByteArray) {
this.write(TEA.encrypt(byteArray, key))
}
fun DataOutputStream.encryptAndWrite(key: ByteArray, encoder: (ByteArrayDataOutputStream) -> Unit) {
fun DataOutputStream.encryptAndWrite(key: ByteArray, encoder: ByteArrayDataOutputStream.() -> Unit) {
this.write(TEA.encrypt(ByteArrayDataOutputStream().also(encoder).toByteArray(), key))
}
fun DataOutputStream.encryptAndWrite(keyHex: String, encoder: (ByteArrayDataOutputStream) -> Unit) {
fun DataOutputStream.encryptAndWrite(keyHex: String, encoder: ByteArrayDataOutputStream.() -> Unit) {
this.encryptAndWrite(keyHex.hexToBytes(), encoder)
}
......@@ -126,21 +126,21 @@ fun DataOutputStream.writeTLV0006(qq: Long, password: String, loginTime: Int, lo
val secondMD5 = md5(firstMD5 + "00 00 00 00".hexToBytes() + qq.toUInt().toByteArray())
this.encryptAndWrite(secondMD5) {
it.writeRandom(4)
it.writeHex("00 02")
it.writeQQ(qq)
it.writeHex(TIMProtocol.constantData2)
it.writeHex("00 00 01")
it.write(firstMD5)
it.writeInt(loginTime)
it.writeByte(0)
it.writeZero(4 * 3)
it.writeIP(loginIP)
it.writeZero(8)
it.writeHex("00 10")//这两个hex是passwordSubmissionTLV2的末尾
it.writeHex("15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B")//16
it.write(privateKey)
writeRandom(4)
writeHex("00 02")
writeQQ(qq)
writeHex(TIMProtocol.constantData2)
writeHex("00 00 01")
write(firstMD5)
writeInt(loginTime)
writeByte(0)
writeZero(4 * 3)
writeIP(loginIP)
writeZero(8)
writeHex("00 10")//这两个hex是passwordSubmissionTLV2的末尾
writeHex("15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B")//16
write(privateKey)
}
}
......
......@@ -21,9 +21,9 @@ class ClientAccountInfoRequestPacket(
this.writeQQ(qq)
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.writeByte(0x88)
it.writeQQ(qq)
it.writeByte(0x00)
writeByte(0x88)
writeQQ(qq)
writeByte(0x00)
}
}
}
......
......@@ -19,7 +19,7 @@ class ClientHeartbeatPacket(
this.writeQQ(qq)
this.writeHex(TIMProtocol.fixVer)
this.encryptAndWrite(sessionKey) {
it.writeHex("00 01 00 01")
writeHex("00 01 00 01")
}
}
}
......
......@@ -364,7 +364,7 @@ class ClientEventResponsePacket(
this.writeQQ(qq)
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.write(eventIdentity)
write(eventIdentity)
}
}
......
......@@ -32,7 +32,7 @@ class ClientCanAddFriendPacket(
this.writeQQ(bot)
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.writeQQ(qq)
writeQQ(qq)
}
}
}
......@@ -96,8 +96,8 @@ class ClientAddFriendPacket(
this.writeQQ(bot)
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.writeHex("01 00 01")
it.writeQQ(qq)
writeHex("01 00 01")
writeQQ(qq)
}
}
......
......@@ -23,24 +23,24 @@ class ClientSendFriendMessagePacket(
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.writeQQ(botQQ)
it.writeQQ(targetQQ)
it.writeHex("00 00 00 08 00 01 00 04 00 00 00 00")
it.writeHex("37 0F")
it.writeQQ(botQQ)
it.writeQQ(targetQQ)
it.write(md5(lazyEncode { md5Key -> md5Key.writeQQ(targetQQ); md5Key.write(sessionKey) }))
it.writeHex("00 0B")
it.writeRandom(2)
it.writeTime()
it.writeHex("00 00 00 00 00 00 01 00 00 00 01 4D 53 47 00 00 00 00 00")
it.writeTime()
it.writeRandom(4)
it.writeHex("00 00 00 00 09 00 86")
it.writeHex(TIMProtocol.messageConst1)//... 85 E9 BB 91
it.writeZero(2)
writeQQ(botQQ)
writeQQ(targetQQ)
writeHex("00 00 00 08 00 01 00 04 00 00 00 00")
writeHex("37 0F")
writeQQ(botQQ)
writeQQ(targetQQ)
write(md5(lazyEncode { md5Key -> md5Key.writeQQ(targetQQ); md5Key.write(sessionKey) }))
writeHex("00 0B")
writeRandom(2)
writeTime()
writeHex("00 00 00 00 00 00 01 00 00 00 01 4D 53 47 00 00 00 00 00")
writeTime()
writeRandom(4)
writeHex("00 00 00 00 09 00 86")
writeHex(TIMProtocol.messageConst1)//... 85 E9 BB 91
writeZero(2)
it.write(message.toByteArray())
write(message.toByteArray())
/*
//Plain text
......
......@@ -24,10 +24,10 @@ class ClientSendGroupMessagePacket(
this.encryptAndWrite(sessionKey) {
val bytes = message.toByteArray()
it.writeByte(0x2A)
it.writeGroup(groupId)
writeByte(0x2A)
writeGroup(groupId)
it.writeLVByteArray(lazyEncode { child ->
writeLVByteArray(lazyEncode { child ->
child.writeHex("00 01 01")
child.writeHex("00 00 00 00 00 00 00 4D 53 47 00 00 00 00 00")
......@@ -46,7 +46,7 @@ class ClientSendGroupMessagePacket(
it.writeShort(bytes.size)
it.write(bytes)*/
println(it.toByteArray().toUHexString())
println(toByteArray().toUHexString())
}
}
}
......
......@@ -31,60 +31,60 @@ class ClientTryGetImageIDPacket(
val byteArray = image.toByteArray()
this.encryptAndWrite(sessionKey) {
it.writeZero(3)
writeZero(3)
it.writeHex("07 00")
writeHex("07 00")
it.writeZero(2)
writeZero(2)
it.writeHex("5E")
it.writeHex("08")
it.writeHex("01 12 03 98 01 01 10 01")
writeHex("5E")
writeHex("08")
writeHex("01 12 03 98 01 01 10 01")
it.writeHex("1A")
it.writeHex("5A")
writeHex("1A")
writeHex("5A")
it.writeHex("08")
it.writeUVarInt(groupNumberOrQQNumber)
writeHex("08")
writeUVarInt(groupNumberOrQQNumber)
it.writeHex("10")
it.writeUVarInt(botNumber)
writeHex("10")
writeUVarInt(botNumber)
it.writeHex("18 00")
writeHex("18 00")
it.writeHex("22")
it.writeHex("10")
it.write(md5(byteArray))
writeHex("22")
writeHex("10")
write(md5(byteArray))
it.writeHex("28")
it.writeUVarInt(byteArray.size.toUInt())
writeHex("28")
writeUVarInt(byteArray.size.toUInt())
it.writeHex("32")
it.writeHex("1A")
it.writeHex("37 00 4D 00 32 00 25 00 4C 00 31 00 56 00 32 00 7B 00 39 00 30 00 29 00 52 00")
writeHex("32")
writeHex("1A")
writeHex("37 00 4D 00 32 00 25 00 4C 00 31 00 56 00 32 00 7B 00 39 00 30 00 29 00 52 00")
it.writeHex("38 01")
writeHex("38 01")
it.writeHex("48 01")
writeHex("48 01")
it.writeHex("50")
it.writeUVarInt(image.width.toUInt())
it.writeHex("58")
it.writeUVarInt(image.height.toUInt())
writeHex("50")
writeUVarInt(image.width.toUInt())
writeHex("58")
writeUVarInt(image.height.toUInt())
it.writeHex("60 04")
writeHex("60 04")
it.writeHex("6A")
it.writeHex("05")
it.writeHex("32 36 36 35 36")
writeHex("6A")
writeHex("05")
writeHex("32 36 36 35 36")
it.writeHex("70 00")
writeHex("70 00")
it.writeHex("78 03")
writeHex("78 03")
it.writeHex("80 01")
writeHex("80 01")
it.writeHex("00")
writeHex("00")
}
}
}
......
......@@ -24,9 +24,9 @@ class ClientChangeOnlineStatusPacket(
this.writeQQ(qq)
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.writeHex("01 00")
it.writeByte(loginStatus.id)
it.writeHex("00 01 00 01 00 04 00 00 00 00")
writeHex("01 00")
writeByte(loginStatus.id)
writeHex("00 01 00 01 00 04 00 00 00 00")
}
}
}
......
......@@ -34,8 +34,8 @@ class ClientPasswordSubmissionPacket(
this.writeHex(TIMProtocol.key0836)
this.encryptAndWrite(TIMProtocol.shareKey.hexToBytes()) {
it.writePart1(qq, password, loginTime, loginIP, privateKey, token0825)
it.writePart2()
writePart1(qq, password, loginTime, loginIP, privateKey, token0825)
writePart2()
}
}
}
......@@ -74,15 +74,15 @@ open class ClientLoginResendPacket internal constructor(
this.writeHex(TIMProtocol.key0836)//16
this.encryptAndWrite(TIMProtocol.shareKey.hexToBytes()) {
it.writePart1(qq, password, loginTime, loginIP, privateKey, token0825, tlv0006)
writePart1(qq, password, loginTime, loginIP, privateKey, token0825, tlv0006)
it.writeHex("01 10") //tag
it.writeHex("00 3C")//length
it.writeHex("00 01")//tag
it.writeHex("00 38")//length
it.write(token00BA)//value
writeHex("01 10") //tag
writeHex("00 3C")//length
writeHex("00 01")//tag
writeHex("00 38")//length
write(token00BA)//value
it.writePart2()
writePart2()
}
}
}
......
......@@ -23,7 +23,7 @@ class ClientSKeyRequestPacket(
this.writeQQ(qq)
this.writeHex(TIMProtocol.fixVer2)
this.encryptAndWrite(sessionKey) {
it.writeHex("33 00 05 00 08 74 2E 71 71 2E 63 6F 6D 00 0A 71 75 6E 2E 71 71 2E 63 6F 6D 00 0C 71 7A 6F 6E 65 2E 71 71 2E 63 6F 6D 00 0C 6A 75 62 61 6F 2E 71 71 2E 63 6F 6D 00 09 6B 65 2E 71 71 2E 63 6F 6D")
writeHex("33 00 05 00 08 74 2E 71 71 2E 63 6F 6D 00 0A 71 75 6E 2E 71 71 2E 63 6F 6D 00 0C 71 7A 6F 6E 65 2E 71 71 2E 63 6F 6D 00 0C 6A 75 62 61 6F 2E 71 71 2E 63 6F 6D 00 09 6B 65 2E 71 71 2E 63 6F 6D")
}
}
}
......@@ -41,7 +41,7 @@ class ClientSKeyRefreshmentRequestPacket(
this.writeRandom(2)//part of packet id
this.writeQQ(qq)
this.encryptAndWrite(sessionKey) {
it.writeHex("33 00 05 00 08 74 2E 71 71 2E 63 6F 6D 00 0A 71 75 6E 2E 71 71 2E 63 6F 6D 00 0C 71 7A 6F 6E 65 2E 71 71 2E 63 6F 6D 00 0C 6A 75 62 61 6F 2E 71 71 2E 63 6F 6D 00 09 6B 65 2E 71 71 2E 63 6F 6D")
writeHex("33 00 05 00 08 74 2E 71 71 2E 63 6F 6D 00 0A 71 75 6E 2E 71 71 2E 63 6F 6D 00 0C 71 7A 6F 6E 65 2E 71 71 2E 63 6F 6D 00 0C 6A 75 62 61 6F 2E 71 71 2E 63 6F 6D 00 09 6B 65 2E 71 71 2E 63 6F 6D")
}
}
}
......
......@@ -25,39 +25,39 @@ class ClientSessionRequestPacket(
this.writeHex("00 38")
this.write(token38)
this.encryptAndWrite(encryptionKey) {
it.writeHex("00 07 00 88")
it.write(token88)
it.writeHex("00 0C 00 16 00 02 00 00 00 00 00 00 00 00 00 00")
it.writeIP(serverIp)
it.writeHex("1F 40 00 00 00 00 00 15 00 30 00 01")//fix1
it.writeHex("01 92 A5 D2 59 00 10 54 2D CF 9B 60 BF BB EC 0D D4 81 CE 36 87 DE 35 02 AE 6D ED DC 00 10 ")
it.writeHex(TIMProtocol.fix0836)
it.writeHex("00 36 00 12 00 02 00 01 00 00 00 05 00 00 00 00 00 00 00 00 00 00")
it.writeHex(TIMProtocol.constantData1)
it.writeHex(TIMProtocol.constantData2)
it.writeQQ(qq)
it.writeHex("00 00 00 00 00 1F 00 22 00 01")
it.writeHex("1A 68 73 66 E4 BA 79 92 CC C2 D4 EC 14 7C 8B AF 43 B0 62 FB 65 58 A9 EB 37 55 1D 26 13 A8 E5 3D")//device ID
writeHex("00 07 00 88")
write(token88)
writeHex("00 0C 00 16 00 02 00 00 00 00 00 00 00 00 00 00")
writeIP(serverIp)
writeHex("1F 40 00 00 00 00 00 15 00 30 00 01")//fix1
writeHex("01 92 A5 D2 59 00 10 54 2D CF 9B 60 BF BB EC 0D D4 81 CE 36 87 DE 35 02 AE 6D ED DC 00 10 ")
writeHex(TIMProtocol.fix0836)
writeHex("00 36 00 12 00 02 00 01 00 00 00 05 00 00 00 00 00 00 00 00 00 00")
writeHex(TIMProtocol.constantData1)
writeHex(TIMProtocol.constantData2)
writeQQ(qq)
writeHex("00 00 00 00 00 1F 00 22 00 01")
writeHex("1A 68 73 66 E4 BA 79 92 CC C2 D4 EC 14 7C 8B AF 43 B0 62 FB 65 58 A9 EB 37 55 1D 26 13 A8 E5 3D")//device ID
//tlv0106
it.writeHex("01 05 00 30")
it.writeHex("00 01 01 02 00 14 01 01 00 10")
it.writeRandom(16)
it.writeHex("00 14 01 02 00 10")
it.writeRandom(16)
writeHex("01 05 00 30")
writeHex("00 01 01 02 00 14 01 01 00 10")
writeRandom(16)
writeHex("00 14 01 02 00 10")
writeRandom(16)
it.writeHex("01 0B 00 85 00 02")
it.writeHex("B9 ED EF D7 CD E5 47 96 7A B5 28 34 CA 93 6B 5C")//fix2
it.writeRandom(1)
it.writeHex("10 00 00 00 00 00 00 00 02")
writeHex("01 0B 00 85 00 02")
writeHex("B9 ED EF D7 CD E5 47 96 7A B5 28 34 CA 93 6B 5C")//fix2
writeRandom(1)
writeHex("10 00 00 00 00 00 00 00 02")
//fix3
it.writeHex("00 63 3E 00 63 02 04 03 06 02 00 04 00 52 D9 00 00 00 00 A9 58 3E 6D 6D 49 AA F6 A6 D9 33 0A E7 7E 36 84 03 01 00 00 68 20 15 8B 00 00 01 02 00 00 03 00 07 DF 00 0A 00 0C 00 01 00 04 00 03 00 04 20 5C 00")
it.writeRandom(32)//md5 32
it.writeHex("68")
writeHex("00 63 3E 00 63 02 04 03 06 02 00 04 00 52 D9 00 00 00 00 A9 58 3E 6D 6D 49 AA F6 A6 D9 33 0A E7 7E 36 84 03 01 00 00 68 20 15 8B 00 00 01 02 00 00 03 00 07 DF 00 0A 00 0C 00 01 00 04 00 03 00 04 20 5C 00")
writeRandom(32)//md5 32
writeHex("68")
it.writeHex("00 00 00 00 00 2D 00 06 00 01")
it.writeIP(InetAddress.getLocalHost().hostAddress)
writeHex("00 00 00 00 00 2D 00 06 00 01")
writeIP(InetAddress.getLocalHost().hostAddress)
}
}
}
......
......@@ -78,13 +78,13 @@ class ClientTouchPacket(private val qq: Long, private val serverIp: String) : Cl
this.writeHex(TIMProtocol.touchKey)
this.encryptAndWrite(TIMProtocol.touchKey) {
it.writeHex(TIMProtocol.constantData1)
it.writeHex(TIMProtocol.constantData2)
it.writeQQ(qq)
it.writeHex("00 00 00 00 03 09 00 08 00 01")
it.writeIP(serverIp)
it.writeHex("00 02 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 02 00 19")
it.writeHex(TIMProtocol.publicKey)
writeHex(TIMProtocol.constantData1)
writeHex(TIMProtocol.constantData2)
writeQQ(qq)
writeHex("00 00 00 00 03 09 00 08 00 01")
writeIP(serverIp)
writeHex("00 02 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 02 00 19")
writeHex(TIMProtocol.publicKey)
}
}
}
......
......@@ -27,18 +27,18 @@ class ClientVerificationCodeTransmissionRequestPacket(
this.writeHex(TIMProtocol.fixVer)
this.writeHex(TIMProtocol.key00BA)
this.encryptAndWrite(TIMProtocol.key00BA) {
it.writeHex("00 02 00 00 08 04 01 E0")
it.writeHex(TIMProtocol.constantData2)
it.writeHex("00 00 38")
it.write(token0825)
it.writeHex("01 03 00 19")
it.writeHex(TIMProtocol.publicKey)
it.writeHex("13 00 05 00 00 00 00")
it.writeByte(verificationSequence)
it.writeHex("00 28")
it.write(token00BA)
it.writeHex("00 10")
it.writeHex(TIMProtocol.key00BAFix)
writeHex("00 02 00 00 08 04 01 E0")
writeHex(TIMProtocol.constantData2)
writeHex("00 00 38")
write(token0825)
writeHex("01 03 00 19")
writeHex(TIMProtocol.publicKey)
writeHex("13 00 05 00 00 00 00")
writeByte(verificationSequence)
writeHex("00 28")
write(token00BA)
writeHex("00 10")
writeHex(TIMProtocol.key00BAFix)
}
}
}
......@@ -66,22 +66,22 @@ class ClientVerificationCodeSubmitPacket(
this.writeHex(TIMProtocol.fixVer)
this.writeHex(TIMProtocol.key00BA)
this.encryptAndWrite(TIMProtocol.key00BA) {
it.writeHex("00 02 00 00 08 04 01 E0")
it.writeHex(TIMProtocol.constantData2)
it.writeHex("01 00 38")
it.write(token0825)
it.writeHex("01 03")
writeHex("00 02 00 00 08 04 01 E0")
writeHex(TIMProtocol.constantData2)
writeHex("01 00 38")
write(token0825)
writeHex("01 03")
it.writeShort(25)
it.writeHex(TIMProtocol.publicKey)//25
writeShort(25)
writeHex(TIMProtocol.publicKey)//25
it.writeHex("14 00 05 00 00 00 00 00 04")
it.write(captcha.toUpperCase().toByteArray())
it.writeHex("00 38")
it.write(verificationToken)
writeHex("14 00 05 00 00 00 00 00 04")
write(captcha.toUpperCase().toByteArray())
writeHex("00 38")
write(verificationToken)
it.writeShort(16)
it.writeHex(TIMProtocol.key00BAFix)//16
writeShort(16)
writeHex(TIMProtocol.key00BAFix)//16
}
}
......@@ -107,14 +107,14 @@ class ClientVerificationCodeRefreshPacket(
this.writeHex(TIMProtocol.fixVer)
this.writeHex(TIMProtocol.key00BA)
this.encryptAndWrite(TIMProtocol.key00BA) {
it.writeHex("00 02 00 00 08 04 01 E0")
it.writeHex(TIMProtocol.constantData2)
it.writeHex("00 00 38")
it.write(token0825)
it.writeHex("01 03 00 19")
it.writeHex(TIMProtocol.publicKey)
it.writeHex("13 00 05 00 00 00 00 00 00 00 00 10")
it.writeHex(TIMProtocol.key00BAFix)
writeHex("00 02 00 00 08 04 01 E0")
writeHex(TIMProtocol.constantData2)
writeHex("00 00 38")
write(token0825)
writeHex("01 03 00 19")
writeHex(TIMProtocol.publicKey)
writeHex("13 00 05 00 00 00 00 00 00 00 00 10")
writeHex(TIMProtocol.key00BAFix)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment