Skip to content

Commit 0c13179

Browse files
committed
Modify move createWrapperId function to RandomSeed.createString function in ChannelDataWrapper, YukiHookDataChannel, UtilsFactory
1 parent 03432d2 commit 0c13179

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/UtilsFactory.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,22 @@ internal fun <T> T.value() = ModifyValue(value = this)
218218
* 可修改变量实现类
219219
* @param value 变量自身实例
220220
*/
221-
internal data class ModifyValue<T>(var value: T)
221+
internal data class ModifyValue<T>(var value: T)
222+
223+
/**
224+
* 随机种子工具类
225+
*/
226+
internal object RandomSeed {
227+
228+
/** 随机字母和数字定义 */
229+
private const val RANDOM_LETTERS_NUMBERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
230+
231+
/**
232+
* 生成随机字符串
233+
* @param length 生成长度 - 默认 15
234+
* @return [String]
235+
*/
236+
internal fun createString(length: Int = 15) = StringBuilder().apply {
237+
for (i in 1..length) append(RANDOM_LETTERS_NUMBERS[(0..RANDOM_LETTERS_NUMBERS.lastIndex).random()])
238+
}.toString()
239+
}

yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/YukiHookDataChannel.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import com.highcapable.yukihookapi.hook.log.YukiHookLogger
4747
import com.highcapable.yukihookapi.hook.log.YukiLoggerData
4848
import com.highcapable.yukihookapi.hook.log.yLoggerE
4949
import com.highcapable.yukihookapi.hook.log.yLoggerW
50+
import com.highcapable.yukihookapi.hook.utils.RandomSeed
5051
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
5152
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiXposedModule
5253
import com.highcapable.yukihookapi.hook.xposed.channel.data.ChannelData
@@ -402,12 +403,12 @@ class YukiHookDataChannel private constructor() {
402403

403404
/**
404405
* [ChannelData]<[T]> 转换为 [ChannelDataWrapper]<[T]> 实例
405-
* @param id 包装实例 ID - 默认为 [ChannelDataWrapper.createWrapperId]
406+
* @param id 包装实例 ID - 默认为 [RandomSeed.createString]
406407
* @param size 分段数据总大小 (长度) - 默认为 -1
407408
* @param index 分段数据当前接收到的下标 - 默认为 -1
408409
* @return [ChannelDataWrapper]<[T]>
409410
*/
410-
private fun <T> ChannelData<T>.toWrapper(id: String = ChannelDataWrapper.createWrapperId(), size: Int = -1, index: Int = -1) =
411+
private fun <T> ChannelData<T>.toWrapper(id: String = RandomSeed.createString(), size: Int = -1, index: Int = -1) =
411412
ChannelDataWrapper(id, size > 0, size, index, this)
412413

413414
/**
@@ -513,7 +514,7 @@ class YukiHookDataChannel private constructor() {
513514
private fun parseSendingData(wrapper: ChannelDataWrapper<*>) {
514515
if (YukiHookAPI.Configs.isEnableDataChannel.not()) return
515516
/** 当前包装实例 ID */
516-
val wrapperId = ChannelDataWrapper.createWrapperId()
517+
val wrapperId = RandomSeed.createString()
517518

518519
/** 当前需要发送的数据字节大小 */
519520
val dataByteSize = wrapper.instance.calDataByteSize()

yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/xposed/channel/data/wrapper/ChannelDataWrapper.kt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ package com.highcapable.yukihookapi.hook.xposed.channel.data.wrapper
2929

3030
import com.highcapable.yukihookapi.hook.xposed.channel.data.ChannelData
3131
import java.io.Serializable
32-
import java.util.*
3332

3433
/**
3534
* 数据通讯桥键值数据包装类
@@ -45,18 +44,4 @@ internal data class ChannelDataWrapper<T>(
4544
val segmentsSize: Int,
4645
val segmentsIndex: Int,
4746
val instance: ChannelData<T>
48-
) : Serializable {
49-
50-
internal companion object {
51-
52-
/**
53-
* 创建新的包装实例 ID
54-
* @return [String]
55-
*/
56-
internal fun createWrapperId() = Random().let { random ->
57-
var randomId = ""
58-
for (i in 0..5) randomId += ((if (random.nextInt(2) % 2 == 0) 65 else 97) + random.nextInt(26)).toChar()
59-
"$randomId${System.currentTimeMillis()}"
60-
}
61-
}
62-
}
47+
) : Serializable

0 commit comments

Comments
 (0)