Commit 7e4e94a9 authored by Him188moe's avatar Him188moe

update

parent 0b2e8c24
...@@ -10,8 +10,8 @@ import io.netty.channel.socket.SocketChannel ...@@ -10,8 +10,8 @@ import io.netty.channel.socket.SocketChannel
import io.netty.channel.socket.nio.NioSocketChannel import io.netty.channel.socket.nio.NioSocketChannel
import io.netty.handler.codec.bytes.ByteArrayDecoder import io.netty.handler.codec.bytes.ByteArrayDecoder
import io.netty.handler.codec.bytes.ByteArrayEncoder 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.ClientPacket
import net.mamoe.mirai.network.packet.client.ClientServerRedirectionPacket
import net.mamoe.mirai.network.packet.client.writeHex import net.mamoe.mirai.network.packet.client.writeHex
import net.mamoe.mirai.network.packet.server.Server0825Packet import net.mamoe.mirai.network.packet.server.Server0825Packet
import net.mamoe.mirai.network.packet.server.ServerPacket import net.mamoe.mirai.network.packet.server.ServerPacket
...@@ -33,7 +33,7 @@ class Robot(val number: Int) { ...@@ -33,7 +33,7 @@ class Robot(val number: Int) {
packet.decode() packet.decode()
if (packet is Server0825Packet) { if (packet is Server0825Packet) {
connect(packet.serverIP) connect(packet.serverIP)
sendPacket(Client0825ResponsePacket(packet.serverIP, number)) sendPacket(ClientServerRedirectionPacket(packet.serverIP, number))
} }
} }
......
...@@ -7,6 +7,7 @@ import net.mamoe.mirai.network.packet.PacketId ...@@ -7,6 +7,7 @@ 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.TEACryptor
import net.mamoe.mirai.util.hexToBytes import net.mamoe.mirai.util.hexToBytes
import net.mamoe.mirai.util.toHexString
import java.io.DataOutputStream import java.io.DataOutputStream
import java.io.IOException import java.io.IOException
import java.security.MessageDigest import java.security.MessageDigest
...@@ -86,7 +87,7 @@ fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArra ...@@ -86,7 +87,7 @@ fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArra
it.writeHex("00 00 01") it.writeHex("00 00 01")
val md5_1 = md5(password); 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(md5_1)
it.write(loginTime)//todo FIXED 12(maybe 11???) bytes??? check that it.write(loginTime)//todo FIXED 12(maybe 11???) bytes??? check that
it.writeByte(0); it.writeByte(0);
...@@ -99,13 +100,15 @@ fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArra ...@@ -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(24) and 0xFF).toByte(),
(this.ushr(16) and 0xFF).toByte(), (this.ushr(16) and 0xFF).toByte(),
(this.ushr(8) and 0xFF).toByte(), (this.ushr(8) and 0xFF).toByte(),
(this.ushr(0) 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(str: String): ByteArray = MessageDigest.getInstance("MD5").digest(str.toByteArray())
private fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5").digest(byteArray) private fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5").digest(byteArray)
......
...@@ -10,14 +10,15 @@ import java.io.IOException ...@@ -10,14 +10,15 @@ import java.io.IOException
import java.net.InetAddress import java.net.InetAddress
/** /**
* Password submission (0836_622)
*
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
*/ */
@PacketId("08 36") @PacketId("08 36 31 03")
@ExperimentalUnsignedTypes @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 @ExperimentalUnsignedTypes
override fun encode() { override fun encode() {
this.writeHex(seq)
this.writeQQ(qq) this.writeQQ(qq)
this.writeHex(Protocol._0836_622_fix1) this.writeHex(Protocol._0836_622_fix1)
this.writeHex(Protocol.publicKey) this.writeHex(Protocol.publicKey)
......
...@@ -7,11 +7,13 @@ import net.mamoe.mirai.util.hexToBytes ...@@ -7,11 +7,13 @@ import net.mamoe.mirai.util.hexToBytes
import java.io.IOException import java.io.IOException
/** /**
* Server redirection (0825 response)
*
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
*/ */
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
@PacketId("08 25 31 02") @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 @ExperimentalUnsignedTypes
override fun encode() { override fun encode() {
this.writeQQ(qq) this.writeQQ(qq)
......
...@@ -10,7 +10,7 @@ import java.util.zip.CRC32 ...@@ -10,7 +10,7 @@ import java.util.zip.CRC32
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
*/ */
object Utils { 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(); var ret = it.toString(16).toUpperCase();
if (ret.length == 1) { if (ret.length == 1) {
ret = "0$ret"; ret = "0$ret";
...@@ -19,7 +19,7 @@ object Utils { ...@@ -19,7 +19,7 @@ object Utils {
} }
@ExperimentalUnsignedTypes @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(); var ret = it.toString(16).toUpperCase();
if (ret.length == 1) { if (ret.length == 1) {
ret = "0$ret"; ret = "0$ret";
...@@ -28,9 +28,9 @@ object Utils { ...@@ -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 @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) fun Byte.toHexString(): String = this.toString(16)
......
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