mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 22:30:47 +08:00
update
This commit is contained in:
parent
5a8899bdde
commit
2fa99f22af
@ -39,7 +39,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Before sending the packet, an [tail][Protocol.tail] will be added.
|
* Before sending the packet, an [tail][Protocol.tail] will be added.
|
||||||
*/// TODO: 2019/8/9 添加 tail
|
*/
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
abstract fun encode()
|
abstract fun encode()
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package net.mamoe.mirai.network.packet.server
|
|||||||
|
|
||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import net.mamoe.mirai.util.TEACryptor
|
import net.mamoe.mirai.util.TEACryptor
|
||||||
|
import net.mamoe.mirai.util.getRandomKey
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,6 +23,7 @@ class Server0825Packet(private val type: Type, inputStream: DataInputStream) : S
|
|||||||
TYPE_08_25_31_02,
|
TYPE_08_25_31_02,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
override fun decode() {
|
override fun decode() {
|
||||||
input.skip(43 - 11)//todo: check
|
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
|
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))
|
token = data.readNBytes(167 - (16 - 2))
|
||||||
loginTime = data.readLong()//todo check
|
loginTime = data.readLong()//todo check
|
||||||
loginIP = data.readIP()
|
loginIP = data.readIP()
|
||||||
|
tgtgtKey = getRandomKey(16);
|
||||||
TODO("从易语言抄协议来")
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
throw IllegalStateException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package net.mamoe.mirai.util
|
|||||||
import net.mamoe.mirai.network.Protocol
|
import net.mamoe.mirai.network.Protocol
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
|
import java.util.*
|
||||||
|
import java.util.zip.CRC32
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Him188moe @ Mirai Project
|
* @author Him188moe @ Mirai Project
|
||||||
@ -32,6 +34,7 @@ fun UByteArray.toHexString(separator: String = ", "): String = Utils.toHexString
|
|||||||
|
|
||||||
fun Byte.toHexString(): String = this.toString(16)
|
fun Byte.toHexString(): String = this.toString(16)
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
fun String.hexToBytes(): ByteArray = Protocol.hexToBytes(this)
|
fun String.hexToBytes(): ByteArray = Protocol.hexToBytes(this)
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
fun String.hexToUBytes(): UByteArray = Protocol.hexToUBytes(this)
|
fun String.hexToUBytes(): UByteArray = Protocol.hexToUBytes(this)
|
||||||
@ -40,4 +43,13 @@ open class ByteArrayDataOutputStream : DataOutputStream(ByteArrayOutputStream())
|
|||||||
open fun toByteArray(): ByteArray = (out as ByteArrayOutputStream).toByteArray()
|
open fun toByteArray(): ByteArray = (out as ByteArrayOutputStream).toByteArray()
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
open fun toUByteArray(): UByteArray = (out as ByteArrayOutputStream).toByteArray().toUByteArray();
|
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 };
|
Loading…
Reference in New Issue
Block a user