From 522db02f34468d96528c2bab0d649b8b0b864a52 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Wed, 13 Apr 2022 03:53:25 +0800 Subject: [PATCH] Changed Finder function --- .../yukihookapi/demo_module/hook/HookEntry.kt | 3 ++ docs/api/public/ConstructorFinder.md | 42 +++++++++++++++++-- docs/api/public/FieldFinder.md | 10 ++--- docs/api/public/HookParam.md | 8 ++-- docs/api/public/MethodFinder.md | 32 ++++++++++---- docs/config/api-exception.md | 29 +++++++++++-- .../hook/core/finder/ConstructorFinder.kt | 19 ++++++--- .../hook/core/finder/FieldFinder.kt | 10 ++--- .../hook/core/finder/MethodFinder.kt | 25 +++++++---- 9 files changed, 133 insertions(+), 45 deletions(-) diff --git a/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt b/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt index 2b45a921..a0d2ea17 100644 --- a/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt +++ b/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt @@ -73,6 +73,7 @@ class HookEntry : YukiHookXposedInitProxy { injectMember { method { name = "getFirstText" + emptyParam() returnType = StringType } // 执行替换 Hook @@ -122,6 +123,7 @@ class HookEntry : YukiHookXposedInitProxy { injectMember { method { name = "toast" + emptyParam() returnType = UnitType } // 拦截整个方法 @@ -137,6 +139,7 @@ class HookEntry : YukiHookXposedInitProxy { injectMember { method { name = "getDataText" + emptyParam() returnType = StringType } // 执行替换 Hook diff --git a/docs/api/public/ConstructorFinder.md b/docs/api/public/ConstructorFinder.md index ec8845c6..0dac2bf7 100644 --- a/docs/api/public/ConstructorFinder.md +++ b/docs/api/public/ConstructorFinder.md @@ -28,7 +28,7 @@ var paramCount: Int 功能描述 -> `Constructor` 参数个数。 +> 设置 `Constructor` 参数个数。 你可以不使用 `param` 指定参数类型而是仅使用此变量指定参数个数。 @@ -46,12 +46,26 @@ fun modifiers(initiate: ModifierRules.() -> Unit): IndexTypeCondition 功能描述 -> `Constructor` 筛选条件。 +> 设置 `Constructor` 标识符筛选条件。 可不设置筛选条件,默认模糊查找并取第一个匹配的 `Constructor`。 !> 存在多个 `IndexTypeCondition` 时除了 `order` 只会生效最后一个。 +### emptyParam [method] + +```kotlin +fun emptyParam(): IndexTypeCondition +``` + +变更记录 + +`v1.0.75` `新增` + +功能描述 + +> 设置 `Constructor` 空参数、无参数。 + ### param [method] ```kotlin @@ -64,16 +78,36 @@ fun param(vararg paramType: Any): IndexTypeCondition 功能描述 -> `Constructor` 参数。 +> 设置 `Constructor` 参数。 如果同时使用了 `paramCount` 则 `paramTypes` 的数量必须与 `paramCount` 完全匹配。 -!> 无参 `Constructor` 不要使用此方法。 +!> 无参 `Constructor` 请使用 `emptyParam` 设置查询条件。 !> 有参 `Constructor` 必须使用此方法设定参数或使用 `paramCount` 指定个数。 !> 存在多个 `IndexTypeCondition` 时除了 `order` 只会生效最后一个。 +### paramCount [method] + +```kotlin +fun paramCount(num: Int): IndexTypeCondition +``` + +变更记录 + +`v1.0.70` `新增` + +功能描述 + +> 设置 `Constructor` 参数个数。 + +你可以不使用 `param` 指定参数类型而是仅使用此方法指定参数个数。 + +若参数个数小于零则忽略并使用 `param`。 + +!> 存在多个 `IndexTypeCondition` 时除了 `order` 只会生效最后一个。 + ### RemedyPlan [class] ```kotlin diff --git a/docs/api/public/FieldFinder.md b/docs/api/public/FieldFinder.md index 684108ab..3193aa7a 100644 --- a/docs/api/public/FieldFinder.md +++ b/docs/api/public/FieldFinder.md @@ -40,7 +40,7 @@ var name: String 功能描述 -> `Field` 名称。 +> 设置 `Field` 名称。 !> 若不填写名称则必须存在一个其它条件。 @@ -56,7 +56,7 @@ var type: Any? 功能描述 -> `Field` 类型。 +> 设置 `Field` 类型。 可不填写类型,默认模糊查找并取第一个匹配的 `Field`。 @@ -72,7 +72,7 @@ fun modifiers(initiate: ModifierRules.() -> Unit): IndexTypeCondition 功能描述 -> `Field` 筛选条件。 +> 设置 `Field` 标识符筛选条件。 可不设置筛选条件,默认模糊查找并取第一个匹配的 `Field`。 @@ -104,7 +104,7 @@ fun name(value: String): IndexTypeCondition 功能描述 -> `Field` 名称。 +> 设置 `Field` 名称。 !> 若不填写名称则必须存在一个其它条件,默认模糊查找并取第一个匹配的 `Field`。 @@ -122,7 +122,7 @@ fun type(value: Any): IndexTypeCondition 功能描述 -> `Field` 类型。 +> 设置 `Field` 类型。 !> 可不填写类型,默认模糊查找并取第一个匹配的 `Field`。 diff --git a/docs/api/public/HookParam.md b/docs/api/public/HookParam.md index 1655cce1..3d6856c1 100644 --- a/docs/api/public/HookParam.md +++ b/docs/api/public/HookParam.md @@ -26,7 +26,7 @@ val args: Array > 获取当前 Hook 对象 `member` 或 `constructor` 的参数对象数组。 -### ~~firstArgs [field]~~ +### ~~firstArgs [field]~~ 变更记录 @@ -36,7 +36,7 @@ val args: Array 请使用 `args(index = 0)` 或 `args().first()` -### ~~lastArgs [field]~~ +### ~~lastArgs [field]~~ 变更记录 @@ -132,7 +132,7 @@ inline fun result(): T? > 获取当前 Hook 对象的 `method` 或 `constructor` 的返回值 `T`。 -### ~~firstArgs [method]~~ +### ~~firstArgs [method]~~ 变更记录 @@ -140,7 +140,7 @@ inline fun result(): T? `v1.0.75` `移除` -### ~~lastArgs [method]~~ +### ~~lastArgs [method]~~ 变更记录 diff --git a/docs/api/public/MethodFinder.md b/docs/api/public/MethodFinder.md index 7972767f..68b2cf90 100644 --- a/docs/api/public/MethodFinder.md +++ b/docs/api/public/MethodFinder.md @@ -32,7 +32,7 @@ var name: String 功能描述 -> `Method` 名称。 +> 设置 `Method` 名称。 !> 若不填写名称则必须存在一个其它条件。 @@ -48,7 +48,7 @@ var paramCount: Int 功能描述 -> `Method` 参数个数。 +> 设置 `Method` 参数个数。 你可以不使用 `param` 指定参数类型而是仅使用此变量指定参数个数。 @@ -66,7 +66,7 @@ var returnType: Any? 功能描述 -> `Method` 返回值,可不填写返回值,默认模糊查找并取第一个匹配的 `Method`。 +> 设置 `Method` 返回值,可不填写返回值,默认模糊查找并取第一个匹配的 `Method`。 ### modifiers [method] @@ -80,12 +80,26 @@ fun modifiers(initiate: ModifierRules.() -> Unit): IndexTypeCondition 功能描述 -> `Method` 筛选条件。 +> 设置 `Method` 标识符筛选条件。 可不设置筛选条件,默认模糊查找并取第一个匹配的 `Method`。 !> 存在多个 `IndexTypeCondition` 时除了 `order` 只会生效最后一个。 +### emptyParam [method] + +```kotlin +fun emptyParam(): IndexTypeCondition +``` + +变更记录 + +`v1.0.75` `新增` + +功能描述 + +> 设置 `Method` 空参数、无参数。 + ### param [method] ```kotlin @@ -98,11 +112,11 @@ fun param(vararg paramType: Any): IndexTypeCondition 功能描述 -> `Method` 参数。 +> 设置 `Method` 参数。 如果同时使用了 `paramCount` 则 `paramTypes` 的数量必须与 `paramCount` 完全匹配。 -!> 无参 `Method` 不要使用此方法。 +!> 无参 `Method` 请使用 `emptyParam` 设置查询条件。 !> 有参 `Method` 必须使用此方法设定参数或使用 `paramCount` 指定个数。 @@ -134,7 +148,7 @@ fun name(value: String): IndexTypeCondition 功能描述 -> `Method` 名称。 +> 设置 `Method` 名称。 !> 若不填写名称则必须存在一个其它条件,默认模糊查找并取第一个匹配的 `Method`。 @@ -152,7 +166,7 @@ fun paramCount(num: Int): IndexTypeCondition 功能描述 -> `Method` 参数个数。 +> 设置 `Method` 参数个数。 你可以不使用 `param` 指定参数类型而是仅使用此方法指定参数个数。 @@ -172,7 +186,7 @@ fun returnType(value: Any): IndexTypeCondition 功能描述 -> `Method` 返回值。 +> 设置 `Method` 返回值。 可不填写返回值,默认模糊查找并取第一个匹配的 `Method`。 diff --git a/docs/config/api-exception.md b/docs/config/api-exception.md index 298aeb6e..3e6bbaf7 100644 --- a/docs/config/api-exception.md +++ b/docs/config/api-exception.md @@ -683,7 +683,7 @@ TargetClass.hook { 你必须在 `hook` 方法体内加入至少一个 `injectMember` 方法。 -!> `IllegalStateException` paramTypes is empty, please delete param() method +!> `IllegalStateException` paramTypes is empty, please use emptyParam() instead 异常原因 @@ -693,11 +693,34 @@ TargetClass.hook { ```kotlin method { - // 没有填写任何参数 + name = "test" + // 括号内没有填写任何参数 param() } ``` 解决方案 -若要标识此方法、构造方法没有参数,你可以什么都不写或设置 `paramCount = 0` 即可。 \ No newline at end of file +若要标识此方法、构造方法没有参数,你可以有如下设置方法。 + +第一种,设置 `emptyParam` (推荐) + +> 示例如下 + +```kotlin +method { + name = "test" + emptyParam() +} +``` + +第二种,设置 `paramCount = 0` + +> 示例如下 + +```kotlin +method { + name = "test" + paramCount = 0 +} +``` \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt index 50e68ec9..dcd9d1f9 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt @@ -65,7 +65,7 @@ class ConstructorFinder( private var modifiers: ModifierRules? = null /** - * [Constructor] 参数个数 + * 设置 [Constructor] 参数个数 * * 你可以不使用 [param] 指定参数类型而是仅使用此变量指定参数个数 * @@ -74,7 +74,7 @@ class ConstructorFinder( var paramCount = -1 /** - * [Constructor] 筛选条件 + * 设置 [Constructor] 标识符筛选条件 * * - ❗存在多个 [BaseFinder.IndexTypeCondition] 时除了 [order] 只会生效最后一个 * @param initiate 方法体 @@ -86,11 +86,18 @@ class ConstructorFinder( } /** - * [Constructor] 参数 + * 设置 [Constructor] 空参数、无参数 + * + * @return [BaseFinder.IndexTypeCondition] + */ + fun emptyParam() = paramCount(num = 0) + + /** + * 设置 [Constructor] 参数 * * 如果同时使用了 [paramCount] 则 [paramTypes] 的数量必须与 [paramCount] 完全匹配 * - * - ❗无参 [Constructor] 不要使用此方法 + * - ❗无参 [Constructor] 请使用 [emptyParam] 设置查询条件 * * - ❗有参 [Constructor] 必须使用此方法设定参数或使用 [paramCount] 指定个数 * @@ -99,7 +106,7 @@ class ConstructorFinder( * @return [BaseFinder.IndexTypeCondition] */ fun param(vararg paramType: Any): IndexTypeCondition { - if (paramType.isEmpty()) error("paramTypes is empty, please delete param() method") + if (paramType.isEmpty()) error("paramTypes is empty, please use emptyParam() instead") paramTypes = ArrayList>().apply { paramType.forEach { add(it.compat() ?: UndefinedType) } }.toTypedArray() return IndexTypeCondition(IndexConfigType.MATCH) } @@ -111,7 +118,7 @@ class ConstructorFinder( fun order() = IndexTypeCondition(IndexConfigType.ORDER) /** - * [Constructor] 参数个数 + * 设置 [Constructor] 参数个数 * * 你可以不使用 [param] 指定参数类型而是仅使用此方法指定参数个数 * diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt index a05c0845..cc7171cf 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt @@ -55,14 +55,14 @@ class FieldFinder( private var modifiers: ModifierRules? = null /** - * [Field] 名称 + * 设置 [Field] 名称 * * - ❗若不填写名称则必须存在一个其它条件 - 默认模糊查找并取第一个匹配的 [Field] */ var name = "" /** - * [Field] 类型 + * 设置 [Field] 类型 * * - ❗只能是 [Class]、[String]、[VariousClass] * @@ -71,7 +71,7 @@ class FieldFinder( var type: Any? = null /** - * [Field] 筛选条件 + * 设置 [Field] 标识符筛选条件 * * 可不设置筛选条件 - 默认模糊查找并取第一个匹配的 [Field] * @@ -91,7 +91,7 @@ class FieldFinder( fun order() = IndexTypeCondition(IndexConfigType.ORDER) /** - * [Field] 名称 + * 设置 [Field] 名称 * * - ❗若不填写名称则必须存在一个其它条件 - 默认模糊查找并取第一个匹配的 [Field] * @@ -105,7 +105,7 @@ class FieldFinder( } /** - * [Field] 类型 + * 设置 [Field] 类型 * * - 可不填写类型 - 默认模糊查找并取第一个匹配的 [Field] * diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt index 36728bf8..ebcd4506 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt @@ -65,14 +65,14 @@ class MethodFinder( private var modifiers: ModifierRules? = null /** - * [Method] 名称 + * 设置 [Method] 名称 * * - ❗若不填写名称则必须存在一个其它条件 - 默认模糊查找并取第一个匹配的 [Method] */ var name = "" /** - * [Method] 参数个数 + * 设置 [Method] 参数个数 * * 你可以不使用 [param] 指定参数类型而是仅使用此变量指定参数个数 * @@ -90,7 +90,7 @@ class MethodFinder( var returnType: Any? = null /** - * [Method] 筛选条件 + * 设置 [Method] 标识符筛选条件 * * 可不设置筛选条件 - 默认模糊查找并取第一个匹配的 [Method] * @@ -104,11 +104,18 @@ class MethodFinder( } /** - * [Method] 参数 + * 设置 [Method] 空参数、无参数 + * + * @return [BaseFinder.IndexTypeCondition] + */ + fun emptyParam() = paramCount(num = 0) + + /** + * 设置 [Method] 参数 * * 如果同时使用了 [paramCount] 则 [paramTypes] 的数量必须与 [paramCount] 完全匹配 * - * - ❗无参 [Method] 不要使用此方法 + * - ❗无参 [Method] 请使用 [emptyParam] 设置查询条件 * * - ❗有参 [Method] 必须使用此方法设定参数或使用 [paramCount] 指定个数 * @@ -117,7 +124,7 @@ class MethodFinder( * @return [BaseFinder.IndexTypeCondition] */ fun param(vararg paramType: Any): IndexTypeCondition { - if (paramType.isEmpty()) error("paramTypes is empty, please delete param() method") + if (paramType.isEmpty()) error("paramTypes is empty, please use emptyParam() instead") paramTypes = ArrayList>().apply { paramType.forEach { add(it.compat() ?: UndefinedType) } }.toTypedArray() return IndexTypeCondition(IndexConfigType.MATCH) } @@ -129,7 +136,7 @@ class MethodFinder( fun order() = IndexTypeCondition(IndexConfigType.ORDER) /** - * [Method] 名称 + * 设置 [Method] 名称 * * - ❗若不填写名称则必须存在一个其它条件 - 默认模糊查找并取第一个匹配的 [Method] * @@ -143,7 +150,7 @@ class MethodFinder( } /** - * [Method] 参数个数 + * 设置 [Method] 参数个数 * * 你可以不使用 [param] 指定参数类型而是仅使用此方法指定参数个数 * @@ -159,7 +166,7 @@ class MethodFinder( } /** - * [Method] 返回值 + * 设置 [Method] 返回值 * * 可不填写返回值 - 默认模糊查找并取第一个匹配的 [Method] *