From 0c131792ac83dd4ddb6854d9678084f1c428741d Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Thu, 12 Jan 2023 23:19:02 +0800 Subject: [PATCH] Modify move createWrapperId function to RandomSeed.createString function in ChannelDataWrapper, YukiHookDataChannel, UtilsFactory --- .../yukihookapi/hook/utils/UtilsFactory.kt | 20 ++++++++++++++++++- .../xposed/channel/YukiHookDataChannel.kt | 7 ++++--- .../data/wrapper/ChannelDataWrapper.kt | 17 +--------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/UtilsFactory.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/UtilsFactory.kt index bff02179..e33bdc2c 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/UtilsFactory.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/UtilsFactory.kt @@ -218,4 +218,22 @@ internal fun T.value() = ModifyValue(value = this) * 可修改变量实现类 * @param value 变量自身实例 */ -internal data class ModifyValue(var value: T) \ No newline at end of file +internal data class ModifyValue(var value: T) + +/** + * 随机种子工具类 + */ +internal object RandomSeed { + + /** 随机字母和数字定义 */ + private const val RANDOM_LETTERS_NUMBERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + + /** + * 生成随机字符串 + * @param length 生成长度 - 默认 15 + * @return [String] + */ + internal fun createString(length: Int = 15) = StringBuilder().apply { + for (i in 1..length) append(RANDOM_LETTERS_NUMBERS[(0..RANDOM_LETTERS_NUMBERS.lastIndex).random()]) + }.toString() +} \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt index 7a3204a4..4c8949a6 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt @@ -47,6 +47,7 @@ import com.highcapable.yukihookapi.hook.log.YukiHookLogger import com.highcapable.yukihookapi.hook.log.YukiLoggerData import com.highcapable.yukihookapi.hook.log.yLoggerE import com.highcapable.yukihookapi.hook.log.yLoggerW +import com.highcapable.yukihookapi.hook.utils.RandomSeed import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication import com.highcapable.yukihookapi.hook.xposed.bridge.YukiXposedModule import com.highcapable.yukihookapi.hook.xposed.channel.data.ChannelData @@ -402,12 +403,12 @@ class YukiHookDataChannel private constructor() { /** * [ChannelData]<[T]> 转换为 [ChannelDataWrapper]<[T]> 实例 - * @param id 包装实例 ID - 默认为 [ChannelDataWrapper.createWrapperId] + * @param id 包装实例 ID - 默认为 [RandomSeed.createString] * @param size 分段数据总大小 (长度) - 默认为 -1 * @param index 分段数据当前接收到的下标 - 默认为 -1 * @return [ChannelDataWrapper]<[T]> */ - private fun ChannelData.toWrapper(id: String = ChannelDataWrapper.createWrapperId(), size: Int = -1, index: Int = -1) = + private fun ChannelData.toWrapper(id: String = RandomSeed.createString(), size: Int = -1, index: Int = -1) = ChannelDataWrapper(id, size > 0, size, index, this) /** @@ -513,7 +514,7 @@ class YukiHookDataChannel private constructor() { private fun parseSendingData(wrapper: ChannelDataWrapper<*>) { if (YukiHookAPI.Configs.isEnableDataChannel.not()) return /** 当前包装实例 ID */ - val wrapperId = ChannelDataWrapper.createWrapperId() + val wrapperId = RandomSeed.createString() /** 当前需要发送的数据字节大小 */ val dataByteSize = wrapper.instance.calDataByteSize() diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/data/wrapper/ChannelDataWrapper.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/data/wrapper/ChannelDataWrapper.kt index be672b08..0d774e16 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/data/wrapper/ChannelDataWrapper.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/data/wrapper/ChannelDataWrapper.kt @@ -29,7 +29,6 @@ package com.highcapable.yukihookapi.hook.xposed.channel.data.wrapper import com.highcapable.yukihookapi.hook.xposed.channel.data.ChannelData import java.io.Serializable -import java.util.* /** * 数据通讯桥键值数据包装类 @@ -45,18 +44,4 @@ internal data class ChannelDataWrapper( val segmentsSize: Int, val segmentsIndex: Int, val instance: ChannelData -) : Serializable { - - internal companion object { - - /** - * 创建新的包装实例 ID - * @return [String] - */ - internal fun createWrapperId() = Random().let { random -> - var randomId = "" - for (i in 0..5) randomId += ((if (random.nextInt(2) % 2 == 0) 65 else 97) + random.nextInt(26)).toChar() - "$randomId${System.currentTimeMillis()}" - } - } -} \ No newline at end of file +) : Serializable \ No newline at end of file