diff --git a/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt b/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt index 226fe0d8e..f897fffe0 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/BotConfiguration.kt @@ -208,24 +208,22 @@ public open class BotConfiguration { // open for Java } @Suppress("ACTUAL_WITHOUT_EXPECT") - public enum class MiraiProtocol constructor( - /** 协议模块使用的 ID */ - @JvmField internal val id: Long - ) { + public enum class MiraiProtocol { /** * Android 手机. */ - ANDROID_PHONE(537066439), + ANDROID_PHONE, /** * Android 平板. */ - ANDROID_PAD(537062409), + ANDROID_PAD, /** * Android 手表. * */ - ANDROID_WATCH(537061176) + ANDROID_WATCH, + } public companion object { diff --git a/mirai-core/src/commonMain/kotlin/network/QQAndroidClient.kt b/mirai-core/src/commonMain/kotlin/network/QQAndroidClient.kt index f2370fd84..14f6ace1d 100644 --- a/mirai-core/src/commonMain/kotlin/network/QQAndroidClient.kt +++ b/mirai-core/src/commonMain/kotlin/network/QQAndroidClient.kt @@ -76,9 +76,10 @@ internal open class QQAndroidClient( val device: DeviceInfo, bot: QQAndroidBot ) { - @Suppress("INVISIBLE_MEMBER") + val protocol = MiraiProtocolInternal[bot.configuration.protocol] + val subAppId: Long - get() = bot.configuration.protocol.id + get() = protocol.id internal val serverList: MutableList> = DefaultServerList.toMutableList() @@ -118,9 +119,10 @@ internal open class QQAndroidClient( var tgtgtKey: ByteArray = generateTgtgtKey(device.guid) val randomKey: ByteArray = getRandomByteArray(16) - var miscBitMap: Int = 184024956 // 也可能是 150470524 ? - private var mainSigMap: Int = 16724722 - var subSigMap: Int = 0x10400 //=66,560 + + val miscBitMap: Int get() = protocol.miscBitMap // 184024956 // 也可能是 150470524 ? + private val mainSigMap: Int = protocol.mainSigMap + var subSigMap: Int = protocol.subSigMap // 0x10400 //=66,560 private val _ssoSequenceId: AtomicInt = atomic(85600) @@ -157,9 +159,12 @@ internal open class QQAndroidClient( var openAppId: Long = 715019303L - val apkVersionName: ByteArray get() = "8.4.18".toByteArray() + val apkVersionName: ByteArray get() = protocol.ver.toByteArray() //"8.4.18".toByteArray() val buildVer: String get() = "8.4.18.4810" // 8.2.0.1296 // 8.4.8.4810 // 8.2.7.4410 + val buildTime: Long get() = protocol.buildTime + val sdkVersion: String get() = protocol.sdkVer + private val messageSequenceId: AtomicInt = atomic(22911) internal fun atomicNextMessageSequenceId(): Int = messageSequenceId.getAndAdd(2) @@ -194,7 +199,7 @@ internal open class QQAndroidClient( var networkType: NetworkType = NetworkType.WIFI - val apkSignatureMd5: ByteArray = "A6 B7 45 BF 24 A2 C2 77 52 77 16 F6 F3 6E B6 8D".hexToBytes() + val apkSignatureMd5: ByteArray get() = protocol.sign.hexToBytes() // "A6 B7 45 BF 24 A2 C2 77 52 77 16 F6 F3 6E B6 8D".hexToBytes() /** * 协议版本?, 8.2.7 的为 8001 diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/Tlv.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/Tlv.kt index 0c22aadfd..20d86e608 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/Tlv.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/Tlv.kt @@ -120,7 +120,7 @@ internal fun BytePacketBuilder.t106( writeByte(isSavePassword.toByte()) writeFully(passwordMd5) writeFully(tgtgtKey) - writeInt(0) + writeInt(0) // wtf writeByte(isGuidAvailable.toByte()) if (isGuidAvailable) { require(guid != null) { "Guid must not be null when isGuidAvailable==true" } @@ -193,7 +193,7 @@ internal fun BytePacketBuilder.t107( internal fun BytePacketBuilder.t108( ksid: ByteArray ) { - require(ksid.size == 16) { "ksid should length 16" } + // require(ksid.size == 16) { "ksid should length 16" } writeShort(0x108) writeShortLVPacket { writeFully(ksid) diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt index 8fb77cd5e..fcfada40c 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt @@ -128,7 +128,7 @@ internal class WtLogin { writeSsoPacket(client, client.subAppId, commandName, sequenceId = sequenceId) { writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) { writeShort(9) // subCommand - writeShort(17) // count of TLVs, probably ignored by server? + writeShort(0x18) // count of TLVs, probably ignored by server? //writeShort(LoginType.PASSWORD.value.toShort()) t18(appId, client.appClientVersion, client.uin) @@ -161,7 +161,8 @@ internal class WtLogin { */ t116(client.miscBitMap, client.subSigMap) t100(appId, client.subAppId, client.appClientVersion, client.ssoVersion) - t107(6) + t107(0) + t108(client.device.imei.toByteArray()) // t108(byteArrayOf()) // ignored: t104() @@ -192,9 +193,11 @@ internal class WtLogin { t145(client.device.guid) t147(appId, client.apkVersionName, client.apkSignatureMd5) + /* if (client.miscBitMap and 0x80 != 0) { t166(1) } + */ // ignored t16a because array5 is null @@ -210,14 +213,14 @@ internal class WtLogin { "connect.qq.com", "qzone.qq.com", "vip.qq.com", + "gamecenter.qq.com", "qun.qq.com", "game.qq.com", "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", - "qzone.com", - "mma.qq.com" + "mma.qq.com", ) ) @@ -243,7 +246,10 @@ internal class WtLogin { t202(bssid, ssid) } - t177() + t177( + buildTime = client.buildTime, + buildVersion = client.sdkVersion, + ) t516() t521() diff --git a/mirai-core/src/commonMain/kotlin/utils/MiraiProtocolInternal.kt b/mirai-core/src/commonMain/kotlin/utils/MiraiProtocolInternal.kt new file mode 100644 index 000000000..9035fcf7e --- /dev/null +++ b/mirai-core/src/commonMain/kotlin/utils/MiraiProtocolInternal.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.internal.utils + +import net.mamoe.mirai.utils.BotConfiguration.MiraiProtocol +import java.util.* + +internal class MiraiProtocolInternal( + @JvmField internal val apkId: String, + @JvmField internal val id: Long, + @JvmField internal val ver: String, + @JvmField internal val sdkVer: String, + @JvmField internal val miscBitMap: Int, + @JvmField internal val subSigMap: Int, + @JvmField internal val mainSigMap: Int, + @JvmField internal val sign: String, + @JvmField internal val buildTime: Long, +) { + internal companion object { + internal val protocols = EnumMap( + MiraiProtocol::class.java + ) + + operator fun get(protocol: MiraiProtocol): MiraiProtocolInternal = + protocols[protocol] ?: error("Internal Error: Missing protocol $protocol") + + init { + protocols[MiraiProtocol.ANDROID_PHONE] = MiraiProtocolInternal( + "com.tencent.mobileqq", + 537066419, + "8.4.18", + "6.0.0.2454", + 184024956, + 0x10400, + 34869472, + "A6 B7 45 BF 24 A2 C2 77 52 77 16 F6 F3 6E B6 8D", + 1604580615L, + ) + protocols[MiraiProtocol.ANDROID_PAD] = MiraiProtocolInternal( + "com.tencent.mobileqq", + 537062409, "8.4.18", + "6.0.0.2454", + 184024956, + 0x10400, + 34869472, + "A6 B7 45 BF 24 A2 C2 77 52 77 16 F6 F3 6E B6 8D", + 1604580615L, + ) + protocols[MiraiProtocol.ANDROID_WATCH] = MiraiProtocolInternal( + "com.tencent.mobileqq", + 537061176, + "8.2.7", + "6.0.0.2413", + 184024956, + 0x10400, + 34869472, + "A6 B7 45 BF 24 A2 C2 77 52 77 16 F6 F3 6E B6 8D", + 1571193922L + ) + } + } +}