1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-03 14:20:10 +08:00

Add useAndroid val to QQAndroidClient and rebase to the latest dev branch

This commit is contained in:
sandtechnology 2023-04-15 01:01:12 +08:00 committed by Him188
parent 243872d925
commit 3966b1ae07
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
9 changed files with 106 additions and 127 deletions
mirai-core/src/commonMain/kotlin/network

View File

@ -82,6 +82,10 @@ 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
}
var onlineStatus: OnlineStatus = OnlineStatus.ONLINE
var fileStoragePushFSSvcList: FileStoragePushFSSvcList? = null

View File

@ -382,7 +382,7 @@ internal open class SsoProcessorImpl(
override suspend fun doLogin() = withExceptionCollector {
@Suppress("FunctionName")
fun SSOWtLogin9(allowSlider: Boolean) = when (loginType) {
suspend fun SSOWtLogin9(allowSlider: Boolean) = when (loginType) {
is LoginType.Password -> WtLogin9.Password(client, loginType.passwordMd5.asByteArray, allowSlider)
is LoginType.QRCode -> WtLogin9.QRCode(client, loginType.qrCodeLoginData)
}

View File

@ -98,7 +98,7 @@ internal inline fun <R : Packet?> OutgoingPacketFactory<R>.buildOutgoingUniPacke
}
encryptAndWrite(key) {
writeUniPacket(commandName, client.outgoingPacketSessionId, extraData) {
body(sequenceId)
body(sequenceId)
}
}
}
@ -169,7 +169,7 @@ internal val NO_ENCRYPT: ByteArray = ByteArray(0)
/**
* com.tencent.qphone.base.util.CodecWarpper#encodeRequest(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, byte[], int, int, java.lang.String, byte, byte, byte, byte[], byte[], boolean)
*/
internal inline fun <R : Packet?> OutgoingPacketFactory<R>.buildLoginOutgoingPacket(
internal fun <R : Packet?> OutgoingPacketFactory<R>.buildLoginOutgoingPacket(
client: QQAndroidClient,
bodyType: Byte,
uin: String = client.uin.toString(),
@ -177,7 +177,7 @@ internal inline fun <R : Packet?> OutgoingPacketFactory<R>.buildLoginOutgoingPac
remark: String? = null,
commandName: String = this.commandName,
key: ByteArray = KEY_16_ZEROS,
crossinline body: BytePacketBuilder.(sequenceId: Int) -> Unit
body: BytePacketBuilder.(sequenceId: Int) -> Unit
): OutgoingPacketWithRespType<R> {
val sequenceId: Int = client.nextSsoSequenceId()
@ -208,14 +208,14 @@ internal inline fun <R : Packet?> OutgoingPacketFactory<R>.buildLoginOutgoingPac
private inline val BRP_STUB get() = ByteReadPacket.Empty
internal inline fun BytePacketBuilder.writeSsoPacket(
internal fun BytePacketBuilder.writeSsoPacket(
client: QQAndroidClient,
subAppId: Long,
commandName: String,
extraData: ByteReadPacket = BRP_STUB,
unknownHex: String = "01 00 00 00 00 00 00 00 00 00 01 00",
sequenceId: Int,
crossinline body: BytePacketBuilder.() -> Unit
body: BytePacketBuilder.() -> Unit
) {
/* send

View File

@ -900,7 +900,7 @@ internal fun TlvMapWriter.t525(
}
}
internal suspend fun BytePacketBuilder.t544ForToken( // 1348
internal suspend fun TlvMapWriter.t544ForToken( // 1348
uin: Long,
guid: ByteArray,
sdkVersion: String,
@ -908,19 +908,19 @@ internal suspend fun BytePacketBuilder.t544ForToken( // 1348
commandStr: String
) {
tlv(0x544) {
val dataIn = buildPacket {
writeFully(buildPacket {
writeLong(uin)
}.readBytes(4))
writeShortLVByteArray(guid)
writeShortLVString(sdkVersion)
writeInt(subCommandId)
writeInt(0)
}
runBlocking {
val result = EncryptWorkerService.doTLVEncrypt(uin, 0x544, dataIn.readBytes(), commandStr)
writeFully(result ?: "".toByteArray()) // Empty str means native throws exception
}
val dataIn = buildPacket {
writeFully(buildPacket {
writeLong(uin)
}.readBytes(4))
writeShortLVByteArray(guid)
writeShortLVString(sdkVersion)
writeInt(subCommandId)
writeInt(0)
}
runBlocking {
val result = EncryptWorkerService.doTLVEncrypt(uin, 0x544, dataIn.readBytes(), commandStr)
writeFully(result ?: "".toByteArray()) // Empty str means native throws exception
}
}
}

View File

@ -18,7 +18,6 @@ import net.mamoe.mirai.internal.utils.GuidSource
import net.mamoe.mirai.internal.utils.MacOrAndroidIdChangeFlag
import net.mamoe.mirai.internal.utils.guidFlag
import net.mamoe.mirai.utils._writeTlvMap
import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.generateDeviceInfoData
import net.mamoe.mirai.utils.md5
import net.mamoe.mirai.utils.toReadPacket
@ -47,9 +46,6 @@ internal object WtLogin10 : WtLoginExt {
0x0810
) {
writeShort(11) // subCommand
val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
_writeTlvMap(Short.SIZE_BYTES) {
t100(appId, subAppId, client.appClientVersion, client.ssoVersion, mainSigMap)
t10a(client.wLoginSigInfo.tgt)
@ -88,17 +84,17 @@ val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProt
t194(client.device.imsiMd5)
t511()
t202(client.device.wifiBSSID, client.device.wifiSSID)
if (useAndroid) {
runBlocking {
t544ForToken(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 10,
commandStr = "810_a"
)
}
}
if (client.useAndroid) {
runBlocking {
t544ForToken(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 10,
commandStr = "810_a"
)
}
}
}
}

View File

@ -15,7 +15,6 @@ import net.mamoe.mirai.internal.network.*
import net.mamoe.mirai.internal.network.protocol.packet.*
import net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin
import net.mamoe.mirai.utils._writeTlvMap
import net.mamoe.mirai.utils.BotConfiguration
import kotlin.math.abs
import kotlin.random.Random
@ -39,8 +38,6 @@ internal object WtLogin15 : WtLoginExt {
commandId = 0x0810
) {
writeShort(subCommand) // subCommand
val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
_writeTlvMap {
@ -129,17 +126,17 @@ val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProt
t521() // new
t525(client.loginExtraData) // new
if (useAndroid) {
runBlocking {
t544ForToken(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 15,
commandStr = "810_f"
)
}
}
if (client.useAndroid) {
runBlocking {
t544ForToken(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 15,
commandStr = "810_f"
)
}
}
}
}

View File

@ -10,16 +10,11 @@
package net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin
import io.ktor.utils.io.core.*
ines.runBlocking
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.internal.network.*
import net.mamoe.mirai.internal.network.QQAndroidClient
import net.mamoe.mirai.internal.network.miscBitMap
import net.mamoe.mirai.internal.network.protocol.packet.*
import net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin
import net.mamoe.mirai.internal.network.subAppId
import net.mamoe.mirai.internal.network.subSigMap
import net.mamoe.mirai.utils._writeTlvMap
import net.mamoe.mirai.utils.BotConfiguration
internal object WtLogin2 : WtLoginExt {
@ -30,25 +25,24 @@ internal object WtLogin2 : WtLoginExt {
writeSsoPacket(client, client.subAppId, WtLogin.Login.commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, commandId = 0x0810) {
writeShort(2) // subCommand
val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
_writeTlvMap {
t193(ticket)
t8(2052)
t104(client.t104)
t116(client.miscBitMap, client.subSigMap)
client.t547?.let { t547(it) }
if (useAndroid) {
runBlocking {
t544ForVerify(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 2,
commandStr = "810_2"
)
}
}
if (client.useAndroid) {
runBlocking {
t544ForVerify(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 2,
commandStr = "810_2"
)
}
}
}
@ -64,26 +58,24 @@ internal object WtLogin2 : WtLoginExt {
writeSsoPacket(client, client.subAppId, WtLogin.Login.commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, commandId = 0x0810) {
writeShort(2) // subCommand
val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
_writeTlvMap {
t2(captchaAnswer, captchaSign, 0)
t8(2052)
t104(client.t104)
t116(client.miscBitMap, client.subSigMap)
client.t547?.let { t547(it) }
if (useAndroid) {
runBlocking {
t544ForVerify(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 2,
commandStr = "810_2"
)
}
}
if (client.useAndroid) {
runBlocking {
t544ForVerify(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 2,
commandStr = "810_2"
)
}
}
}
}
}

View File

@ -12,13 +12,8 @@ package net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin
import io.ktor.utils.io.core.*
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.internal.network.*
import net.mamoe.mirai.internal.network.QQAndroidClient
import net.mamoe.mirai.internal.network.miscBitMap
import net.mamoe.mirai.internal.network.protocol.packet.*
import net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin
import net.mamoe.mirai.internal.network.subAppId
import net.mamoe.mirai.internal.network.subSigMap
import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.DeviceVerificationRequests
import net.mamoe.mirai.utils._writeTlvMap
@ -37,9 +32,6 @@ internal object WtLogin7 : WtLoginExt {
writeSsoPacket(client, client.subAppId, WtLogin.Login.commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, commandId = 0x0810) {
writeShort(7) // subCommand
val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
_writeTlvMap {
t8(2052)
@ -49,17 +41,18 @@ val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProt
t17c(code.encodeToByteArray())
t401(client.G)
t198()
if (useAndroid) {
runBlocking {
t544ForVerify(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 7,
commandStr = "810_7"
)
}
}
if (client.useAndroid) {
runBlocking {
t544ForVerify(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 7,
commandStr = "810_7"
)
}
}
}
}
}

View File

@ -15,29 +15,25 @@ import net.mamoe.mirai.internal.network.*
import net.mamoe.mirai.internal.network.protocol.packet.*
import net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin
import net.mamoe.mirai.utils._writeTlvMap
import net.mamoe.mirai.utils.BotConfiguration
internal object WtLogin9 : WtLoginExt {
private const val appId = 16L
fun Password(
client: QQAndroidClient,
passwordMd5: ByteArray,
allowSlider: Boolean
) = WtLogin.Login.buildLoginOutgoingPacket(
client, bodyType = 2, remark = "9:password-login"
) { sequenceId ->
writeSsoPacket(client, client.subAppId, WtLogin.Login.commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, commandId = 0x0810) {
writeShort(9) // subCommand
var tlvCount = if (allowSlider) 0x18 else 0x17;
suspend fun Password(
client: QQAndroidClient,
passwordMd5: ByteArray,
allowSlider: Boolean
) = WtLogin.Login.buildLoginOutgoingPacket(
client, bodyType = 2, remark = "9:password-login"
) { sequenceId ->
writeSsoPacket(client, client.subAppId, WtLogin.Login.commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, commandId = 0x0810) {
writeShort(9) // subCommand
var tlvCount = if (allowSlider) 0x18 else 0x17;
val useEncryptA1AndNoPicSig =
client.wLoginSigInfoInitialized
&& client.wLoginSigInfo.noPicSig != null
&& client.wLoginSigInfo.encryptA1 != null
val useAndroid = client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
client.bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
if (useEncryptA1AndNoPicSig) {
tlvCount++;
}
@ -124,17 +120,18 @@ internal object WtLogin9 : WtLoginExt {
// this.build().debugPrint("傻逼")
// ignored t318 because not logging in by QR
if (useAndroid) {
runBlocking {
t544ForToken(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 9,
commandStr = "810_9"
)
}
}
if (client.useAndroid) {
runBlocking {
t544ForToken(
uin = client.uin,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 9,
commandStr = "810_9"
)
}
}
}
}
}