mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Desensitize LightAppElem.data
This commit is contained in:
parent
54b3bf405f
commit
149b77c05b
@ -13,9 +13,12 @@ import kotlinx.serialization.Serializable
|
|||||||
import kotlinx.serialization.protobuf.ProtoIntegerType
|
import kotlinx.serialization.protobuf.ProtoIntegerType
|
||||||
import kotlinx.serialization.protobuf.ProtoNumber
|
import kotlinx.serialization.protobuf.ProtoNumber
|
||||||
import kotlinx.serialization.protobuf.ProtoType
|
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.io.ProtoBuf
|
||||||
import net.mamoe.mirai.internal.utils.structureToStringIfAvailable
|
import net.mamoe.mirai.internal.utils.structureToStringIfAvailable
|
||||||
import net.mamoe.mirai.utils.EMPTY_BYTE_ARRAY
|
import net.mamoe.mirai.utils.EMPTY_BYTE_ARRAY
|
||||||
|
import net.mamoe.mirai.utils.unzip
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
internal class ImCommon : ProtoBuf {
|
internal class ImCommon : ProtoBuf {
|
||||||
@ -538,10 +541,26 @@ internal class ImMsgBody : ProtoBuf {
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
internal class LightAppElem(
|
internal class LightAppElem(
|
||||||
|
@NestedStructure(LightAppElemDesensitizer::class)
|
||||||
@ProtoNumber(1) @JvmField val data: ByteArray = EMPTY_BYTE_ARRAY,
|
@ProtoNumber(1) @JvmField val data: ByteArray = EMPTY_BYTE_ARRAY,
|
||||||
@ProtoNumber(2) @JvmField val msgResid: ByteArray = EMPTY_BYTE_ARRAY,
|
@ProtoNumber(2) @JvmField val msgResid: ByteArray = EMPTY_BYTE_ARRAY,
|
||||||
) : ProtoBuf
|
) : ProtoBuf
|
||||||
|
|
||||||
|
internal object LightAppElemDesensitizer : NestedStructureDesensitizer<LightAppElem, ByteArray> {
|
||||||
|
|
||||||
|
// 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
|
@Serializable
|
||||||
internal class LocationInfo(
|
internal class LocationInfo(
|
||||||
@ProtoNumber(1) @JvmField val longitude: Double = 0.0,
|
@ProtoNumber(1) @JvmField val longitude: Double = 0.0,
|
||||||
|
@ -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 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 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.
|
* 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<out NestedStructureDesensitizer<*, *>>
|
val serializer: KClass<out NestedStructureDesensitizer<*, *>>
|
||||||
)
|
)
|
||||||
|
|
||||||
internal interface NestedStructureDesensitizer<in C : ProtocolStruct, T : ProtocolStruct> {
|
internal interface NestedStructureDesensitizer<in C : ProtocolStruct, T> {
|
||||||
fun deserialize(context: C, byteArray: ByteArray): T?
|
fun deserialize(context: C, byteArray: ByteArray): T?
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user