mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-09 19:50:27 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f6bab7921a
@ -10,8 +10,8 @@ import io.netty.channel.socket.SocketChannel
|
||||
import io.netty.channel.socket.nio.NioSocketChannel
|
||||
import io.netty.handler.codec.bytes.ByteArrayDecoder
|
||||
import io.netty.handler.codec.bytes.ByteArrayEncoder
|
||||
import net.mamoe.mirai.network.packet.client.Client0825ResponsePacket
|
||||
import net.mamoe.mirai.network.packet.client.ClientPacket
|
||||
import net.mamoe.mirai.network.packet.client.ClientServerRedirectionPacket
|
||||
import net.mamoe.mirai.network.packet.client.writeHex
|
||||
import net.mamoe.mirai.network.packet.server.Server0825Packet
|
||||
import net.mamoe.mirai.network.packet.server.ServerPacket
|
||||
@ -33,7 +33,7 @@ class Robot(val number: Int) {
|
||||
packet.decode()
|
||||
if (packet is Server0825Packet) {
|
||||
connect(packet.serverIP)
|
||||
sendPacket(Client0825ResponsePacket(packet.serverIP, number))
|
||||
sendPacket(ClientServerRedirectionPacket(packet.serverIP, number))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import net.mamoe.mirai.network.packet.PacketId
|
||||
import net.mamoe.mirai.util.ByteArrayDataOutputStream
|
||||
import net.mamoe.mirai.util.TEACryptor
|
||||
import net.mamoe.mirai.util.hexToBytes
|
||||
import net.mamoe.mirai.util.toHexString
|
||||
import java.io.DataOutputStream
|
||||
import java.io.IOException
|
||||
import java.security.MessageDigest
|
||||
@ -86,7 +87,7 @@ fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArra
|
||||
it.writeHex("00 00 01")
|
||||
|
||||
val md5_1 = md5(password);
|
||||
val md5_2 = md5(md5_1 + "00 00 00 00".hexToBytes() + qq.toBytes())
|
||||
val md5_2 = md5(md5_1 + "00 00 00 00".hexToBytes() + qq.toByteArray())
|
||||
it.write(md5_1)
|
||||
it.write(loginTime)//todo FIXED 12(maybe 11???) bytes??? check that
|
||||
it.writeByte(0);
|
||||
@ -99,13 +100,15 @@ fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArra
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.toBytes(): ByteArray = byteArrayOf(
|
||||
private fun Int.toByteArray(): ByteArray = byteArrayOf(//todo 检查这方法对不对, 这其实就是从 DataInputStream copy来的
|
||||
(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 Int.toHexString(separator: String = " "): String = this.toByteArray().toHexString(separator);
|
||||
|
||||
private fun md5(str: String): ByteArray = MessageDigest.getInstance("MD5").digest(str.toByteArray())
|
||||
|
||||
private fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5").digest(byteArray)
|
||||
|
@ -10,14 +10,15 @@ import java.io.IOException
|
||||
import java.net.InetAddress
|
||||
|
||||
/**
|
||||
* Password submission (0836_622)
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
@PacketId("08 36")
|
||||
@PacketId("08 36 31 03")
|
||||
@ExperimentalUnsignedTypes
|
||||
class Client0836_622Packet(private val qq: Int, private val password: String, private val loginTime: ByteArray, private val loginIP: ByteArray, private val tgtgtKey: ByteArray, private val seq: String, private val token0825: ByteArray) : ClientPacket() {
|
||||
class ClientPasswordSubmissionPacket(private val qq: Int, private val password: String, private val loginTime: ByteArray, private val loginIP: ByteArray, private val tgtgtKey: ByteArray, private val token0825: ByteArray) : ClientPacket() {
|
||||
@ExperimentalUnsignedTypes
|
||||
override fun encode() {
|
||||
this.writeHex(seq)
|
||||
this.writeQQ(qq)
|
||||
this.writeHex(Protocol._0836_622_fix1)
|
||||
this.writeHex(Protocol.publicKey)
|
@ -7,11 +7,13 @@ import net.mamoe.mirai.util.hexToBytes
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Server redirection (0825 response)
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@PacketId("08 25 31 02")
|
||||
class Client0825ResponsePacket(private val serverIP: String, private val qq: Int) : ClientPacket() {
|
||||
class ClientServerRedirectionPacket(private val serverIP: String, private val qq: Int) : ClientPacket() {
|
||||
@ExperimentalUnsignedTypes
|
||||
override fun encode() {
|
||||
this.writeQQ(qq)
|
@ -10,7 +10,7 @@ import java.util.zip.CRC32
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
object Utils {
|
||||
fun toHexString(byteArray: ByteArray, separator: String = ","): String = byteArray.joinToString(separator) {
|
||||
fun toHexString(byteArray: ByteArray, separator: String = " "): String = byteArray.joinToString(separator) {
|
||||
var ret = it.toString(16).toUpperCase();
|
||||
if (ret.length == 1) {
|
||||
ret = "0$ret";
|
||||
@ -19,7 +19,7 @@ object Utils {
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
fun toHexString(byteArray: UByteArray, separator: String = ","): String = byteArray.joinToString(separator) {
|
||||
fun toHexString(byteArray: UByteArray, separator: String = " "): String = byteArray.joinToString(separator) {
|
||||
var ret = it.toString(16).toUpperCase();
|
||||
if (ret.length == 1) {
|
||||
ret = "0$ret";
|
||||
@ -28,9 +28,9 @@ object Utils {
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteArray.toHexString(separator: String = ", "): String = Utils.toHexString(this, separator)
|
||||
fun ByteArray.toHexString(separator: String = " "): String = Utils.toHexString(this, separator)
|
||||
@ExperimentalUnsignedTypes
|
||||
fun UByteArray.toHexString(separator: String = ", "): String = Utils.toHexString(this, separator)
|
||||
fun UByteArray.toHexString(separator: String = " "): String = Utils.toHexString(this, separator)
|
||||
|
||||
fun Byte.toHexString(): String = this.toString(16)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user