From 756fcff0d2fdb707ad1117677535dd0310e36815 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Sun, 3 Apr 2022 12:36:35 +0800 Subject: [PATCH] Fix some bugs --- .../yukihookapi/hook/utils/ReflectionTool.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionTool.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionTool.kt index 6e8aed56..429bf3f4 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionTool.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionTool.kt @@ -52,7 +52,7 @@ internal object ReflectionTool { * @param modifiers 变量描述 * @param type 变量类型 * @return [Field] - * @throws IllegalStateException 如果 [classSet] 为 null + * @throws IllegalStateException 如果 [classSet] 为 null 或未设置任何条件 * @throws NoSuchFieldError 如果找不到变量 */ internal fun findField( @@ -63,11 +63,11 @@ internal object ReflectionTool { modifiers: ModifierRules?, type: Class<*>? ): Field { + 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.findField(hashCode) ?: let { var field: Field? = null - if (orderIndex == null && matchIndex != null && name.isBlank() && modifiers == null && type == null) - error("You must set a condition when finding a Field") classSet?.declaredFields?.apply { var typeIndex = -1 var nameIndex = -1 @@ -155,7 +155,7 @@ internal object ReflectionTool { * @param paramCount 方法参数个数 * @param paramTypes 方法参数类型 * @return [Method] - * @throws IllegalStateException 如果 [classSet] 为 null + * @throws IllegalStateException 如果 [classSet] 为 null 或未设置任何条件 * @throws NoSuchMethodError 如果找不到方法 */ internal fun findMethod( @@ -168,6 +168,8 @@ internal object ReflectionTool { paramCount: Int, paramTypes: Array>? ): Method { + if (orderIndex == null && matchIndex == null && name.isBlank() && modifiers == null && paramCount < 0 && paramTypes == null && returnType == null) + error("You must set a condition when finding a Method") val hashCode = ("[$orderIndex][$matchIndex][$name][$paramCount][${paramTypes.typeOfString()}][$returnType][$modifiers][$classSet]").hashCode() return MemberCacheStore.findMethod(hashCode) ?: let { @@ -286,7 +288,7 @@ internal object ReflectionTool { * @param paramCount 构造方法参数个数 * @param paramTypes 构造方法参数类型 * @return [Constructor] - * @throws IllegalStateException 如果 [classSet] 为 null + * @throws IllegalStateException 如果 [classSet] 为 null 或未设置任何条件 * @throws NoSuchMethodError 如果找不到构造方法 */ internal fun findConstructor( @@ -297,6 +299,8 @@ internal object ReflectionTool { paramCount: Int, paramTypes: Array>? ): Constructor<*> { + if (orderIndex == null && matchIndex == null && paramCount < 0 && paramTypes == null && modifiers == null) + error("You must set a condition when finding a Constructor") val hashCode = ("[$orderIndex][$matchIndex][$paramCount][${paramTypes.typeOfString()}][$modifiers][$classSet]").hashCode() return MemberCacheStore.findConstructor(hashCode) ?: let { var constructor: Constructor<*>? = null