Commit 73c700b4 authored by Him188's avatar Him188

Support protocol selecting

parent 91c8c717
...@@ -77,6 +77,10 @@ internal open class QQAndroidClient( ...@@ -77,6 +77,10 @@ internal open class QQAndroidClient(
val device: DeviceInfo = SystemDeviceInfo(context), val device: DeviceInfo = SystemDeviceInfo(context),
bot: QQAndroidBot bot: QQAndroidBot
) { ) {
@Suppress("INVISIBLE_MEMBER")
val subAppId: Long
get() = bot.configuration.protocol.id
internal val serverList: MutableList<Pair<String, Int>> = DefaultServerList.toMutableList() internal val serverList: MutableList<Pair<String, Int>> = DefaultServerList.toMutableList()
val keys: Map<String, ByteArray> by lazy { val keys: Map<String, ByteArray> by lazy {
...@@ -368,7 +372,7 @@ internal class WLoginSigInfo( ...@@ -368,7 +372,7 @@ internal class WLoginSigInfo(
val deviceToken: ByteArray val deviceToken: ByteArray
) { ) {
override fun toString(): String { override fun toString(): String {
return "WLoginSigInfo(uin=$uin, encryptA1=${encryptA1?.toUHexString()}, noPicSig=${noPicSig?.toUHexString()}, G=${G.toUHexString()}, dpwd=${dpwd.toUHexString()}, randSeed=${randSeed.toUHexString()}, simpleInfo=$simpleInfo, appPri=$appPri, a2ExpiryTime=$a2ExpiryTime, loginBitmap=$loginBitmap, tgt=${tgt.toUHexString()}, a2CreationTime=$a2CreationTime, tgtKey=${tgtKey.toUHexString()}, userStSig=$userStSig, userStKey=${userStKey.toUHexString()}, userStWebSig=$userStWebSig, userA5=$userA5, userA8=$userA8, lsKey=$lsKey, sKey=$sKey, userSig64=$userSig64, openId=${openId.toUHexString()}, openKey=$openKey, vKey=$vKey, accessToken=$accessToken, d2=$d2, d2Key=${d2Key.toUHexString()}, sid=$sid, aqSig=$aqSig, psKey=${psKeyMap.toString()}, superKey=${superKey.toUHexString()}, payToken=${payToken.toUHexString()}, pf=${pf.toUHexString()}, pfKey=${pfKey.toUHexString()}, da2=${da2.toUHexString()}, wtSessionTicket=$wtSessionTicket, wtSessionTicketKey=${wtSessionTicketKey.toUHexString()}, deviceToken=${deviceToken.toUHexString()})" return "WLoginSigInfo(uin=$uin, encryptA1=${encryptA1?.toUHexString()}, noPicSig=${noPicSig?.toUHexString()}, G=${G.toUHexString()}, dpwd=${dpwd.toUHexString()}, randSeed=${randSeed.toUHexString()}, simpleInfo=$simpleInfo, appPri=$appPri, a2ExpiryTime=$a2ExpiryTime, loginBitmap=$loginBitmap, tgt=${tgt.toUHexString()}, a2CreationTime=$a2CreationTime, tgtKey=${tgtKey.toUHexString()}, userStSig=$userStSig, userStKey=${userStKey.toUHexString()}, userStWebSig=$userStWebSig, userA5=$userA5, userA8=$userA8, lsKey=$lsKey, sKey=$sKey, userSig64=$userSig64, openId=${openId.toUHexString()}, openKey=$openKey, vKey=$vKey, accessToken=$accessToken, d2=$d2, d2Key=${d2Key.toUHexString()}, sid=$sid, aqSig=$aqSig, psKey=$psKeyMap, superKey=${superKey.toUHexString()}, payToken=${payToken.toUHexString()}, pf=${pf.toUHexString()}, pfKey=${pfKey.toUHexString()}, da2=${da2.toUHexString()}, wtSessionTicket=$wtSessionTicket, wtSessionTicketKey=${wtSessionTicketKey.toUHexString()}, deviceToken=${deviceToken.toUHexString()})"
} }
} }
......
...@@ -159,6 +159,7 @@ internal object HighwayHelper { ...@@ -159,6 +159,7 @@ internal object HighwayHelper {
socket.use { socket.use {
createImageDataPacketSequence( createImageDataPacketSequence(
client = client, client = client,
appId = client.subAppId.toInt(),
command = "PicUp.DataUp", command = "PicUp.DataUp",
commandId = commandId, commandId = commandId,
ticket = ticket, ticket = ticket,
......
...@@ -32,7 +32,7 @@ internal fun createImageDataPacketSequence( ...@@ -32,7 +32,7 @@ internal fun createImageDataPacketSequence(
// RequestDataTrans // RequestDataTrans
client: QQAndroidClient, client: QQAndroidClient,
command: String, command: String,
appId: Int = 537062845, appId: Int,
dataFlag: Int = 4096, dataFlag: Int = 4096,
commandId: Int, commandId: Int,
localId: Int = 2052, localId: Int = 2052,
......
...@@ -83,7 +83,7 @@ internal fun BytePacketBuilder.t18( ...@@ -83,7 +83,7 @@ internal fun BytePacketBuilder.t18(
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
internal fun BytePacketBuilder.t106( internal fun BytePacketBuilder.t106(
appId: Long = 16L, appId: Long = 16L,
subAppId: Long = 537062845L, subAppId: Long,
appClientVersion: Int = 0, appClientVersion: Int = 0,
uin: Long, uin: Long,
n5_always_1: Int = 1, n5_always_1: Int = 1,
...@@ -159,7 +159,7 @@ internal fun BytePacketBuilder.t116( ...@@ -159,7 +159,7 @@ internal fun BytePacketBuilder.t116(
internal fun BytePacketBuilder.t100( internal fun BytePacketBuilder.t100(
appId: Long = 16, appId: Long = 16,
subAppId: Long = 537062845, subAppId: Long,
appClientVersion: Int appClientVersion: Int
) { ) {
writeShort(0x100) writeShort(0x100)
......
...@@ -100,7 +100,7 @@ internal class TroopManagement { ...@@ -100,7 +100,7 @@ internal class TroopManagement {
serviceType = 7, serviceType = 7,
result = 0, result = 0,
bodybuffer = Oidb0x88d.ReqBody( bodybuffer = Oidb0x88d.ReqBody(
appid = 537062845, appid = client.subAppId.toInt(),
stzreqgroupinfo = listOf( stzreqgroupinfo = listOf(
Oidb0x88d.ReqGroupInfo( Oidb0x88d.ReqGroupInfo(
stgroupinfo = Oidb0x88d.GroupInfo( stgroupinfo = Oidb0x88d.GroupInfo(
......
...@@ -25,7 +25,7 @@ internal class Heartbeat { ...@@ -25,7 +25,7 @@ internal class Heartbeat {
operator fun invoke( operator fun invoke(
client: QQAndroidClient client: QQAndroidClient
): OutgoingPacket = buildLoginOutgoingPacket(client, 0, key = NO_ENCRYPT) { ): OutgoingPacket = buildLoginOutgoingPacket(client, 0, key = NO_ENCRYPT) {
writeSsoPacket(client, 537062845, commandName, sequenceId = it) { writeSsoPacket(client, client.subAppId, commandName, sequenceId = it) {
} }
} }
......
...@@ -88,8 +88,6 @@ internal class StatSvc { ...@@ -88,8 +88,6 @@ internal class StatSvc {
override fun toString(): String = "Response(StatSvc.register)" override fun toString(): String = "Response(StatSvc.register)"
} }
private const val subAppId = 537062845L
@OptIn(MiraiInternalAPI::class) @OptIn(MiraiInternalAPI::class)
operator fun invoke( operator fun invoke(
client: QQAndroidClient, client: QQAndroidClient,
...@@ -101,7 +99,7 @@ internal class StatSvc { ...@@ -101,7 +99,7 @@ internal class StatSvc {
key = client.wLoginSigInfo.d2Key key = client.wLoginSigInfo.d2Key
) { sequenceId -> ) { sequenceId ->
writeSsoPacket( writeSsoPacket(
client, subAppId = subAppId, commandName = commandName, client, subAppId = client.subAppId, commandName = commandName,
extraData = client.wLoginSigInfo.tgt.toReadPacket(), sequenceId = sequenceId extraData = client.wLoginSigInfo.tgt.toReadPacket(), sequenceId = sequenceId
) { ) {
writeJceStruct( writeJceStruct(
......
...@@ -32,8 +32,6 @@ internal class WtLogin { ...@@ -32,8 +32,6 @@ internal class WtLogin {
@Suppress("FunctionName") @Suppress("FunctionName")
@OptIn(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class) @OptIn(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class)
internal object Login : OutgoingPacketFactory<Login.LoginPacketResponse>("wtlogin.login") { internal object Login : OutgoingPacketFactory<Login.LoginPacketResponse>("wtlogin.login") {
private const val subAppId = 537062845L
/** /**
* 提交验证码 * 提交验证码
*/ */
...@@ -42,7 +40,7 @@ internal class WtLogin { ...@@ -42,7 +40,7 @@ internal class WtLogin {
client: QQAndroidClient, client: QQAndroidClient,
ticket: String ticket: String
): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId -> ): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId ->
writeSsoPacket(client, subAppId, commandName, sequenceId = sequenceId) { writeSsoPacket(client, client.subAppId, commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) { writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) {
writeShort(2) // subCommand writeShort(2) // subCommand
writeShort(4) // count of TLVs writeShort(4) // count of TLVs
...@@ -59,7 +57,7 @@ internal class WtLogin { ...@@ -59,7 +57,7 @@ internal class WtLogin {
captchaSign: ByteArray, captchaSign: ByteArray,
captchaAnswer: String captchaAnswer: String
): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId -> ): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId ->
writeSsoPacket(client, subAppId, commandName, sequenceId = sequenceId) { writeSsoPacket(client, client.subAppId, commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) { writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) {
writeShort(2) // subCommand writeShort(2) // subCommand
writeShort(4) // count of TLVs writeShort(4) // count of TLVs
...@@ -78,7 +76,7 @@ internal class WtLogin { ...@@ -78,7 +76,7 @@ internal class WtLogin {
client: QQAndroidClient, client: QQAndroidClient,
t402: ByteArray t402: ByteArray
): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId -> ): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId ->
writeSsoPacket(client, subAppId, commandName, sequenceId = sequenceId) { writeSsoPacket(client, client.subAppId, commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) { writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) {
writeShort(20) // subCommand writeShort(20) // subCommand
writeShort(4) // count of TLVs, probably ignored by server? writeShort(4) // count of TLVs, probably ignored by server?
...@@ -100,7 +98,7 @@ internal class WtLogin { ...@@ -100,7 +98,7 @@ internal class WtLogin {
): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId -> ): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId ->
writeSsoPacket( writeSsoPacket(
client, client,
subAppId, client.subAppId,
commandName, commandName,
sequenceId = sequenceId, sequenceId = sequenceId,
unknownHex = "01 00 00 00 00 00 00 00 00 00 01 00" unknownHex = "01 00 00 00 00 00 00 00 00 00 01 00"
...@@ -126,13 +124,12 @@ internal class WtLogin { ...@@ -126,13 +124,12 @@ internal class WtLogin {
*/ */
object SubCommand9 { object SubCommand9 {
private const val appId = 16L private const val appId = 16L
private const val subAppId = 537062845L
@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) @OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class)
operator fun invoke( operator fun invoke(
client: QQAndroidClient client: QQAndroidClient
): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId -> ): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2) { sequenceId ->
writeSsoPacket(client, subAppId, commandName, sequenceId = sequenceId) { writeSsoPacket(client, client.subAppId, commandName, sequenceId = sequenceId) {
writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) { writeOicqRequestPacket(client, EncryptMethodECDH(client.ecdh), 0x0810) {
writeShort(9) // subCommand writeShort(9) // subCommand
writeShort(17) // count of TLVs, probably ignored by server? writeShort(17) // count of TLVs, probably ignored by server?
...@@ -142,7 +139,7 @@ internal class WtLogin { ...@@ -142,7 +139,7 @@ internal class WtLogin {
t1(client.uin, client.device.ipAddress) t1(client.uin, client.device.ipAddress)
t106( t106(
appId, appId,
subAppId /* maybe 1*/, client.subAppId /* maybe 1*/,
client.appClientVersion, client.appClientVersion,
client.uin, client.uin,
1, 1,
...@@ -166,7 +163,7 @@ internal class WtLogin { ...@@ -166,7 +163,7 @@ internal class WtLogin {
if (ConfigManager.get_loginWithPicSt()) appIdList = longArrayOf(1600000226L) if (ConfigManager.get_loginWithPicSt()) appIdList = longArrayOf(1600000226L)
*/ */
t116(client.miscBitMap, client.subSigMap) t116(client.miscBitMap, client.subSigMap)
t100(appId, subAppId, client.appClientVersion) t100(appId, client.subAppId, client.appClientVersion)
t107(0) t107(0)
// t108(byteArrayOf()) // t108(byteArrayOf())
......
...@@ -15,6 +15,7 @@ import net.mamoe.mirai.network.BotNetworkHandler ...@@ -15,6 +15,7 @@ import net.mamoe.mirai.network.BotNetworkHandler
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.coroutineContext import kotlin.coroutines.coroutineContext
import kotlin.jvm.JvmField
import kotlin.jvm.JvmOverloads import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmStatic import kotlin.jvm.JvmStatic
...@@ -75,6 +76,34 @@ open class BotConfiguration { ...@@ -75,6 +76,34 @@ open class BotConfiguration {
*/ */
var loginSolver: LoginSolver = LoginSolver.Default var loginSolver: LoginSolver = LoginSolver.Default
/**
* 使用协议类型
*/
@SinceMirai("1.0.0")
val protocol: MiraiProtocol = MiraiProtocol.ANDROID_PAD
@SinceMirai("1.0.0")
enum class MiraiProtocol(
/** 协议模块使用的 ID */
@JvmField internal val id: Long
) {
/**
* Android 手机.
*
* - 与手机冲突
* - 与平板和电脑不冲突
*/
ANDROID_PHONE(537062845),
/**
* Android 平板.
*
* - 与平板冲突
* - 与手机和电脑不冲突
*/
ANDROID_PAD(537062409)
}
companion object { companion object {
/** /**
* 默认的配置实例 * 默认的配置实例
......
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