Commit e129719d authored by Him188moe's avatar Him188moe

Updated robot & network structure

parent c353e8e8
...@@ -10,7 +10,7 @@ class Group(robot: Robot, number: Long) : Contact(robot, number), Closeable { ...@@ -10,7 +10,7 @@ class Group(robot: Robot, number: Long) : Contact(robot, number), Closeable {
val members = ContactList<QQ>() val members = ContactList<QQ>()
override fun sendMessage(message: Message) { override fun sendMessage(message: Message) {
robot.network.packetSystem.sendGroupMessage(this, message) robot.network.messageHandler.sendGroupMessage(this, message)
} }
override fun sendXMLMessage(message: String) { override fun sendXMLMessage(message: String) {
......
...@@ -12,7 +12,7 @@ import net.mamoe.mirai.message.defaults.At ...@@ -12,7 +12,7 @@ import net.mamoe.mirai.message.defaults.At
*/ */
class QQ(robot: Robot, number: Long) : Contact(robot, number) { class QQ(robot: Robot, number: Long) : Contact(robot, number) {
override fun sendMessage(message: Message) { override fun sendMessage(message: Message) {
robot.network.packetSystem.sendFriendMessage(this, message) robot.network.messageHandler.sendFriendMessage(this, message)
} }
override fun sendXMLMessage(message: String) { override fun sendXMLMessage(message: String) {
......
...@@ -7,88 +7,86 @@ import java.util.stream.Collectors ...@@ -7,88 +7,86 @@ import java.util.stream.Collectors
/** /**
* @author Him188moe * @author Him188moe
*/ */
interface Protocol { object Protocol {
companion object { val SERVER_IP: List<String> = object : ArrayList<String>() {
val SERVER_IP: ArrayList<String> = object : ArrayList<String>() { init {
init { add("183.60.56.29")
add("183.60.56.29")
arrayOf( arrayOf(
"sz2.tencent.com", "sz2.tencent.com",
"sz3.tencent.com", "sz3.tencent.com",
"sz4.tencent.com", "sz4.tencent.com",
"sz5.tencent.com", "sz5.tencent.com",
"sz6.tencent.com", "sz6.tencent.com",
"sz8.tencent.com", "sz8.tencent.com",
"sz9.tencent.com" "sz9.tencent.com"
).forEach { this.add(InetAddress.getByName(it).hostAddress) } ).forEach { this.add(InetAddress.getByName(it).hostAddress) }
}
} }
}
get() = Collections.unmodifiableList(field)
const val head = "02"
const val ver = "37 13"
const val fixVer = "03 00 00 00 01 2E 01 00 00 68 52 00 00 00 00"
const val tail = "03"
/**
* _fixVer
*/
const val fixVer2 = "02 00 00 00 01 01 01 00 00 68 20"
/**
* 0825data1
*/
const val constantData0 = "00 18 00 16 00 01 "
/**
* 0825data2
*/
const val constantData1 = "00 00 04 53 00 00 00 01 00 00 15 85 "
const val key0825 = "A4 F1 91 88 C9 82 14 99 0C 9E 56 55 91 23 C8 3D"
const val redirectionKey = "A8 F2 14 5F 58 12 60 AF 07 63 97 D6 76 B2 1A 3B"
const val publicKey = "02 6D 28 41 D2 A5 6F D2 FC 3E 2A 1F 03 75 DE 6E 28 8F A8 19 3E 5F 16 49 D3"
const val shareKey = "1A E9 7F 7D C9 73 75 98 AC 02 E0 80 5F A9 C6 AF"
const val fix0836 = "06 A9 12 97 B7 F8 76 25 AF AF D3 EA B4 C8 BC E7 "
const val head = "02" const val key00BA = "C1 9C B8 C8 7B 8C 81 BA 9E 9E 7A 89 E1 7A EC 94"
const val ver = "37 13" const val key00BAFix = "69 20 D1 14 74 F5 B3 93 E4 D5 02 B3 71 1A CD 2A"
const val fixVer = "03 00 00 00 01 2E 01 00 00 68 52 00 00 00 00"
const val tail = "03"
/**
* _fixVer
*/
const val fixVer2 = "02 00 00 00 01 01 01 00 00 68 20"
/**
* 0825data1
*/
const val constantData0 = "00 18 00 16 00 01 "
/**
* 0825data2
*/
const val constantData1 = "00 00 04 53 00 00 00 01 00 00 15 85 "
const val key0825 = "A4 F1 91 88 C9 82 14 99 0C 9E 56 55 91 23 C8 3D"
const val redirectionKey = "A8 F2 14 5F 58 12 60 AF 07 63 97 D6 76 B2 1A 3B"
const val publicKey = "02 6D 28 41 D2 A5 6F D2 FC 3E 2A 1F 03 75 DE 6E 28 8F A8 19 3E 5F 16 49 D3"
const val shareKey = "1A E9 7F 7D C9 73 75 98 AC 02 E0 80 5F A9 C6 AF"
const val fix0836 = "06 A9 12 97 B7 F8 76 25 AF AF D3 EA B4 C8 BC E7 "
const val key00BA = "C1 9C B8 C8 7B 8C 81 BA 9E 9E 7A 89 E1 7A EC 94"
const val key00BAFix = "69 20 D1 14 74 F5 B3 93 E4 D5 02 B3 71 1A CD 2A"
const val encryptKey = "“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”" const val encryptKey = "“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”"
/** /**
* 0836_622_fix2 * 0836_622_fix2
*/ */
const val passwordSubmissionKey2 = "00 15 00 30 00 01 01 27 9B C7 F5 00 10 65 03 FD 8B 00 00 00 00 00 00 00 00 00 00 00 00 02 90 49 55 33 00 10 15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B"; const val passwordSubmissionKey2 = "00 15 00 30 00 01 01 27 9B C7 F5 00 10 65 03 FD 8B 00 00 00 00 00 00 00 00 00 00 00 00 02 90 49 55 33 00 10 15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B";
/** /**
* 0836_622_fix1 * 0836_622_fix1
*/ */
const val passwordSubmissionKey1 = "03 00 00 00 01 01 01 00 00 68 20 00 00 00 00 00 01 01 03 00 19"; const val passwordSubmissionKey1 = "03 00 00 00 01 01 01 00 00 68 20 00 00 00 00 00 01 01 03 00 19";
/** /**
* fix_0836_1 * fix_0836_1
*/ */
const val key0836 = "EF 4A 36 6A 16 A8 E6 3D 2E EA BD 1F 98 C1 3C DA" const val key0836 = "EF 4A 36 6A 16 A8 E6 3D 2E EA BD 1F 98 C1 3C DA"
private val hexToByteArrayCacheMap: MutableMap<Int, ByteArray> = mutableMapOf() private val hexToByteArrayCacheMap: MutableMap<Int, ByteArray> = mutableMapOf()
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
fun hexToBytes(hex: String): ByteArray { fun hexToBytes(hex: String): ByteArray {
hex.hashCode().let { id -> hex.hashCode().let { id ->
if (hexToByteArrayCacheMap.containsKey(id)) { if (hexToByteArrayCacheMap.containsKey(id)) {
return hexToByteArrayCacheMap[id]!!.clone() return hexToByteArrayCacheMap[id]!!.clone()
} else { } else {
hexToUBytes(hex).toByteArray().let { hexToUBytes(hex).toByteArray().let {
hexToByteArrayCacheMap[id] = it.clone(); hexToByteArrayCacheMap[id] = it.clone();
return it return it
}
} }
} }
} }
}
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
fun hexToUBytes(hex: String): UByteArray = Arrays fun hexToUBytes(hex: String): UByteArray = Arrays
.stream(hex.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) .stream(hex.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
.map { value -> value.trim { it <= ' ' } } .map { value -> value.trim { it <= ' ' } }
.map { s -> s.toUByte(16) } .map { s -> s.toUByte(16) }
.collect(Collectors.toList()).toUByteArray() .collect(Collectors.toList()).toUByteArray()
}
} }
...@@ -17,6 +17,7 @@ class ClientAccountInfoRequestPacket( ...@@ -17,6 +17,7 @@ class ClientAccountInfoRequestPacket(
) : ClientPacket() { ) : ClientPacket() {
override fun encode() { override fun encode() {
this.writeRandom(2)//part of packet id this.writeRandom(2)//part of packet id
this.writeQQ(qq) this.writeQQ(qq)
this.writeHex(Protocol.fixVer2) this.writeHex(Protocol.fixVer2)
this.encryptAndWrite(sessionKey) { this.encryptAndWrite(sessionKey) {
......
...@@ -53,11 +53,13 @@ abstract class ServerPacket(val input: DataInputStream) : Packet { ...@@ -53,11 +53,13 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
551, 487 -> LoginState.DEVICE_LOCK 551, 487 -> LoginState.DEVICE_LOCK
359 -> LoginState.TAKEN_BACK 359 -> LoginState.TAKEN_BACK
else -> LoginState.UNKNOWN
/*
//unknown //unknown
63 -> throw IllegalArgumentException(bytes.size.toString() + " (Unknown error)") 63 -> throw IllegalArgumentException(bytes.size.toString() + " (Unknown error)")
351 -> throw IllegalArgumentException(bytes.size.toString() + " (Illegal package data or Unknown error)")//包数据有误 351 -> throw IllegalArgumentException(bytes.size.toString() + " (Illegal package data or Unknown error)")//包数据有误
else -> throw IllegalArgumentException(bytes.size.toString()) else -> throw IllegalArgumentException(bytes.size.toString())*/
}, stream) }, stream)
} }
...@@ -112,17 +114,6 @@ abstract class ServerPacket(val input: DataInputStream) : Packet { ...@@ -112,17 +114,6 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
} }
fun DataInputStream.readUntil(byte: Byte): ByteArray {
var buff = byteArrayOf()
var b: Byte
b = readByte()
while (b != byte) {
buff += b
b = readByte()
}
return buff
}
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
fun DataInputStream.readIP(): String { fun DataInputStream.readIP(): String {
var buff = "" var buff = ""
......
...@@ -14,5 +14,7 @@ enum class LoginState { ...@@ -14,5 +14,7 @@ enum class LoginState {
DEVICE_LOCK,//设备锁 DEVICE_LOCK,//设备锁
TAKEN_BACK,//被回收 TAKEN_BACK,//被回收
// VERIFICATION_CODE,//需要验证码 // VERIFICATION_CODE,//需要验证码
// SUCCEED,
UNKNOWN,
} }
\ No newline at end of file
...@@ -11,9 +11,8 @@ import java.util.Random; ...@@ -11,9 +11,8 @@ import java.util.Random;
* @author iweiz https://github.com/iweizime/StepChanger/blob/master/app/src/main/java/me/iweizi/stepchanger/qq/Cryptor.java * @author iweiz https://github.com/iweizime/StepChanger/blob/master/app/src/main/java/me/iweizi/stepchanger/qq/Cryptor.java
*/ */
public final class TEA { public final class TEA {
public static final TEA CRYPTOR_SHARE_KEY = new TEA(Protocol.Companion.hexToBytes(Protocol.shareKey)); public static final TEA CRYPTOR_SHARE_KEY = new TEA(Protocol.INSTANCE.hexToBytes(Protocol.shareKey));
public static final TEA CRYPTOR_0825KEY = new TEA(Protocol.Companion.hexToBytes(Protocol.key0825)); public static final TEA CRYPTOR_0825KEY = new TEA(Protocol.INSTANCE.hexToBytes(Protocol.key0825));
public static final TEA CRYPTOR_00BAKEY = new TEA(Protocol.Companion.hexToBytes(Protocol.key00BA));
private static final long UINT32_MASK = 0xffffffffL; private static final long UINT32_MASK = 0xffffffffL;
private final long[] mKey; private final long[] mKey;
......
...@@ -79,7 +79,7 @@ operator fun File.plus(child: String): File = File(this, child) ...@@ -79,7 +79,7 @@ operator fun File.plus(child: String): File = File(this, child)
private const val GTK_BASE_VALUE: Int = 5381 private const val GTK_BASE_VALUE: Int = 5381
fun getGTK(sKey: String): Int { internal fun getGTK(sKey: String): Int {
var value = GTK_BASE_VALUE var value = GTK_BASE_VALUE
for (c in sKey.toCharArray()) { for (c in sKey.toCharArray()) {
value += (value shl 5) + c.toInt() value += (value shl 5) + c.toInt()
...@@ -89,7 +89,7 @@ fun getGTK(sKey: String): Int { ...@@ -89,7 +89,7 @@ fun getGTK(sKey: String): Int {
return value return value
} }
fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() } internal fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() }
/** /**
...@@ -122,3 +122,13 @@ fun Any.getAllDeclaredFields(): List<Field> { ...@@ -122,3 +122,13 @@ fun Any.getAllDeclaredFields(): List<Field> {
return list return list
} }
private const val ZERO_BYTE: Byte = 0
fun ByteArray.removeZeroTail(): ByteArray {
var i = this.size - 1
while (this[i] == ZERO_BYTE) {
--i
}
return this.copyOfRange(0, i + 1)
}
\ No newline at end of file
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