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
This commit is contained in:
cssxsh 2023-06-27 04:30:45 +08:00 committed by GitHub
parent 356f00b54b
commit cb3dc9f897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 16 deletions

View File

@ -92,8 +92,8 @@ public class StandardCharImageLoginSolver
}
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) {
logger.warning("[QRCodeLogin] 无法写出二维码图片. 请尽量关闭终端个性化样式后扫描二维码字符图片", e)
logger.warning(

View File

@ -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.protocol.data.jce.FileStoragePushFSSvcList
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.MiraiProtocolInternal
import net.mamoe.mirai.internal.utils.NetworkType
@ -82,9 +83,8 @@ internal open class QQAndroidClient(
override var outgoingPacketSessionId: ByteArray = 0x02B05B8B.toByteArray()
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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -105,15 +105,15 @@ internal class MiraiProtocolInternal(
)
protocols[MiraiProtocol.MACOS] = MiraiProtocolInternal(
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",
miscBitMap = 0x7ffc,
subSigMap = 66560,
mainSigMap = 1970400,
sign = "com.tencent.qq".encodeToByteArray().toUHexString(" "),
buildTime = 0L,
buildTime = 1647227495L,
ssoVersion = 7,
appKey = "",
supportsQRLogin = true,