Commit 091037ec authored by liujiahua123123's avatar liujiahua123123

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt
parents 50c0f27c 3e451344
...@@ -44,6 +44,9 @@ interface Protocol { ...@@ -44,6 +44,9 @@ interface Protocol {
const val encryptKey = "“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”" const val encryptKey = "“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”"
const val _0836_622_fix2 = "00 15 00 30 00 01 01 27 9B C7 F5 00 10 65 03 FD 8B 00 00 00 00 00 00 00 00 00 00 00 00 02 90 49 55 33 00 10 15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B";
const val _0836_622_fix1 = "03 00 00 00 01 01 01 00 00 68 20 00 00 00 00 00 01 01 03 00 19";
const val _0836key1 = "EF 4A 36 6A 16 A8 E6 3D 2E EA BD 1F 98 C1 3C DA"
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
fun hexToBytes(hex: String): ByteArray = hexToUBytes(hex).toByteArray() fun hexToBytes(hex: String): ByteArray = hexToUBytes(hex).toByteArray()
......
...@@ -14,5 +14,5 @@ public @interface PacketId { ...@@ -14,5 +14,5 @@ public @interface PacketId {
/** /**
* 获取用于识别的包 ID * 获取用于识别的包 ID
*/ */
int value(); String value();
} }
package net.mamoe.mirai.network.packet.client
import net.mamoe.mirai.network.Protocol
import net.mamoe.mirai.network.packet.PacketId
import net.mamoe.mirai.util.TEACryptor
import net.mamoe.mirai.util.getCrc32
import net.mamoe.mirai.util.getRandomKey
import net.mamoe.mirai.util.hexToBytes
import java.io.IOException
import java.net.InetAddress
/**
* @author Him188moe @ Mirai Project
*/
@PacketId("08 36")
@ExperimentalUnsignedTypes
class Client0836_622Packet(private val qq: Int, private val password: String, private val tgtgtKey: ByteArray, private val seq: String, private val token0825: ByteArray) : ClientPacket() {
@ExperimentalUnsignedTypes
override fun encode() {
//TEA 加密
this.write(TEACryptor.encrypt(object : ClientPacket() {
@Throws(IOException::class)
override fun encode() {
val hostName: String = InetAddress.getLocalHost().hostName.let { it.substring(0, it.length - 3) };
this.writeQQ(System.currentTimeMillis().toInt())//that's correct
this.writeHex("01 12");//tag
this.writeHex("00 38");//length
this.write(token0825);//length
this.writeHex("03 0F");//tag
this.writeShort(hostName.length / 2);//todo check that
this.writeShort(hostName.length);
this.writeBytes(hostName)
this.writeHex("00 05 00 06 00 02")
this.writeQQ(qq)
this.writeHex("00 06")//tag
this.writeHex("00 78")//length
this.writeTLV0006(qq, password)
//fix
this.writeHex(Protocol._0836_622_fix2)
this.writeHex("00 1A")//tag
this.writeHex("00 40")//length
this.write(TEACryptor.encrypt(Protocol._0836_622_fix2.hexToBytes(), tgtgtKey))
this.writeHex(Protocol._0825data0)
this.writeHex(Protocol._0825data2)
this.writeQQ(qq)
this.writeZero(4)
this.writeHex("01 03")//tag
this.writeHex("00 14")//length
this.writeHex("00 01")//tag
this.writeHex("00 10")//length
this.writeHex("60 C9 5D A7 45 70 04 7F 21 7D 84 50 5C 66 A5 C6")//key
this.writeHex("03 12")//tag
this.writeHex("00 05")//length
this.writeHex("01 00 00 00 01")//value
this.writeHex("05 08")//tag
this.writeHex("00 05")//length
this.writeHex("10 00 00 00 00")//value
this.writeHex("03 13")//tag
this.writeHex("00 19")//length
this.writeHex("01")//value
this.writeHex("01 02")//tag
this.writeHex("00 10")//length
this.writeHex("04 EA 78 D1 A4 FF CD CC 7C B8 D4 12 7D BB 03 AA")//key
this.writeZero(3)
this.writeByte(0)//maybe 00, 0F, 1F
this.writeHex("01 02")//tag
this.writeHex("00 62")//length
this.writeHex("00 01")//word?
this.writeHex("04 EB B7 C1 86 F9 08 96 ED 56 84 AB 50 85 2E 48")//key
this.writeHex("00 38")//length
//value
this.writeHex("E9 AA 2B 4D 26 4C 76 18 FE 59 D5 A9 82 6A 0C 04 B4 49 50 D7 9B B1 FE 5D 97 54 8D 82 F3 22 C2 48 B9 C9 22 69 CA 78 AD 3E 2D E9 C9 DF A8 9E 7D 8C 8D 6B DF 4C D7 34 D0 D3")
this.writeHex("00 14")//length
getRandomKey(16).let {
write(it)//key
writeLong(getCrc32(it))//todo may be int? check that.
}
}
}.encodeToByteArray(), Protocol.redirectionKey.hexToBytes()))
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ import java.io.IOException ...@@ -10,6 +10,7 @@ import java.io.IOException
/** /**
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
*/ */
@ExperimentalUnsignedTypes
@PacketId(0x08_25_31_01) @PacketId(0x08_25_31_01)
class ClientLoginPacket : ClientPacket() { class ClientLoginPacket : ClientPacket() {
var qq: Int = 0 var qq: Int = 0
......
...@@ -5,8 +5,11 @@ import net.mamoe.mirai.network.Protocol ...@@ -5,8 +5,11 @@ import net.mamoe.mirai.network.Protocol
import net.mamoe.mirai.network.packet.Packet import net.mamoe.mirai.network.packet.Packet
import net.mamoe.mirai.network.packet.PacketId import net.mamoe.mirai.network.packet.PacketId
import net.mamoe.mirai.util.ByteArrayDataOutputStream import net.mamoe.mirai.util.ByteArrayDataOutputStream
import net.mamoe.mirai.util.TEACryptor
import net.mamoe.mirai.util.hexToBytes
import java.io.DataOutputStream import java.io.DataOutputStream
import java.io.IOException import java.io.IOException
import java.security.MessageDigest
/** /**
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
...@@ -14,7 +17,7 @@ import java.io.IOException ...@@ -14,7 +17,7 @@ import java.io.IOException
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
abstract class ClientPacket : ByteArrayDataOutputStream(), Packet { abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
@Getter @Getter
val packageId: Int val packageId: String
init { init {
val annotation = this.javaClass.getAnnotation(PacketId::class.java) val annotation = this.javaClass.getAnnotation(PacketId::class.java)
...@@ -32,7 +35,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet { ...@@ -32,7 +35,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
@Throws(IOException::class) @Throws(IOException::class)
fun writePacketId() { fun writePacketId() {
this.writeInt(this@ClientPacket.packageId) this.writeHex(this@ClientPacket.packageId)
} }
/** /**
...@@ -72,6 +75,50 @@ fun DataOutputStream.writeHex(hex: String) { ...@@ -72,6 +75,50 @@ fun DataOutputStream.writeHex(hex: String) {
} }
} }
@ExperimentalUnsignedTypes
@Throws(IOException::class)
fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArray, loginIP: ByteArray, tgtgtKey: ByteArray) {
ByteArrayDataOutputStream().let {
it.writeRandom(4)
it.writeHex("00 02")
it.writeQQ(qq)
it.writeHex(Protocol._0825data2)
it.writeHex("00 00 01")
val md5_1: ByteArray = md5(password);
val md5_2 = md5(md5_1 + "00 00 00 00".hexToBytes() + qq.toBytes())
it.write(md5_1)
it.write(loginTime)//FIXED 12(maybe 11???) bytes
it.writeByte(0);
it.writeZero(4 * 3)
it.write(loginIP)
it.writeHex("00 10")
it.writeHex("15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B")
it.write(tgtgtKey)
this.write(TEACryptor.encrypt(md5_2, it.toByteArray()))
}
}
private fun Int.toBytes(): ByteArray = byteArrayOf(
(this.ushr(24) and 0xFF).toByte(),
(this.ushr(16) and 0xFF).toByte(),
(this.ushr(8) and 0xFF).toByte(),
(this.ushr(0) and 0xFF).toByte()
)
private fun md5(str: String): ByteArray = MessageDigest.getInstance("MD5").digest(str.toByteArray())
private fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5").digest(byteArray)
@ExperimentalUnsignedTypes
@Throws(IOException::class)
fun DataOutputStream.writeZero(count: Int) {
for (x in 0..count) {
this.writeByte(0)
}
}
@Throws(IOException::class) @Throws(IOException::class)
fun DataOutputStream.writeRandom(length: Int) { fun DataOutputStream.writeRandom(length: Int) {
for (i in 0 until length) { for (i in 0 until length) {
......
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