mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-24 06:10:09 +08:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/login/ClientPasswordSubmissionPacket.kt # mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt
This commit is contained in:
commit
ff3bd74abf
@ -95,7 +95,7 @@ public class MiraiServer {
|
||||
});
|
||||
*/
|
||||
|
||||
Robot robot = new Robot(1994701021);
|
||||
Robot robot = new Robot(1994701021, "xiaoqqq");
|
||||
try {
|
||||
robot.connect(Protocol.Companion.getSERVER_IP().get(2), 8000);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -11,10 +11,11 @@ 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.ClientPacket
|
||||
import net.mamoe.mirai.network.packet.client.ClientServerRedirectionPacket
|
||||
import net.mamoe.mirai.network.packet.client.login.ClientPasswordSubmissionPacket
|
||||
import net.mamoe.mirai.network.packet.client.login.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
|
||||
import net.mamoe.mirai.network.packet.server.ServerTouchResponsePacket
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.net.DatagramPacket
|
||||
import java.net.InetSocketAddress
|
||||
@ -24,16 +25,30 @@ import java.net.InetSocketAddress
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
class Robot(val number: Int) {
|
||||
class Robot(val number: Int, private val password: String) {
|
||||
private lateinit var channel: Channel
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
internal fun onPacketReceived(packet: ServerPacket) {
|
||||
packet.decode()
|
||||
if (packet is Server0825Packet) {
|
||||
connect(packet.serverIP)
|
||||
sendPacket(ClientServerRedirectionPacket(packet.serverIP, number))
|
||||
if (packet is ServerTouchResponsePacket) {
|
||||
if (packet.serverIP != null) {//redirection
|
||||
connect(packet.serverIP!!)
|
||||
sendPacket(ClientServerRedirectionPacket(
|
||||
serverIP = packet.serverIP!!,
|
||||
qq = number
|
||||
))
|
||||
} else {//password submission
|
||||
sendPacket(ClientPasswordSubmissionPacket(
|
||||
qq = this.number,
|
||||
password = this.password,
|
||||
loginTime = packet.loginTime,
|
||||
loginIP = packet.loginIP,
|
||||
token0825 = packet.token,
|
||||
tgtgtKey = packet.tgtgtKey
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
|
||||
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun DataOutputStream.writeIp(ip: String) {
|
||||
fun DataOutputStream.writeIP(ip: String) {
|
||||
for (s in ip.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
|
||||
this.writeByte(s.toInt())
|
||||
}
|
||||
@ -78,7 +78,7 @@ fun DataOutputStream.writeHex(hex: String) {
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@Throws(IOException::class)
|
||||
fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArray, loginIP: ByteArray, tgtgtKey: ByteArray) {
|
||||
fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: Int, loginIP: String, tgtgtKey: ByteArray) {
|
||||
ByteArrayDataOutputStream().let {
|
||||
it.writeRandom(4)
|
||||
it.writeHex("00 02")
|
||||
@ -89,10 +89,10 @@ fun DataOutputStream.writeTLV0006(qq: Int, password: String, loginTime: ByteArra
|
||||
val md5_1 = md5(password);
|
||||
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.writeInt(loginTime)//todo FIXED 12(maybe 11???) bytes??? check that
|
||||
it.writeByte(0);
|
||||
it.writeZero(4 * 3)
|
||||
it.write(loginIP)
|
||||
it.writeIP(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)
|
||||
|
@ -0,0 +1,11 @@
|
||||
package net.mamoe.mirai.network.packet.client
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
class ClientSendMessagePacket : ClientPacket() {
|
||||
override fun encode() {
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
package net.mamoe.mirai.network.packet.client
|
||||
package net.mamoe.mirai.network.packet.client.login
|
||||
|
||||
import net.mamoe.mirai.network.Protocol
|
||||
import net.mamoe.mirai.network.packet.PacketId
|
||||
import net.mamoe.mirai.network.packet.client.ClientPacket
|
||||
import net.mamoe.mirai.network.packet.client.writeHex
|
||||
import net.mamoe.mirai.network.packet.client.writeQQ
|
||||
import net.mamoe.mirai.network.packet.client.writeRandom
|
||||
import net.mamoe.mirai.util.TEACryptor
|
||||
import java.io.IOException
|
||||
|
||||
@ -9,7 +13,7 @@ import java.io.IOException
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@PacketId("00 58")
|
||||
@PacketId("00 58")//todo check
|
||||
class ClientHeartbeatPacket : ClientPacket() {
|
||||
var qq: Int = 0
|
||||
var sessionKey: ByteArray? = null//登录后获得
|
@ -32,12 +32,12 @@ class ClientPasswordSubmissionPacket(private val qq: Int, private val password:
|
||||
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.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)
|
@ -1,7 +1,11 @@
|
||||
package net.mamoe.mirai.network.packet.client
|
||||
package net.mamoe.mirai.network.packet.client.login
|
||||
|
||||
import net.mamoe.mirai.network.Protocol
|
||||
import net.mamoe.mirai.network.packet.PacketId
|
||||
import net.mamoe.mirai.network.packet.client.ClientPacket
|
||||
import net.mamoe.mirai.network.packet.client.writeHex
|
||||
import net.mamoe.mirai.network.packet.client.writeIP
|
||||
import net.mamoe.mirai.network.packet.client.writeQQ
|
||||
import net.mamoe.mirai.util.TEACryptor
|
||||
import net.mamoe.mirai.util.hexToBytes
|
||||
import java.io.IOException
|
||||
@ -28,7 +32,7 @@ class ClientServerRedirectionPacket(private val serverIP: String, private val qq
|
||||
this.writeHex(Protocol._0825data2)
|
||||
this.writeQQ(qq)
|
||||
this.writeHex("00 01 00 00 03 09 00 0C 00 01")
|
||||
this.writeIp(serverIP)
|
||||
this.writeIP(serverIP)
|
||||
this.writeHex("01 6F A1 58 22 01 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 03 00 19")
|
||||
this.writeHex(Protocol.publicKey)
|
||||
}
|
@ -1,18 +1,27 @@
|
||||
package net.mamoe.mirai.network.packet.client
|
||||
package net.mamoe.mirai.network.packet.client.login
|
||||
|
||||
import net.mamoe.mirai.network.Protocol
|
||||
import net.mamoe.mirai.network.packet.PacketId
|
||||
import net.mamoe.mirai.network.packet.client.ClientPacket
|
||||
import net.mamoe.mirai.network.packet.client.writeHex
|
||||
import net.mamoe.mirai.network.packet.client.writeIP
|
||||
import net.mamoe.mirai.network.packet.client.writeQQ
|
||||
import net.mamoe.mirai.util.ByteArrayDataOutputStream
|
||||
import net.mamoe.mirai.util.TEACryptor
|
||||
import net.mamoe.mirai.util.toHexString
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* The packet to touch server.
|
||||
*
|
||||
* @see net.mamoe.mirai.network.packet.server.ServerTouchResponsePacket
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@PacketId("08 25 31 01")
|
||||
class ClientLoginPacket : ClientPacket() {
|
||||
class ClientTouchPacket : ClientPacket() {
|
||||
//已经完成测试
|
||||
var qq: Int = 0
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@ -34,9 +43,9 @@ class ClientLoginPacket : ClientPacket() {
|
||||
this.writeHex(Protocol._0825data2)
|
||||
this.writeQQ(qq)
|
||||
this.writeHex("00 00 00 00 03 09 00 08 00 01")
|
||||
this.writeIp("192.168.1.1");
|
||||
//this.writeIp(Protocol.SERVER_IP[2]);
|
||||
//this.writeIp("123456789")
|
||||
this.writeIP("192.168.1.1");
|
||||
//this.writeIP(Protocol.SERVER_IP[2]);
|
||||
//this.writeIP("123456789")
|
||||
this.writeHex("00 02 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 02 00 19")
|
||||
this.writeHex(Protocol.publicKey)
|
||||
println(this.toUByteArray().toHexString(" "))
|
||||
@ -49,7 +58,7 @@ class ClientLoginPacket : ClientPacket() {
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
fun main() {
|
||||
val pk = ClientLoginPacket()
|
||||
val pk = ClientTouchPacket()
|
||||
pk.qq = 1994701021
|
||||
pk.encode()
|
||||
pk.writeHex(Protocol.tail)
|
||||
@ -70,13 +79,13 @@ fun main() {
|
||||
println(object : ByteArrayDataOutputStream() {
|
||||
@Throws(IOException::class)
|
||||
override fun toUByteArray(): UByteArray {
|
||||
//this.writeIp("192.168.1.1")
|
||||
//this.writeIP("192.168.1.1")
|
||||
this.writeHex(Protocol._0825data0)
|
||||
this.writeHex(Protocol._0825data2)
|
||||
this.writeQQ(1994701021)
|
||||
this.writeHex("00 00 00 00 03 09 00 08 00 01")
|
||||
//this.writeIp(Protocol.SERVER_IP.get(2));
|
||||
this.writeIp("192.168.1.1")
|
||||
//this.writeIP(Protocol.SERVER_IP.get(2));
|
||||
this.writeIP("192.168.1.1")
|
||||
this.writeHex("00 02 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 02 00 19")
|
||||
this.writeHex(Protocol.publicKey)
|
||||
return super.toUByteArray()
|
@ -54,7 +54,7 @@ fun DataInputStream.readIP(): String {
|
||||
val byte = readByte();
|
||||
buff += (byte.toUByte().toString())
|
||||
if(i !=3)buff+="."
|
||||
//System.out.println(byte.toHexString())
|
||||
System.out.println(byte.toHexString())
|
||||
}
|
||||
return buff
|
||||
}
|
||||
|
@ -6,10 +6,13 @@ import java.io.DataInputStream
|
||||
/**
|
||||
* A packet received when logging in, used to redirect server address
|
||||
*
|
||||
* @see net.mamoe.mirai.network.packet.client.login.ClientServerRedirectionPacket
|
||||
* @see net.mamoe.mirai.network.packet.client.login.ClientPasswordSubmissionPacket
|
||||
*
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
class Server0825Packet(private val type: Type, inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
lateinit var serverIP: String;
|
||||
class ServerTouchResponsePacket(private val type: Type, inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
var serverIP: String? = null;
|
||||
|
||||
var loginTime: Int = 0
|
||||
lateinit var loginIP: String
|
||||
@ -32,7 +35,7 @@ class Server0825Packet(private val type: Type, inputStream: DataInputStream) : S
|
||||
|
||||
when (data.readByte().toInt()) {
|
||||
0xFE -> {
|
||||
System.out.println("0xfe")
|
||||
println("0xfe")
|
||||
serverIP = data.readIP()
|
||||
}
|
||||
0X00 -> {
|
@ -1,9 +1,3 @@
|
||||
import net.mamoe.mirai.network.packet.server.Server0825Packet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Him188moe @ Mirai Project
|
||||
*/
|
||||
|
@ -1,9 +1,7 @@
|
||||
import net.mamoe.mirai.network.packet.client.ClientPasswordSubmissionPacket
|
||||
import net.mamoe.mirai.network.packet.client.toHexString
|
||||
import net.mamoe.mirai.network.packet.server.Server0825Packet
|
||||
import net.mamoe.mirai.util.TEACryptor
|
||||
import net.mamoe.mirai.network.packet.server.ServerTouchResponsePacket
|
||||
import net.mamoe.mirai.util.hexToBytes
|
||||
import net.mamoe.mirai.util.hexToUBytes
|
||||
import net.mamoe.mirai.util.toHexString
|
||||
import java.io.DataInputStream
|
||||
|
||||
@ -12,7 +10,7 @@ fun main(){
|
||||
/*
|
||||
val data = "00 37 13 08 25 31 01 EB 10 08 30 69 50 1C 84 A9 C2 16 D7 52 B9 1C 79 CA 5A CF FD BC EB 10 08 30 69 50 1C 84 A9 C2 16 D7 52 B9 1C 79 CA 5A CF FD BC AE D8 A6 BB DC 21 6E 79 26 E1 A2 23 11 AA B0 9A AE D8 A6 BB DC 21 6E 79 26 E1 A2 23 11 AA B0 9A 76 E4 B8 DD 03 00 00 00 01 2E 01 00 00 68 52 00 00 00 00 A4 F1 91 88 C9 82 14 99 0C 9E 56 55 91 23 C8 3D C3 47 F0 25 A1 8E 74 EF 1E 0B 32 5B 20 8A FA 3B 0B 52 8F 86 E6 04 F1 D6 F8 63 75 60 8C 0C 7D 06 D1 E0 22 F8 49 EF AF 61 EE 7E 69 72 EB 10 08 30 69 50 1C 84 A9 C2 16 D7 52 B9 1C 79 CA 5A CF FD BC AE D8 A6 BB DC 21 6E 79 26 E1 A2 23 11 AA B0 9A 49 39 72 ED 61 12 B6 88 4D A2 56 23 E9 92 11 92 27 4A 70 00 C9 01 7B 03";
|
||||
val s = DataInputStream(data.hexToBytes().inputStream())
|
||||
val packet = Server0825Packet(Server0825Packet.Type.TYPE_08_25_31_01,s)
|
||||
val packet = ServerTouchResponsePacket(ServerTouchResponsePacket.Type.TYPE_08_25_31_01, s)
|
||||
packet.decode()
|
||||
System.out.println(packet.token.toUByteArray().toHexString(" "))
|
||||
System.out.println(packet.loginTime.toHexString(" "))
|
||||
|
Loading…
Reference in New Issue
Block a user