Bläddra i källkod

fix: qrcode login (#2708)

* fix: uri

* update: macos 6.8.2.21241

* add: pc (macos) t544

* add: protocol value

* add: protocol supported check

* fix: name
cssxsh 2 år sedan
förälder
incheckning
cb3dc9f897

+ 2 - 2
mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt

@@ -92,8 +92,8 @@ public class StandardCharImageLoginSolver
                     }
                     }
 
 
                     tempFile.writeBytes(data)
                     tempFile.writeBytes(data)
-                    logger.info { "[QRCodeLogin] 将会显示二维码图片,若看不清图片,请查看文件 file://${tempFile.absolutePath}" }
-                    logger.info { "[QRCodeLogin] Displaying qrcode image. If not clear, view file file://${tempFile.absolutePath}." }
+                    logger.info { "[QRCodeLogin] 将会显示二维码图片,若看不清图片,请查看文件 ${tempFile.toPath().toUri()}" }
+                    logger.info { "[QRCodeLogin] Displaying qrcode image. If not clear, view file ${tempFile.toPath().toUri()}." }
                 } catch (e: Exception) {
                 } catch (e: Exception) {
                     logger.warning("[QRCodeLogin] 无法写出二维码图片. 请尽量关闭终端个性化样式后扫描二维码字符图片", e)
                     logger.warning("[QRCodeLogin] 无法写出二维码图片. 请尽量关闭终端个性化样式后扫描二维码字符图片", e)
                     logger.warning(
                     logger.warning(

+ 3 - 3
mirai-core/src/commonMain/kotlin/network/QQAndroidClient.kt

@@ -21,6 +21,7 @@ import net.mamoe.mirai.internal.network.components.AccountSecrets
 import net.mamoe.mirai.internal.network.components.SsoSession
 import net.mamoe.mirai.internal.network.components.SsoSession
 import net.mamoe.mirai.internal.network.protocol.data.jce.FileStoragePushFSSvcList
 import net.mamoe.mirai.internal.network.protocol.data.jce.FileStoragePushFSSvcList
 import net.mamoe.mirai.internal.network.protocol.packet.Tlv
 import net.mamoe.mirai.internal.network.protocol.packet.Tlv
+import net.mamoe.mirai.internal.spi.EncryptService
 import net.mamoe.mirai.internal.utils.AtomicIntSeq
 import net.mamoe.mirai.internal.utils.AtomicIntSeq
 import net.mamoe.mirai.internal.utils.MiraiProtocolInternal
 import net.mamoe.mirai.internal.utils.MiraiProtocolInternal
 import net.mamoe.mirai.internal.utils.NetworkType
 import net.mamoe.mirai.internal.utils.NetworkType
@@ -82,9 +83,8 @@ internal open class QQAndroidClient(
     override var outgoingPacketSessionId: ByteArray = 0x02B05B8B.toByteArray()
     override var outgoingPacketSessionId: ByteArray = 0x02B05B8B.toByteArray()
     override var loginState = 0
     override var loginState = 0
 
 
-    val useAndroid by lazy {
-        bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
-                bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
+    val supportedEncrypt by lazy {
+        EncryptService.instance?.supports(bot.configuration.protocol) ?: false
     }
     }
     var onlineStatus: OnlineStatus = OnlineStatus.ONLINE
     var onlineStatus: OnlineStatus = OnlineStatus.ONLINE
 
 

+ 4 - 0
mirai-core/src/commonMain/kotlin/network/protocol/packet/Tlv.kt

@@ -966,6 +966,7 @@ internal fun TlvMapWriter.t548(
 
 
 internal fun TlvMapWriter.t544ForToken( // 1348
 internal fun TlvMapWriter.t544ForToken( // 1348
     uin: Long,
     uin: Long,
+    protocol: BotConfiguration.MiraiProtocol,
     guid: ByteArray,
     guid: ByteArray,
     sdkVersion: String,
     sdkVersion: String,
     subCommandId: Int,
     subCommandId: Int,
@@ -984,6 +985,7 @@ internal fun TlvMapWriter.t544ForToken( // 1348
         }.use { dataIn ->
         }.use { dataIn ->
             service.encryptTlv(EncryptServiceContext(uin, buildTypeSafeMap {
             service.encryptTlv(EncryptServiceContext(uin, buildTypeSafeMap {
                 set(EncryptServiceContext.KEY_COMMAND_STR, commandStr)
                 set(EncryptServiceContext.KEY_COMMAND_STR, commandStr)
+                set(EncryptServiceContext.KEY_BOT_PROTOCOL, protocol)
             }), 0x544, dataIn.readBytes())
             }), 0x544, dataIn.readBytes())
         }.let { result ->
         }.let { result ->
             writeFully(result ?: "".toByteArray()) // Empty str means native throws exception
             writeFully(result ?: "".toByteArray()) // Empty str means native throws exception
@@ -993,6 +995,7 @@ internal fun TlvMapWriter.t544ForToken( // 1348
 
 
 internal fun TlvMapWriter.t544ForVerify( // 1348
 internal fun TlvMapWriter.t544ForVerify( // 1348
     uin: Long,
     uin: Long,
+    protocol: BotConfiguration.MiraiProtocol,
     guid: ByteArray,
     guid: ByteArray,
     sdkVersion: String,
     sdkVersion: String,
     subCommandId: Int,
     subCommandId: Int,
@@ -1008,6 +1011,7 @@ internal fun TlvMapWriter.t544ForVerify( // 1348
         }.use { dataIn ->
         }.use { dataIn ->
             service.encryptTlv(EncryptServiceContext(uin, buildTypeSafeMap {
             service.encryptTlv(EncryptServiceContext(uin, buildTypeSafeMap {
                 set(EncryptServiceContext.KEY_COMMAND_STR, commandStr)
                 set(EncryptServiceContext.KEY_COMMAND_STR, commandStr)
+                set(EncryptServiceContext.KEY_BOT_PROTOCOL, protocol)
             }), 0x544, dataIn.readBytes())
             }), 0x544, dataIn.readBytes())
         }.let { result ->
         }.let { result ->
             writeFully(result ?: "".toByteArray()) // Empty str means native throws exception
             writeFully(result ?: "".toByteArray()) // Empty str means native throws exception

+ 2 - 1
mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLogin10.kt

@@ -85,9 +85,10 @@ internal object WtLogin10 : WtLoginExt {
                     t194(client.device.imsiMd5)
                     t194(client.device.imsiMd5)
                     t511()
                     t511()
                     t202(client.device.wifiBSSID, client.device.wifiSSID)
                     t202(client.device.wifiBSSID, client.device.wifiSSID)
-                    if (client.useAndroid) {
+                    if (client.supportedEncrypt) {
                         t544ForToken(
                         t544ForToken(
                             uin = client.uin,
                             uin = client.uin,
+                            protocol = client.bot.configuration.protocol,
                             guid = client.device.guid,
                             guid = client.device.guid,
                             sdkVersion = client.sdkVersion,
                             sdkVersion = client.sdkVersion,
                             subCommandId = 10,
                             subCommandId = 10,

+ 2 - 1
mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLogin15.kt

@@ -135,9 +135,10 @@ internal object WtLogin15 : WtLoginExt {
 
 
                 t521() // new
                 t521() // new
                 t525(client.loginExtraData) // new
                 t525(client.loginExtraData) // new
-                if (client.useAndroid) {
+                if (client.supportedEncrypt) {
                     t544ForToken(
                     t544ForToken(
                         uin = client.uin,
                         uin = client.uin,
+                        protocol = client.bot.configuration.protocol,
                         guid = client.device.guid,
                         guid = client.device.guid,
                         sdkVersion = client.sdkVersion,
                         sdkVersion = client.sdkVersion,
                         subCommandId = 15,
                         subCommandId = 15,

+ 4 - 2
mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLogin2.kt

@@ -31,9 +31,10 @@ internal object WtLogin2 : WtLoginExt {
                     t104(client.t104)
                     t104(client.t104)
                     t116(client.miscBitMap, client.subSigMap)
                     t116(client.miscBitMap, client.subSigMap)
                     client.t547?.let { t547(it) }
                     client.t547?.let { t547(it) }
-                    if (client.useAndroid) {
+                    if (client.supportedEncrypt) {
                         t544ForVerify(
                         t544ForVerify(
                             uin = client.uin,
                             uin = client.uin,
+                            protocol = client.bot.configuration.protocol,
                             guid = client.device.guid,
                             guid = client.device.guid,
                             sdkVersion = client.sdkVersion,
                             sdkVersion = client.sdkVersion,
                             subCommandId = 2,
                             subCommandId = 2,
@@ -60,9 +61,10 @@ internal object WtLogin2 : WtLoginExt {
                     t104(client.t104)
                     t104(client.t104)
                     t116(client.miscBitMap, client.subSigMap)
                     t116(client.miscBitMap, client.subSigMap)
                     client.t547?.let { t547(it) }
                     client.t547?.let { t547(it) }
-                    if (client.useAndroid) {
+                    if (client.supportedEncrypt) {
                         t544ForVerify(
                         t544ForVerify(
                             uin = client.uin,
                             uin = client.uin,
+                            protocol = client.bot.configuration.protocol,
                             guid = client.device.guid,
                             guid = client.device.guid,
                             sdkVersion = client.sdkVersion,
                             sdkVersion = client.sdkVersion,
                             subCommandId = 2,
                             subCommandId = 2,

+ 2 - 1
mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLogin7.kt

@@ -41,9 +41,10 @@ internal object WtLogin7 : WtLoginExt {
                     t17c(code.encodeToByteArray())
                     t17c(code.encodeToByteArray())
                     t401(client.G)
                     t401(client.G)
                     t198()
                     t198()
-                    if (client.useAndroid) {
+                    if (client.supportedEncrypt) {
                         t544ForVerify(
                         t544ForVerify(
                             uin = client.uin,
                             uin = client.uin,
+                            protocol = client.bot.configuration.protocol,
                             guid = client.device.guid,
                             guid = client.device.guid,
                             sdkVersion = client.sdkVersion,
                             sdkVersion = client.sdkVersion,
                             subCommandId = 7,
                             subCommandId = 7,

+ 13 - 1
mirai-core/src/commonMain/kotlin/network/protocol/packet/login/wtlogin/WtLogin9.kt

@@ -134,9 +134,10 @@ internal object WtLogin9 : WtLoginExt {
                     // this.build().debugPrint("傻逼")
                     // this.build().debugPrint("傻逼")
 
 
                     // ignored t318 because not logging in by QR
                     // ignored t318 because not logging in by QR
-                    if (client.useAndroid) {
+                    if (client.supportedEncrypt) {
                         t544ForToken(
                         t544ForToken(
                             uin = client.uin,
                             uin = client.uin,
+                            protocol = client.bot.configuration.protocol,
                             guid = client.device.guid,
                             guid = client.device.guid,
                             sdkVersion = client.sdkVersion,
                             sdkVersion = client.sdkVersion,
                             subCommandId = 9,
                             subCommandId = 9,
@@ -197,6 +198,17 @@ internal object WtLogin9 : WtLoginExt {
                     t516()
                     t516()
                     t521(8)
                     t521(8)
                     t318(data.tgtQR)
                     t318(data.tgtQR)
+
+                    if (client.supportedEncrypt) {
+                        t544ForToken(
+                            uin = client.uin,
+                            protocol = client.bot.configuration.protocol,
+                            guid = client.device.guid,
+                            sdkVersion = client.sdkVersion,
+                            subCommandId = 9,
+                            commandStr = "810_9"
+                        )
+                    }
                 }
                 }
             }
             }
         }
         }

+ 9 - 1
mirai-core/src/commonMain/kotlin/spi/EncryptService.kt

@@ -39,8 +39,16 @@ public class EncryptServiceContext @MiraiInternalApi constructor(
  * @since 2.15.0
  * @since 2.15.0
  */
  */
 public interface EncryptService : BaseService {
 public interface EncryptService : BaseService {
+
+    /**
+     * Returns `false` if not supported.
+     */
+    public fun supports(protocol: BotConfiguration.MiraiProtocol) : Boolean {
+        return protocol != BotConfiguration.MiraiProtocol.ANDROID_WATCH
+    }
+
     /**
     /**
-     * Returns `null` if not supported.
+     * Returns `null` if encrypt fail.
      */
      */
     public fun encryptTlv(
     public fun encryptTlv(
         context: EncryptServiceContext,
         context: EncryptServiceContext,

+ 4 - 4
mirai-core/src/commonMain/kotlin/utils/MiraiProtocolInternal.kt

@@ -105,15 +105,15 @@ internal class MiraiProtocolInternal(
             )
             )
             protocols[MiraiProtocol.MACOS] = MiraiProtocolInternal(
             protocols[MiraiProtocol.MACOS] = MiraiProtocolInternal(
                 apkId = "com.tencent.qq",
                 apkId = "com.tencent.qq",
-                id = 0x2003ca32,
-                ver = "6.7.9",
-                buildVer = "6.7.9",
+                id = 537128930,
+                ver = "6.8.2",
+                buildVer = "6.8.2.21241",
                 sdkVer = "6.2.0.1023",
                 sdkVer = "6.2.0.1023",
                 miscBitMap = 0x7ffc,
                 miscBitMap = 0x7ffc,
                 subSigMap = 66560,
                 subSigMap = 66560,
                 mainSigMap = 1970400,
                 mainSigMap = 1970400,
                 sign = "com.tencent.qq".encodeToByteArray().toUHexString(" "),
                 sign = "com.tencent.qq".encodeToByteArray().toUHexString(" "),
-                buildTime = 0L,
+                buildTime = 1647227495L,
                 ssoVersion = 7,
                 ssoVersion = 7,
                 appKey = "",
                 appKey = "",
                 supportsQRLogin = true,
                 supportsQRLogin = true,