This commit is contained in:
Him188moe 2019-08-17 18:28:09 +08:00
parent 5a8899bdde
commit 2fa99f22af
3 changed files with 18 additions and 4 deletions

View File

@ -39,7 +39,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
*
*
* Before sending the packet, an [tail][Protocol.tail] will be added.
*/// TODO: 2019/8/9 添加 tail
*/
@Throws(IOException::class)
abstract fun encode()

View File

@ -2,6 +2,7 @@ package net.mamoe.mirai.network.packet.server
import net.mamoe.mirai.network.Protocol
import net.mamoe.mirai.util.TEACryptor
import net.mamoe.mirai.util.getRandomKey
import java.io.DataInputStream
/**
@ -22,6 +23,7 @@ class Server0825Packet(private val type: Type, inputStream: DataInputStream) : S
TYPE_08_25_31_02,
}
@ExperimentalUnsignedTypes
override fun decode() {
input.skip(43 - 11)//todo: check
val data = DataInputStream(TEACryptor.decrypt(input.readAllBytes().let { it.copyOfRange(0, it.size - 2) }, when (type) {//todo: check array range
@ -38,10 +40,10 @@ class Server0825Packet(private val type: Type, inputStream: DataInputStream) : S
token = data.readNBytes(167 - (16 - 2))
loginTime = data.readLong()//todo check
loginIP = data.readIP()
TODO("从易语言抄协议来")
tgtgtKey = getRandomKey(16);
}
else -> {
throw IllegalStateException()
}
}
}

View File

@ -3,6 +3,8 @@ package net.mamoe.mirai.util
import net.mamoe.mirai.network.Protocol
import java.io.ByteArrayOutputStream
import java.io.DataOutputStream
import java.util.*
import java.util.zip.CRC32
/**
* @author Him188moe @ Mirai Project
@ -32,6 +34,7 @@ fun UByteArray.toHexString(separator: String = ", "): String = Utils.toHexString
fun Byte.toHexString(): String = this.toString(16)
@ExperimentalUnsignedTypes
fun String.hexToBytes(): ByteArray = Protocol.hexToBytes(this)
@ExperimentalUnsignedTypes
fun String.hexToUBytes(): UByteArray = Protocol.hexToUBytes(this)
@ -40,4 +43,13 @@ open class ByteArrayDataOutputStream : DataOutputStream(ByteArrayOutputStream())
open fun toByteArray(): ByteArray = (out as ByteArrayOutputStream).toByteArray()
@ExperimentalUnsignedTypes
open fun toUByteArray(): UByteArray = (out as ByteArrayOutputStream).toByteArray().toUByteArray();
}
}
@ExperimentalUnsignedTypes
fun getRandomKey(length: Int): ByteArray {
val bytes = LinkedList<Byte>();
for (i in 0..length) bytes.add((Math.random() * 255).toByte())
return bytes.toByteArray();
}
fun getCrc32(key: ByteArray): Long = with(CRC32()) { update(key); return@with this.value };