mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-13 11:30:13 +08:00
QQA Debugging update
This commit is contained in:
parent
9353a5af7b
commit
5f16f23c71
@ -36,9 +36,13 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
println("Sending login")
|
println("Sending login")
|
||||||
LoginPacket.SubCommand9(bot.client).sendAndExpect<LoginPacket.LoginPacketResponse>()
|
LoginPacket.SubCommand9(bot.client).sendAndExpect<LoginPacket.LoginPacketResponse>()
|
||||||
println("SessionTicket=${bot.client.wLoginSigInfo.wtSessionTicket.data.toUHexString()}")
|
println("SessionTicket=${bot.client.wLoginSigInfo.wtSessionTicket.data.toUHexString()}")
|
||||||
println("SessionTicketKey=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
|
println("d2key=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
|
||||||
println("SessionTicketKey=${bot.client.wLoginSigInfo.wtSessionTicketKey.toUHexString()}")
|
println("SessionTicketKey=${bot.client.wLoginSigInfo.wtSessionTicketKey.toUHexString()}")
|
||||||
delay(2000)
|
delay(2000)
|
||||||
|
println()
|
||||||
|
println()
|
||||||
|
println()
|
||||||
|
println("Sending ReqRegister")
|
||||||
SvcReqRegisterPacket(bot.client, RegPushReason.setOnlineStatus).sendAndExpect<SvcReqRegisterPacket.Response>()
|
SvcReqRegisterPacket(bot.client, RegPushReason.setOnlineStatus).sendAndExpect<SvcReqRegisterPacket.Response>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import kotlinx.io.core.ByteReadPacket
|
|||||||
import kotlinx.io.core.buildPacket
|
import kotlinx.io.core.buildPacket
|
||||||
import kotlinx.io.core.writeFully
|
import kotlinx.io.core.writeFully
|
||||||
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
||||||
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.PacketId
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.PacketId
|
||||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||||
import net.mamoe.mirai.utils.cryptor.DecrypterByteArray
|
import net.mamoe.mirai.utils.cryptor.DecrypterByteArray
|
||||||
@ -110,10 +111,12 @@ internal inline fun PacketFactory<*>.buildOutgingPacket(
|
|||||||
internal inline fun PacketFactory<*>.buildLoginOutgoingPacket(
|
internal inline fun PacketFactory<*>.buildLoginOutgoingPacket(
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
subAppId: Long,
|
subAppId: Long,
|
||||||
|
bodyType: Byte, // login=2, uni=1
|
||||||
extraData: ByteArray = EMPTY_BYTE_ARRAY,
|
extraData: ByteArray = EMPTY_BYTE_ARRAY,
|
||||||
name: String? = null,
|
name: String? = null,
|
||||||
id: PacketId = this.id,
|
id: PacketId = this.id,
|
||||||
ssoExtraData: ByteReadPacket = BRP_STUB,
|
ssoExtraData: ByteReadPacket = BRP_STUB,
|
||||||
|
key: ByteArray = KEY_16_ZEROS,
|
||||||
body: BytePacketBuilder.(sequenceId: Int) -> Unit
|
body: BytePacketBuilder.(sequenceId: Int) -> Unit
|
||||||
): OutgoingPacket {
|
): OutgoingPacket {
|
||||||
val sequenceId: Int = client.nextSsoSequenceId()
|
val sequenceId: Int = client.nextSsoSequenceId()
|
||||||
@ -121,7 +124,7 @@ internal inline fun PacketFactory<*>.buildLoginOutgoingPacket(
|
|||||||
return OutgoingPacket(name, id, sequenceId, buildPacket {
|
return OutgoingPacket(name, id, sequenceId, buildPacket {
|
||||||
writeIntLVPacket(lengthOffset = { it + 4 }) {
|
writeIntLVPacket(lengthOffset = { it + 4 }) {
|
||||||
writeInt(0x00_00_00_0A)
|
writeInt(0x00_00_00_0A)
|
||||||
writeByte(0x02)
|
writeByte(bodyType)
|
||||||
extraData.let {
|
extraData.let {
|
||||||
writeInt(it.size + 4)
|
writeInt(it.size + 4)
|
||||||
writeFully(it)
|
writeFully(it)
|
||||||
@ -133,12 +136,10 @@ internal inline fun PacketFactory<*>.buildLoginOutgoingPacket(
|
|||||||
writeStringUtf8(it)
|
writeStringUtf8(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptAndWrite(KEY_16_ZEROS) {
|
encryptAndWrite(key) {
|
||||||
writeLoginSsoPacket(client, subAppId, id, ssoExtraData, sequenceId) {
|
|
||||||
body(sequenceId)
|
body(sequenceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +170,7 @@ private val BRP_STUB = ByteReadPacket(EMPTY_BYTE_ARRAY)
|
|||||||
* byte[] body()
|
* byte[] body()
|
||||||
*/
|
*/
|
||||||
@UseExperimental(MiraiInternalAPI::class)
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
private inline fun BytePacketBuilder.writeLoginSsoPacket(
|
internal inline fun BytePacketBuilder.writeLoginSsoPacket(
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
subAppId: Long,
|
subAppId: Long,
|
||||||
packetId: PacketId,
|
packetId: PacketId,
|
||||||
|
@ -68,22 +68,32 @@ internal object KnownPacketFactories : List<PacketFactory<*>> by mutableListOf(
|
|||||||
}
|
}
|
||||||
check(remaining.toInt() == expectedLength) { "Invalid packet length. Expected $expectedLength, got ${rawInput.remaining} Probably packets merged? " }
|
check(remaining.toInt() == expectedLength) { "Invalid packet length. Expected $expectedLength, got ${rawInput.remaining} Probably packets merged? " }
|
||||||
// login
|
// login
|
||||||
when (val flag1 = readInt()) {
|
val flag1 = readInt()
|
||||||
0x0A -> when (val flag2 = readByte().toInt()) {
|
when (val flag2 = readByte().toInt()) {
|
||||||
0x02 -> {
|
0x02 -> {
|
||||||
val flag3 = readByte().toInt()
|
val flag3 = readByte().toInt()
|
||||||
check(flag3 == 0) { "Illegal flag3. Expected 0, got $flag3" }
|
check(flag3 == 0) { "Illegal flag3. Expected 0, got $flag3" }
|
||||||
|
bot.logger.verbose("got uinAccount = " + readString(readInt() - 4)) // uinAccount
|
||||||
bot.logger.verbose(readString(readInt() - 4)) // uinAccount
|
|
||||||
|
|
||||||
//debugPrint("remaining")
|
//debugPrint("remaining")
|
||||||
parseLoginSsoPacket(bot, decryptBy(DECRYPTER_16_ZERO), consumer)
|
|
||||||
}
|
}
|
||||||
else -> error("Illegal flag2. Expected 0x02, got $flag2")
|
else -> error("Illegal flag2. Expected 0x02, got $flag2")
|
||||||
}
|
}
|
||||||
// 00 00 00 60 00 00 00 0B 02 00 00 00 00 0E 31 39 39 34 37 30 31 30 32 31 CE 35 53 19 84 A8 1A B8 5B 48 E3 7C D0 A6 BA 58 6A EB CE 50 B9 A0 98 D5 B9 D0 1C 72 E2 86 24 FC 55 44 6C 6E E3 F9 15 6C EC 6C 6B 94 40 F7 B4 45 CF B4 D0 79 84 FE 30 EA 98 84 44 84 02 32 70 DD D7 07 07 72 DE 87 59 AC
|
when (flag1) {
|
||||||
0x0B ->
|
0x0A -> parseLoginSsoPacket(bot, decryptBy(DECRYPTER_16_ZERO), consumer)
|
||||||
else -> error("Illegal flag1. Expected 0x0A or 0x0B, got $flag1")
|
0x0B -> parseUniPacket(bot, decryptBy(DECRYPTER_16_ZERO), consumer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun parseUniPacket(bot: QQAndroidBot, rawInput: ByteReadPacket, consumer: PacketConsumer) =
|
||||||
|
rawInput.debugIfFail("Login sso packet") {
|
||||||
|
readIoBuffer(readInt() - 4).withUse {
|
||||||
|
//00 01 4E 64 FF FF D8 E8 00 00 00 14 6E 65 65 64 20 41 32 20 61 6E 64 20 49 4D 45 49 00 00 00 04 00 00 00 08 60 7F B6 23 00 00 00 00 00 00 00 04
|
||||||
|
val sequenceId = readInt()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
readIoBuffer(readInt() - 4).withUse {
|
||||||
|
debugPrintln("收到 UniPacket 的 body=${this.readBytes().toUHexString()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>() {
|
|||||||
@UseExperimental(MiraiInternalAPI::class)
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
client: QQAndroidClient
|
client: QQAndroidClient
|
||||||
): OutgoingPacket = buildLoginOutgoingPacket(client, subAppId) { sequenceId ->
|
): OutgoingPacket = buildLoginOutgoingPacket(client, subAppId = subAppId, bodyType = 2) { sequenceId ->
|
||||||
|
writeLoginSsoPacket(client, subAppId, id, sequenceId = sequenceId) {
|
||||||
writeOicqRequestPacket(client, EncryptMethodECDH7(client.ecdh), id) {
|
writeOicqRequestPacket(client, EncryptMethodECDH7(client.ecdh), id) {
|
||||||
writeShort(9) // subCommand
|
writeShort(9) // subCommand
|
||||||
writeShort(17) // count of TLVs, probably ignored by server?
|
writeShort(17) // count of TLVs, probably ignored by server?
|
||||||
@ -169,6 +170,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sealed class LoginPacketResponse : Packet {
|
sealed class LoginPacketResponse : Packet {
|
||||||
@ -335,7 +337,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>() {
|
|||||||
var a1: ByteArray? = null
|
var a1: ByteArray? = null
|
||||||
var noPicSig: ByteArray? = null
|
var noPicSig: ByteArray? = null
|
||||||
tlvMap119[0x531]?.let {
|
tlvMap119[0x531]?.let {
|
||||||
analysisTlv0x531(it){ arg1, arg2 ->
|
analysisTlv0x531(it) { arg1, arg2 ->
|
||||||
a1 = arg1
|
a1 = arg1
|
||||||
noPicSig = arg2
|
noPicSig = arg2
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,9 @@ import net.mamoe.mirai.qqandroid.network.protocol.jce.SvcReqRegister
|
|||||||
import net.mamoe.mirai.qqandroid.network.protocol.jce.writeUniRequestPacket
|
import net.mamoe.mirai.qqandroid.network.protocol.jce.writeUniRequestPacket
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.PacketFactory
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.PacketFactory
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgingPacket
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildLoginOutgoingPacket
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.oidb.oidb0x769.Oidb0x769
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.oidb.oidb0x769.Oidb0x769
|
||||||
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.writeLoginSsoPacket
|
||||||
import net.mamoe.mirai.qqandroid.utils.NetworkType
|
import net.mamoe.mirai.qqandroid.utils.NetworkType
|
||||||
import net.mamoe.mirai.utils.currentTimeSeconds
|
import net.mamoe.mirai.utils.currentTimeSeconds
|
||||||
import net.mamoe.mirai.utils.io.encodeToString
|
import net.mamoe.mirai.utils.io.encodeToString
|
||||||
@ -34,10 +35,23 @@ internal object SvcReqRegisterPacket : PacketFactory<SvcReqRegisterPacket.Respon
|
|||||||
|
|
||||||
internal object Response : Packet
|
internal object Response : Packet
|
||||||
|
|
||||||
|
const val subAppId = 537062845L
|
||||||
|
|
||||||
|
init {
|
||||||
|
_id = PacketId(0, "StatSvc.register")
|
||||||
|
}
|
||||||
|
|
||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
client: QQAndroidClient,
|
client: QQAndroidClient,
|
||||||
regPushReason: RegPushReason = RegPushReason.setOnlineStatus
|
regPushReason: RegPushReason = RegPushReason.setOnlineStatus
|
||||||
): OutgoingPacket = buildOutgingPacket(client, key = client.wLoginSigInfo.d2Key) {
|
): OutgoingPacket = buildLoginOutgoingPacket(
|
||||||
|
client,
|
||||||
|
bodyType = 1,
|
||||||
|
extraData = client.wLoginSigInfo.d2.data,
|
||||||
|
key = client.wLoginSigInfo.d2Key,
|
||||||
|
subAppId = subAppId
|
||||||
|
) { sequenceId ->
|
||||||
|
writeLoginSsoPacket(client, subAppId= subAppId, packetId = id, sequenceId = sequenceId){
|
||||||
writeUniRequestPacket {
|
writeUniRequestPacket {
|
||||||
sServantName = "PushService"
|
sServantName = "PushService"
|
||||||
sFuncName = "SvcReqRegister"
|
sFuncName = "SvcReqRegister"
|
||||||
@ -95,6 +109,7 @@ internal object SvcReqRegisterPacket : PacketFactory<SvcReqRegisterPacket.Respon
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
|
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
|
||||||
return Response
|
return Response
|
||||||
|
@ -20,7 +20,7 @@ internal object TransEmpPacket : PacketFactory<TransEmpPacket.Response>() {
|
|||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
fun SubCommand1(
|
fun SubCommand1(
|
||||||
client: QQAndroidClient
|
client: QQAndroidClient
|
||||||
): OutgoingPacket = buildLoginOutgoingPacket(client, subAppId, ssoExtraData = byteArrayOf().toReadPacket()) {
|
): OutgoingPacket = buildLoginOutgoingPacket(client, bodyType = 2, subAppId = subAppId, ssoExtraData = byteArrayOf().toReadPacket()) {
|
||||||
writeOicqRequestPacket(client, EncryptMethodECDH135(client.ecdh), id) {
|
writeOicqRequestPacket(client, EncryptMethodECDH135(client.ecdh), id) {
|
||||||
|
|
||||||
// oicq.wlogin_sdk.request.trans_emp_1#packTransEmpBody
|
// oicq.wlogin_sdk.request.trans_emp_1#packTransEmpBody
|
||||||
|
Loading…
Reference in New Issue
Block a user