mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Modify rename MemberCacheStore to ReflectsCacheStore
This commit is contained in:
@@ -46,7 +46,7 @@ import com.highcapable.yukihookapi.hook.log.*
|
||||
import com.highcapable.yukihookapi.hook.param.PackageParam
|
||||
import com.highcapable.yukihookapi.hook.param.type.HookEntryType
|
||||
import com.highcapable.yukihookapi.hook.param.wrapper.PackageParamWrapper
|
||||
import com.highcapable.yukihookapi.hook.store.MemberCacheStore
|
||||
import com.highcapable.yukihookapi.hook.store.ReflectsCacheStore
|
||||
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
|
||||
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge
|
||||
import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus
|
||||
@@ -255,7 +255,7 @@ object YukiHookAPI {
|
||||
*
|
||||
* 启用后会缓存已经找到的 [Class]、[Method]、[Constructor]、[Field]
|
||||
*
|
||||
* 缓存的 [Member] 都将处于 [MemberCacheStore] 的全局静态实例中
|
||||
* 缓存的 [Member] 都将处于 [ReflectsCacheStore] 的全局静态实例中
|
||||
*
|
||||
* 推荐使用 [MethodFinder]、[ConstructorFinder]、[FieldFinder] 来获取 [Member]
|
||||
*
|
||||
|
@@ -30,7 +30,7 @@ package com.highcapable.yukihookapi.hook.core.reflex.tools
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.ModifierRules
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.NameConditions
|
||||
import com.highcapable.yukihookapi.hook.factory.hasExtends
|
||||
import com.highcapable.yukihookapi.hook.store.MemberCacheStore
|
||||
import com.highcapable.yukihookapi.hook.store.ReflectsCacheStore
|
||||
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
||||
import java.lang.reflect.Constructor
|
||||
import java.lang.reflect.Field
|
||||
@@ -74,7 +74,7 @@ internal object ReflectionTool {
|
||||
if (orderIndex == null && matchIndex == null && name.isBlank() && modifiers == null && type == null)
|
||||
error("You must set a condition when finding a Field")
|
||||
val hashCode = ("[$orderIndex][$matchIndex][$name][$type][$modifiers][$classSet]").hashCode()
|
||||
return MemberCacheStore.findFields(hashCode) ?: let {
|
||||
return ReflectsCacheStore.findFields(hashCode) ?: let {
|
||||
val fields = HashSet<Field>()
|
||||
classSet?.declaredFields?.apply {
|
||||
var typeIndex = -1
|
||||
@@ -135,7 +135,7 @@ internal object ReflectionTool {
|
||||
if (conditions && isMatched) fields.add(it.apply { isAccessible = true })
|
||||
}
|
||||
} ?: error("Can't find this Field [$name] because classSet is null")
|
||||
fields.takeIf { it.isNotEmpty() }?.also { MemberCacheStore.putFields(hashCode, fields) }
|
||||
fields.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putFields(hashCode, fields) }
|
||||
?: if (isFindInSuperClass && classSet.hasExtends)
|
||||
findFields(
|
||||
classSet.superclass,
|
||||
@@ -208,7 +208,7 @@ internal object ReflectionTool {
|
||||
) error("You must set a condition when finding a Method")
|
||||
val hashCode =
|
||||
("[$orderIndex][$matchIndex][$name][$paramCount][${paramTypes.typeOfString()}][$returnType][$modifiers][$classSet]").hashCode()
|
||||
return MemberCacheStore.findMethods(hashCode) ?: let {
|
||||
return ReflectsCacheStore.findMethods(hashCode) ?: let {
|
||||
val methods = HashSet<Method>()
|
||||
classSet?.declaredMethods?.apply {
|
||||
var returnTypeIndex = -1
|
||||
@@ -309,7 +309,7 @@ internal object ReflectionTool {
|
||||
if (conditions && isMatched) methods.add(it.apply { isAccessible = true })
|
||||
}
|
||||
} ?: error("Can't find this Method [$name] because classSet is null")
|
||||
methods.takeIf { it.isNotEmpty() }?.also { MemberCacheStore.putMethods(hashCode, methods) }
|
||||
methods.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putMethods(hashCode, methods) }
|
||||
?: if (isFindInSuperClass && classSet.hasExtends)
|
||||
findMethods(
|
||||
classSet.superclass,
|
||||
@@ -377,7 +377,7 @@ internal object ReflectionTool {
|
||||
paramCountRange.isEmpty() && paramTypes == null
|
||||
) error("You must set a condition when finding a Constructor")
|
||||
val hashCode = ("[$orderIndex][$matchIndex][$paramCount][${paramTypes.typeOfString()}][$modifiers][$classSet]").hashCode()
|
||||
return MemberCacheStore.findConstructors(hashCode) ?: let {
|
||||
return ReflectsCacheStore.findConstructors(hashCode) ?: let {
|
||||
val constructors = HashSet<Constructor<*>>()
|
||||
classSet?.declaredConstructors?.apply {
|
||||
var paramTypeIndex = -1
|
||||
@@ -441,7 +441,7 @@ internal object ReflectionTool {
|
||||
if (conditions && isMatched) constructors.add(it.apply { isAccessible = true })
|
||||
}
|
||||
} ?: error("Can't find this Constructor because classSet is null")
|
||||
return constructors.takeIf { it.isNotEmpty() }?.also { MemberCacheStore.putConstructors(hashCode, constructors) }
|
||||
return constructors.takeIf { it.isNotEmpty() }?.also { ReflectsCacheStore.putConstructors(hashCode, constructors) }
|
||||
?: if (isFindInSuperClass && classSet.hasExtends)
|
||||
findConstructors(
|
||||
classSet.superclass,
|
||||
|
@@ -35,7 +35,7 @@ import com.highcapable.yukihookapi.hook.core.finder.members.ConstructorFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.ModifierRules
|
||||
import com.highcapable.yukihookapi.hook.store.MemberCacheStore
|
||||
import com.highcapable.yukihookapi.hook.store.ReflectsCacheStore
|
||||
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge
|
||||
import com.highcapable.yukihookapi.hook.xposed.bridge.factory.YukiHookHelper
|
||||
import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus
|
||||
@@ -82,7 +82,7 @@ val Class<*>.hasExtends get() = superclass.name != "java.lang.Object"
|
||||
*/
|
||||
fun classOf(name: String, loader: ClassLoader? = null): Class<*> {
|
||||
val hashCode = ("[$name][$loader]").hashCode()
|
||||
return MemberCacheStore.findClass(hashCode) ?: run {
|
||||
return ReflectsCacheStore.findClass(hashCode) ?: run {
|
||||
when {
|
||||
YukiHookBridge.hasXposedBridge ->
|
||||
runCatching { YukiHookHelper.findClass(name, loader) }.getOrNull()
|
||||
@@ -92,7 +92,7 @@ fun classOf(name: String, loader: ClassLoader? = null): Class<*> {
|
||||
}
|
||||
loader == null -> Class.forName(name)
|
||||
else -> loader.loadClass(name)
|
||||
}.also { MemberCacheStore.putClass(hashCode, it) }
|
||||
}.also { ReflectsCacheStore.putClass(hashCode, it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -34,13 +34,13 @@ import java.lang.reflect.Member
|
||||
import java.lang.reflect.Method
|
||||
|
||||
/**
|
||||
* 这是一个全局静态的 [Member] 缓存实例
|
||||
* 这是一个全局静态的 [Class]、[Member] 缓存实例
|
||||
*
|
||||
* 为防止 [Member] 复用过高造成的系统 GC 问题
|
||||
* 为防止 [Class]、[Member] 复用过高造成的系统 GC 问题
|
||||
*
|
||||
* 查询后的 [Member] 在 [YukiHookAPI.Configs.isEnableMemberCache] 启用后自动进入缓存
|
||||
* 查询后的 [Class]、[Member] 在 [YukiHookAPI.Configs.isEnableMemberCache] 启用后自动进入缓存
|
||||
*/
|
||||
internal object MemberCacheStore {
|
||||
internal object ReflectsCacheStore {
|
||||
|
||||
/** 缓存的 [Class] */
|
||||
private val classData = HashMap<Int, Class<*>?>()
|
Reference in New Issue
Block a user