mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-08 19:54:44 +08:00
ProtoBuf test tools
This commit is contained in:
parent
c1785ca4bb
commit
d302c69e8a
@ -60,4 +60,13 @@ dependencies {
|
||||
kotlinx("kotlinx-coroutines-core", coroutinesVersion)
|
||||
|
||||
kotlinx("kotlinx-serialization-runtime", serializationVersion)
|
||||
|
||||
|
||||
ktor("ktor-http-cio", ktorVersion)
|
||||
ktor("ktor-http", ktorVersion)
|
||||
ktor("ktor-client-core-jvm", ktorVersion)
|
||||
ktor("ktor-client-cio", ktorVersion)
|
||||
ktor("ktor-client-core", ktorVersion)
|
||||
ktor("ktor-network", ktorVersion)
|
||||
|
||||
}
|
@ -118,7 +118,7 @@ object PacketDebugger {
|
||||
* 7. 运行完 `mov eax,dword ptr ss:[ebp+10]`
|
||||
* 8. 查看内存, `eax` 到 `eax+10` 的 16 字节就是 `sessionKey`
|
||||
*/
|
||||
val sessionKey: SessionKey = SessionKey("25 DA 6C 27 0B 0B F9 E2 2E 65 46 14 7C 8B 96 F5".hexToBytes())
|
||||
val sessionKey: SessionKey = SessionKey("FF 75 0E 37 92 1C F3 A2 44 77 8A 61 44 29 EA D8".hexToBytes())
|
||||
const val qq: UInt = 1040400290u
|
||||
|
||||
val IgnoredPacketIdList: List<PacketId> = listOf(
|
||||
|
@ -9,48 +9,83 @@ import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import kotlinx.serialization.protobuf.ProtoNumberType
|
||||
import kotlinx.serialization.protobuf.ProtoType
|
||||
import kotlinx.serialization.serializer
|
||||
import net.mamoe.mirai.network.protocol.tim.packet.action.ImageUploadInfo
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import net.mamoe.mirai.utils.ProtoFieldId
|
||||
import net.mamoe.mirai.utils.*
|
||||
import net.mamoe.mirai.utils.io.hexToBytes
|
||||
import net.mamoe.mirai.utils.io.read
|
||||
import net.mamoe.mirai.utils.io.toUHexString
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Serializable
|
||||
data class ProtoTest(
|
||||
@SerialId(1) val string: String,
|
||||
@SerialId(1) val int: Int,
|
||||
@SerialId(1) val boolean: Boolean,
|
||||
@SerialId(1) val short: Short,
|
||||
@SerialId(1) val byte: Byte,
|
||||
//@SerialId(1) val string: String,
|
||||
//@SerialId(1) val int: Int,
|
||||
//@SerialId(1) val boolean: Boolean,
|
||||
//@SerialId(1) val short: Short,
|
||||
//@SerialId(1) val byte: Byte,
|
||||
@SerialId(1) @ProtoType(ProtoNumberType.FIXED) val fixedByte: Byte
|
||||
)
|
||||
|
||||
@UseExperimental(MiraiInternalAPI::class)
|
||||
fun main() {
|
||||
suspend fun main() {
|
||||
//println(ImageId0x03("{CE20C11D-FAAB-6E9B-A685-93072427F942}.png", 0, 0).md5.toUHexString())
|
||||
//return
|
||||
|
||||
/*
|
||||
{
|
||||
02=7B 33 45 46 32 42 37 36 42 2D 43 44 46 38 2D 39 45 35 37 2D 44 39 44 46 2D 33 33 35 44 46 31 42 30 46 43 30 32 7D 2E 70 6E 67,
|
||||
04=87 E5 09 3B,
|
||||
05=D2 C4 C0 B7,
|
||||
06=00 00 00 50,
|
||||
07=43,
|
||||
08=,
|
||||
09=01,
|
||||
B=,
|
||||
14=00 00 00 00,
|
||||
15=00 00 01 ED,
|
||||
16=00 00 02 17,
|
||||
18=00 00 EB 34
|
||||
}
|
||||
*/
|
||||
deserializeTest()
|
||||
return
|
||||
|
||||
println(ProtoFieldId(0x12u))
|
||||
|
||||
intArrayOf(
|
||||
0x5A,
|
||||
0X62,
|
||||
0X6A,
|
||||
0X72
|
||||
).forEach {
|
||||
println(it.toUShort().toUHexString() + " => " + ProtoFieldId(it.toUInt()))
|
||||
}
|
||||
|
||||
println(ProtoBuf.dump(ProtoTest.serializer(), ProtoTest("ss", 1, false, 1, 1, 1)).toUHexString())
|
||||
println(ProtoBuf.dump(ProtoTest.serializer(), ProtoTest(1)).toUHexString())
|
||||
}
|
||||
|
||||
fun deserializeTest() {
|
||||
suspend fun deserializeTest() {
|
||||
println(Http.getURL("http://gchat.qpic.cn/gchatpic_new/1994701021/1994701021-2868483628-39F76532E1AB5CA786D7A51389225385/0?vuin=1994701021&term=255&srvver=26933").remaining)
|
||||
|
||||
val bytes =
|
||||
("08 00 10 00 20 01 2A 1E 0A 10 BF 83 4C 2B 67 47 41 8C 9F DD 6D 8C 8E 95 53 D6 10 04 18 E4 E0 54 20 B0 09 28 9E 0D 30 FB AE A6 F4 07 38 50 48 D8 92 9E CD 0A")
|
||||
"""
|
||||
|
||||
|
||||
10 02 22 4E 08 A0 89 F7 B6 03 10 A2 FF 8C F0 03 18 BB 92 94 BF 08 22 10 63 B1 86 6F 41 3E D9 78 CB CF 53 3E 92 28 5C 58 28 04 30 02 38 20 40 FF 01 48 00 50 01 5A 05 32 36 39 33 33 60 00 68 00 70 00 78 00 80 01 97 04 88 01 ED 03 90 01 04 A0 01 01
|
||||
|
||||
|
||||
|
||||
""".trimIndent().replace("\n", " ").replace("[", "").replace("]", "")
|
||||
.hexToBytes()
|
||||
|
||||
println(ImageUploadInfo::class.loadFrom(bytes))
|
||||
/*
|
||||
00 00 00 07 00 00 00 52 08 01 12 03 98 01 02
|
||||
10 02
|
||||
22 [4E] 08 A0 89 F7 B6 03 10 A2 FF 8C F0 03 18 BB 92 94 BF 08 22 10 64 CF BB 65 00 13 8D B5 58 E2 45 1E EA 65 88 E1 28 04 30 02 38 20 40 FF 01 48 00 50 01 5A 05 32 36 39 33 33 60 00 68 00 70 00 78 00 80 01 97 04 88 01 ED 03 90 01 04 A0 01 01
|
||||
*/
|
||||
|
||||
/*
|
||||
for (i in 0..bytes.size) {
|
||||
try {
|
||||
println(bytes.copyOfRange(i, bytes.size).read { readProtoMap() })
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}*/
|
||||
println(bytes.read { readProtoMap() })
|
||||
}
|
||||
|
||||
@UseExperimental(ImplicitReflectionSerializer::class)
|
||||
|
Loading…
Reference in New Issue
Block a user