QQA Debugging update

This commit is contained in:
Him188 2020-01-24 17:45:32 +08:00
parent 9ff1ff604c
commit b1451f664c

View File

@ -203,18 +203,19 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
println("subCommand=$subCommand")
val type = readByte()
println("type=$type")
debugDiscardExact(2)
val tlvMap: Map<Int, ByteArray> = this.readTLVMap()
return when (type.toInt()) {
0 -> onLoginSuccess(bot)
1, 15 -> onErrorMessage()
2 -> onSolveLoginCaptcha(bot)
0 -> onLoginSuccess(tlvMap, bot)
1, 15 -> onErrorMessage(tlvMap)
2 -> onSolveLoginCaptcha(tlvMap, bot)
else -> error("unknown login result type: $type")
}
}
private fun ByteReadPacket.onErrorMessage(): LoginPacketResponse.Error {
discardExact(2)
val tlvMap = readTLVMap()
tlvMap[0x146]?.toReadPacket()?.run {
private fun ByteReadPacket.onErrorMessage(tlvMap: Map<Int, ByteArray>): LoginPacketResponse.Error {
return tlvMap[0x146]?.toReadPacket()?.run {
readShort() // ver
readShort() // code
@ -222,40 +223,37 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
val message = readUShortLVString()
val errorInfo = readUShortLVString()
return LoginPacketResponse.Error(title, message, errorInfo)
LoginPacketResponse.Error(title, message, errorInfo)
} ?: error("Cannot find error message")
}
@UseExperimental(MiraiDebugAPI::class)
suspend fun ByteReadPacket.onSolveLoginCaptcha(bot: QQAndroidBot): LoginPacketResponse.Captcha = this.debugPrint("login验证码解析").run {
val client = bot.client
debugDiscardExact(2)
val tlvMap: Map<Int, ByteArray> = this.readTLVMap()
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
println()
val question = tlvMap[0x165] ?: error("CAPTCHA QUESTION UNKNOWN")
when (question[18].toUHexString()) {
"36" -> {
//图片验证
debugPrint("是一个图片验证码")
val imageData = tlvMap[0x165]
bot.configuration.captchaSolver.invoke(
bot,
(tlvMap[0x165] ?: error("Captcha Image Data Not Found")).toIoBuffer()
)
}
else -> {
error("UNKNOWN CAPTCHA QUESTION: $question")
suspend fun ByteReadPacket.onSolveLoginCaptcha(tlvMap: Map<Int, ByteArray>, bot: QQAndroidBot): LoginPacketResponse.Captcha =
this.debugPrint("login验证码解析").run {
val client = bot.client
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
println()
val question = tlvMap[0x165] ?: error("CAPTCHA QUESTION UNKNOWN")
when (question[18].toUHexString()) {
"36" -> {
//图片验证
debugPrint("是一个图片验证码")
val imageData = tlvMap[0x165]
bot.configuration.captchaSolver.invoke(
bot,
(tlvMap[0x165] ?: error("Captcha Image Data Not Found")).toIoBuffer()
)
}
else -> {
error("UNKNOWN CAPTCHA QUESTION: $question")
}
}
return TODO()
}
return TODO()
}
@UseExperimental(MiraiDebugAPI::class)
private fun ByteReadPacket.onLoginSuccess(bot: QQAndroidBot): LoginPacketResponse.Success {
private fun ByteReadPacket.onLoginSuccess(tlvMap: Map<Int, ByteArray>, bot: QQAndroidBot): LoginPacketResponse.Success {
val client = bot.client
debugDiscardExact(2)
val tlvMap: Map<Int, ByteArray> = this.readTLVMap()
println("TLV KEYS: " + tlvMap.keys.joinToString { it.contentToString() })
tlvMap[0x150]?.let { client.analysisTlv150(it) }