diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt index 024acbb75..f75d75fc9 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt @@ -13,9 +13,12 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoIntegerType import kotlinx.serialization.protobuf.ProtoNumber import kotlinx.serialization.protobuf.ProtoType +import net.mamoe.mirai.internal.utils.io.NestedStructure +import net.mamoe.mirai.internal.utils.io.NestedStructureDesensitizer import net.mamoe.mirai.internal.utils.io.ProtoBuf import net.mamoe.mirai.internal.utils.structureToStringIfAvailable import net.mamoe.mirai.utils.EMPTY_BYTE_ARRAY +import net.mamoe.mirai.utils.unzip @Serializable internal class ImCommon : ProtoBuf { @@ -538,10 +541,26 @@ internal class ImMsgBody : ProtoBuf { @Serializable internal class LightAppElem( + @NestedStructure(LightAppElemDesensitizer::class) @ProtoNumber(1) @JvmField val data: ByteArray = EMPTY_BYTE_ARRAY, @ProtoNumber(2) @JvmField val msgResid: ByteArray = EMPTY_BYTE_ARRAY, ) : ProtoBuf + internal object LightAppElemDesensitizer : NestedStructureDesensitizer { + + // unzip + override fun deserialize(context: LightAppElem, byteArray: ByteArray): ByteArray { + if (byteArray.isEmpty()) return byteArray + + return when (byteArray[0].toInt()) { + 0 -> byteArrayOf(0) + byteArray.decodeToString(startIndex = 1).toByteArray() + 1 -> byteArrayOf(0) + byteArray.unzip(offset = 1).decodeToString().toByteArray() + else -> error("unknown compression flag=${byteArray[0]}") + } + } + + } + @Serializable internal class LocationInfo( @ProtoNumber(1) @JvmField val longitude: Double = 0.0, diff --git a/mirai-core/src/commonMain/kotlin/utils/io/ProtocolStruct.kt b/mirai-core/src/commonMain/kotlin/utils/io/ProtocolStruct.kt index c3692f328..f4a0686f0 100644 --- a/mirai-core/src/commonMain/kotlin/utils/io/ProtocolStruct.kt +++ b/mirai-core/src/commonMain/kotlin/utils/io/ProtocolStruct.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -21,6 +21,6 @@ internal annotation class NestedStructure( val serializer: KClass> ) -internal interface NestedStructureDesensitizer { +internal interface NestedStructureDesensitizer { fun deserialize(context: C, byteArray: ByteArray): T? } \ No newline at end of file