From 449158879c71e3278d29cac33501b44e805013c4 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Sat, 31 Dec 2022 02:21:00 +0800 Subject: [PATCH] Added param, type, returnType conditions functions in FieldFinder, MethodFinder, ConstructorFinder, FieldRules, MethodRules, ConstructorRules and fix some bugs in ReflectionTool --- docs-source/src/.vuepress/configs/template.ts | 1 + .../core/finder/base/rules/ObjectRules.md | 27 +++++ .../finder/classes/rules/ConstructorRules.md | 22 ++++ .../core/finder/classes/rules/FieldRules.md | 18 ++- .../core/finder/classes/rules/MethodRules.md | 40 ++++++- .../core/finder/members/ConstructorFinder.md | 24 ++++ .../hook/core/finder/members/FieldFinder.md | 22 ++++ .../hook/core/finder/members/MethodFinder.md | 46 ++++++++ .../core/finder/base/rules/ObjectRules.md | 19 +++ .../finder/classes/rules/ConstructorRules.md | 22 ++++ .../core/finder/classes/rules/FieldRules.md | 18 ++- .../core/finder/classes/rules/MethodRules.md | 40 ++++++- .../core/finder/members/ConstructorFinder.md | 24 ++++ .../hook/core/finder/members/FieldFinder.md | 22 ++++ .../hook/core/finder/members/MethodFinder.md | 46 ++++++++ .../core/finder/base/data/BaseRulesData.kt | 28 +++++ .../core/finder/base/rules/ObjectRules.kt | 55 +++++++++ .../finder/classes/rules/ConstructorRules.kt | 19 +++ .../core/finder/classes/rules/FieldRules.kt | 17 +++ .../core/finder/classes/rules/MethodRules.kt | 38 +++++- .../core/finder/members/ConstructorFinder.kt | 23 ++++ .../hook/core/finder/members/FieldFinder.kt | 21 ++++ .../hook/core/finder/members/MethodFinder.kt | 47 +++++++- .../members/data/ConstructorRulesData.kt | 10 +- .../finder/members/data/FieldRulesData.kt | 13 +- .../finder/members/data/MethodRulesData.kt | 20 +++- .../hook/core/finder/tools/ReflectionTool.kt | 111 ++++++++++++------ .../finder/type/factory/TypeAliasFactory.kt | 9 +- 28 files changed, 745 insertions(+), 57 deletions(-) create mode 100644 docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md create mode 100644 docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md create mode 100644 yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.kt diff --git a/docs-source/src/.vuepress/configs/template.ts b/docs-source/src/.vuepress/configs/template.ts index dbf77d05..aba6da08 100644 --- a/docs-source/src/.vuepress/configs/template.ts +++ b/docs-source/src/.vuepress/configs/template.ts @@ -67,6 +67,7 @@ const navigationLinks = { baseApiPath + 'hook/core/finder/base/rules/CountRules', baseApiPath + 'hook/core/finder/base/rules/ModifierRules', baseApiPath + 'hook/core/finder/base/rules/NameRules', + baseApiPath + 'hook/core/finder/base/rules/ObjectRules', baseApiPath + 'hook/bean/HookClass', baseApiPath + 'hook/bean/VariousClass', baseApiPath + 'hook/bean/CurrentClass', diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md new file mode 100644 index 00000000..942762e5 --- /dev/null +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md @@ -0,0 +1,27 @@ +--- +pageClass: code-page +--- + +::: warning + +The English translation of this page has not been completed, you are welcome to contribute translations to us. + +You can use the **Chrome Translation Plugin** to translate entire pages for reference. + +::: + +# ObjectRules - class + +```kotlin:no-line-numbers +class ObjectRules private constructor(private val instance: Any) +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 这是一个任意对象条件实现类。 + +可对 R8 混淆后的 `Class`、`Member` 进行更加详细的定位。 \ No newline at end of file diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md index 47db110e..00b1db98 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md @@ -98,6 +98,28 @@ fun param(vararg paramType: Any) ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions) +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Constructor` 参数条件。 + +::: danger + +无参 **Constructor** 请使用 **emptyParam** 设置查找条件。 + +有参 **Constructor** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +::: + ## paramCount - method ```kotlin:no-line-numbers diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md index 732ff6b6..19b362cd 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md @@ -82,4 +82,20 @@ fun name(conditions: NameConditions) **Function Illustrate** -> 设置 `Field` 名称条件。 \ No newline at end of file +> 设置 `Field` 名称条件。 + +## type - method + +```kotlin:no-line-numbers +fun type(conditions: ObjectConditions) +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Field` 类型条件。 + +可不填写类型。 \ No newline at end of file diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md index 4c3ba057..1cf52388 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md @@ -128,6 +128,28 @@ fun param(vararg paramType: Any) ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions) +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Method` 参数条件。 + +::: danger + +无参 **Method** 请使用 **emptyParam** 设置查找条件。 + +有参 **Method** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +::: + ## name - method ```kotlin:no-line-numbers @@ -172,4 +194,20 @@ fun paramCount(conditions: CountConditions) > 设置 `Method` 参数个数条件。 -你可以不使用 `param` 指定参数类型而是仅使用此方法指定参数个数条件。 \ No newline at end of file +你可以不使用 `param` 指定参数类型而是仅使用此方法指定参数个数条件。 + +## returnType - method + +```kotlin:no-line-numbers +fun returnType(conditions: ObjectConditions) +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Method` 返回值条件。 + +可不填写返回值。 \ No newline at end of file diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md index b97e5eca..7287cd12 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md @@ -124,6 +124,30 @@ fun param(vararg paramType: Any): IndexTypeCondition ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions): IndexTypeCondition +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Constructor` 参数条件。 + +::: danger + +无参 **Constructor** 请使用 **emptyParam** 设置查找条件。 + +有参 **Constructor** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + ## paramCount - method ```kotlin:no-line-numbers diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md index 1ab8f3cf..394487d8 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md @@ -188,10 +188,32 @@ fun type(value: Any): IndexTypeCondition > 设置 `Field` 类型。 +可不填写类型。 + ::: danger +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + +## type - method + +```kotlin:no-line-numbers +fun type(conditions: ObjectConditions): IndexTypeCondition +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Field` 类型条件。 + 可不填写类型。 +::: danger + 存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 ::: diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md index d9a354b3..d044725d 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md @@ -162,6 +162,30 @@ fun param(vararg paramType: Any): IndexTypeCondition ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions): IndexTypeCondition +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Method` 参数条件。 + +::: danger + +无参 **Method** 请使用 **emptyParam** 设置查找条件。 + +有参 **Method** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + ## order - method ```kotlin:no-line-numbers @@ -314,6 +338,28 @@ fun returnType(value: Any): IndexTypeCondition ::: +## returnType - method + +```kotlin:no-line-numbers +fun returnType(conditions: ObjectConditions): IndexTypeCondition +``` + +**Change Records** + +`v1.1.5` `added` + +**Function Illustrate** + +> 设置 `Method` 返回值条件。 + +可不填写返回值。 + +::: danger + +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + ## superClass - method ```kotlin:no-line-numbers diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md new file mode 100644 index 00000000..c0f505b0 --- /dev/null +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.md @@ -0,0 +1,19 @@ +--- +pageClass: code-page +--- + +# ObjectRules - class + +```kotlin:no-line-numbers +class ObjectRules private constructor(private val instance: Any) +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 这是一个任意对象条件实现类。 + +可对 R8 混淆后的 `Class`、`Member` 进行更加详细的定位。 \ No newline at end of file diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md index 8cadd73f..d99a5d85 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.md @@ -90,6 +90,28 @@ fun param(vararg paramType: Any) ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions) +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Constructor` 参数条件。 + +::: danger + +无参 **Constructor** 请使用 **emptyParam** 设置查找条件。 + +有参 **Constructor** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +::: + ## paramCount - method ```kotlin:no-line-numbers diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md index e399986e..4b37f931 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.md @@ -74,4 +74,20 @@ fun name(conditions: NameConditions) **功能描述** -> 设置 `Field` 名称条件。 \ No newline at end of file +> 设置 `Field` 名称条件。 + +## type - method + +```kotlin:no-line-numbers +fun type(conditions: ObjectConditions) +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Field` 类型条件。 + +可不填写类型。 \ No newline at end of file diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md index 2e4ab656..56439a76 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.md @@ -120,6 +120,28 @@ fun param(vararg paramType: Any) ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions) +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Method` 参数条件。 + +::: danger + +无参 **Method** 请使用 **emptyParam** 设置查找条件。 + +有参 **Method** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +::: + ## name - method ```kotlin:no-line-numbers @@ -164,4 +186,20 @@ fun paramCount(conditions: CountConditions) > 设置 `Method` 参数个数条件。 -你可以不使用 `param` 指定参数类型而是仅使用此方法指定参数个数条件。 \ No newline at end of file +你可以不使用 `param` 指定参数类型而是仅使用此方法指定参数个数条件。 + +## returnType - method + +```kotlin:no-line-numbers +fun returnType(conditions: ObjectConditions) +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Method` 返回值条件。 + +可不填写返回值。 \ No newline at end of file diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md index 855232bb..126a50ea 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.md @@ -116,6 +116,30 @@ fun param(vararg paramType: Any): IndexTypeCondition ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions): IndexTypeCondition +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Constructor` 参数条件。 + +::: danger + +无参 **Constructor** 请使用 **emptyParam** 设置查找条件。 + +有参 **Constructor** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + ## paramCount - method ```kotlin:no-line-numbers diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md index 592a5f5d..9d6e76d1 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.md @@ -180,10 +180,32 @@ fun type(value: Any): IndexTypeCondition > 设置 `Field` 类型。 +可不填写类型。 + ::: danger +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + +## type - method + +```kotlin:no-line-numbers +fun type(conditions: ObjectConditions): IndexTypeCondition +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Field` 类型条件。 + 可不填写类型。 +::: danger + 存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 ::: diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md index 29aaad57..d2cd6157 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.md @@ -154,6 +154,30 @@ fun param(vararg paramType: Any): IndexTypeCondition ::: +## param - method + +```kotlin:no-line-numbers +fun param(conditions: ObjectsConditions): IndexTypeCondition +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Method` 参数条件。 + +::: danger + +无参 **Method** 请使用 **emptyParam** 设置查找条件。 + +有参 **Method** 必须使用此方法设定参数或使用 **paramCount** 指定个数。 + +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + ## order - method ```kotlin:no-line-numbers @@ -306,6 +330,28 @@ fun returnType(value: Any): IndexTypeCondition ::: +## returnType - method + +```kotlin:no-line-numbers +fun returnType(conditions: ObjectConditions): IndexTypeCondition +``` + +**变更记录** + +`v1.1.5` `新增` + +**功能描述** + +> 设置 `Method` 返回值条件。 + +可不填写返回值。 + +::: danger + +存在多个 **IndexTypeCondition** 时除了 **order** 只会生效最后一个。 + +::: + ## superClass - method ```kotlin:no-line-numbers diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/data/BaseRulesData.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/data/BaseRulesData.kt index b638378c..e2a1e3ba 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/data/BaseRulesData.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/data/BaseRulesData.kt @@ -30,9 +30,13 @@ package com.highcapable.yukihookapi.hook.core.finder.base.data import com.highcapable.yukihookapi.hook.core.finder.base.rules.CountRules import com.highcapable.yukihookapi.hook.core.finder.base.rules.ModifierRules import com.highcapable.yukihookapi.hook.core.finder.base.rules.NameRules +import com.highcapable.yukihookapi.hook.core.finder.base.rules.ObjectRules import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions import com.highcapable.yukihookapi.hook.type.defined.VagueType +import java.lang.reflect.Constructor +import java.lang.reflect.Field import java.lang.reflect.Member +import java.lang.reflect.Method /** * 这是 [Class] 与 [Member] 规则查找数据基本类实现 @@ -78,6 +82,30 @@ internal abstract class BaseRulesData internal constructor( */ internal fun Member.cast() = ModifierRules.with(instance = this, uniqueValue) + /** + * [Field.getType] 转换为 [ObjectRules] + * @return [ObjectRules] + */ + internal fun Field.type() = ObjectRules.with(type) + + /** + * [Method.getParameterTypes] 转换为 [ObjectRules] + * @return [ObjectRules] + */ + internal fun Method.paramTypes() = ObjectRules.with(parameterTypes) + + /** + * [Method.getReturnType] 转换为 [ObjectRules] + * @return [ObjectRules] + */ + internal fun Method.returnType() = ObjectRules.with(returnType) + + /** + * [Constructor.getParameterTypes] 转换为 [ObjectRules] + * @return [ObjectRules] + */ + internal fun Constructor<*>.paramTypes() = ObjectRules.with(parameterTypes) + /** * 获取参数数组文本化内容 * @return [String] diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.kt new file mode 100644 index 00000000..b4d45876 --- /dev/null +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/rules/ObjectRules.kt @@ -0,0 +1,55 @@ +/* + * YukiHookAPI - An efficient Kotlin version of the Xposed Hook API. + * Copyright (C) 2019-2022 HighCapable + * https://github.com/fankes/YukiHookAPI + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * This file is Created by fankes on 2022/12/30. + */ +@file:Suppress("unused") + +package com.highcapable.yukihookapi.hook.core.finder.base.rules + +import java.lang.reflect.Member + +/** + * 这是一个任意对象条件实现类 + * + * 可对 R8 混淆后的 [Class]、[Member] 进行更加详细的定位 + * @param instance 当前实例对象 + */ +class ObjectRules private constructor(private val instance: Any) { + + @PublishedApi + internal companion object { + + /** + * 创建实例 + * @param instance 实例对象 + * @return [ObjectRules] + */ + @PublishedApi + internal fun with(instance: Any) = ObjectRules(instance) + } + + override fun toString() = "ObjectRules [$instance]" +} \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.kt index 4fefb07f..d06d1c6e 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/ConstructorRules.kt @@ -35,6 +35,7 @@ import com.highcapable.yukihookapi.hook.core.finder.classes.rules.result.MemberR import com.highcapable.yukihookapi.hook.core.finder.members.data.ConstructorRulesData import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectsConditions import com.highcapable.yukihookapi.hook.type.defined.UndefinedType import com.highcapable.yukihookapi.hook.type.defined.VagueType import java.lang.reflect.Constructor @@ -104,6 +105,24 @@ class ConstructorRules internal constructor(@PublishedApi internal val rulesData arrayListOf>().apply { paramType.forEach { add(it.compat(tag = "Constructor") ?: UndefinedType) } }.toTypedArray() } + /** + * 设置 [Constructor] 参数条件 + * + * 使用示例如下 ↓ + * + * ```kotlin + * param { it[1] == StringClass || it[2].name == "java.lang.String" } + * ``` + * + * - ❗无参 [Constructor] 请使用 [emptyParam] 设置查找条件 + * + * - ❗有参 [Constructor] 必须使用此方法设定参数或使用 [paramCount] 指定个数 + * @param conditions 条件方法体 + */ + fun param(conditions: ObjectsConditions) { + rulesData.paramTypesConditions = conditions + } + /** * 设置 [Constructor] 参数个数范围 * diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.kt index 7ab6cc21..5a8d07b8 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/FieldRules.kt @@ -33,6 +33,7 @@ import com.highcapable.yukihookapi.hook.core.finder.classes.rules.result.MemberR import com.highcapable.yukihookapi.hook.core.finder.members.data.FieldRulesData import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectConditions import java.lang.reflect.Field /** @@ -83,6 +84,22 @@ class FieldRules internal constructor(@PublishedApi internal val rulesData: Fiel rulesData.nameConditions = conditions } + /** + * 设置 [Field] 类型条件 + * + * - 可不填写类型 + * + * 使用示例如下 ↓ + * + * ```kotlin + * type { it == StringClass || it.name == "java.lang.String" } + * ``` + * @param conditions 条件方法体 + */ + fun type(conditions: ObjectConditions) { + rulesData.typeConditions = conditions + } + /** * 返回结果实现类 * @return [MemberRulesResult] diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.kt index 4990fb57..1f6d7e92 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/classes/rules/MethodRules.kt @@ -33,9 +33,7 @@ import com.highcapable.yukihookapi.hook.bean.VariousClass import com.highcapable.yukihookapi.hook.core.finder.classes.rules.base.BaseRules import com.highcapable.yukihookapi.hook.core.finder.classes.rules.result.MemberRulesResult import com.highcapable.yukihookapi.hook.core.finder.members.data.MethodRulesData -import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions -import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions -import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.* import com.highcapable.yukihookapi.hook.type.defined.UndefinedType import com.highcapable.yukihookapi.hook.type.defined.VagueType import java.lang.reflect.Method @@ -129,6 +127,24 @@ class MethodRules internal constructor(@PublishedApi internal val rulesData: Met arrayListOf>().apply { paramType.forEach { add(it.compat(tag = "Method") ?: UndefinedType) } }.toTypedArray() } + /** + * 设置 [Method] 参数条件 + * + * 使用示例如下 ↓ + * + * ```kotlin + * param { it[1] == StringClass || it[2].name == "java.lang.String" } + * ``` + * + * - ❗无参 [Method] 请使用 [emptyParam] 设置查找条件 + * + * - ❗有参 [Method] 必须使用此方法设定参数或使用 [paramCount] 指定个数 + * @param conditions 条件方法体 + */ + fun param(conditions: ObjectsConditions) { + rulesData.paramTypesConditions = conditions + } + /** * 设置 [Method] 名称条件 * @param conditions 条件方法体 @@ -169,6 +185,22 @@ class MethodRules internal constructor(@PublishedApi internal val rulesData: Met rulesData.paramCountConditions = conditions } + /** + * 设置 [Method] 返回值条件 + * + * - 可不填写返回值 + * + * 使用示例如下 ↓ + * + * ```kotlin + * returnType { it == StringClass || it.name == "java.lang.String" } + * ``` + * @param conditions 条件方法体 + */ + fun returnType(conditions: ObjectConditions) { + rulesData.returnTypeConditions = conditions + } + /** * 返回结果实现类 * @return [MemberRulesResult] diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt index 6b07ec22..0f013a63 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt @@ -39,6 +39,7 @@ import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool import com.highcapable.yukihookapi.hook.core.finder.type.factory.ConstructorConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectsConditions import com.highcapable.yukihookapi.hook.factory.checkingInternal import com.highcapable.yukihookapi.hook.factory.hasExtends import com.highcapable.yukihookapi.hook.log.yLoggerW @@ -136,6 +137,28 @@ class ConstructorFinder @PublishedApi internal constructor( return IndexTypeCondition(IndexConfigType.MATCH) } + /** + * 设置 [Constructor] 参数条件 + * + * 使用示例如下 ↓ + * + * ```kotlin + * param { it[1] == StringClass || it[2].name == "java.lang.String" } + * ``` + * + * - ❗无参 [Constructor] 请使用 [emptyParam] 设置查找条件 + * + * - ❗有参 [Constructor] 必须使用此方法设定参数或使用 [paramCount] 指定个数 + * + * - ❗存在多个 [BaseFinder.IndexTypeCondition] 时除了 [order] 只会生效最后一个 + * @param conditions 条件方法体 + * @return [BaseFinder.IndexTypeCondition] + */ + fun param(conditions: ObjectsConditions): IndexTypeCondition { + rulesData.paramTypesConditions = conditions + return IndexTypeCondition(IndexConfigType.MATCH) + } + /** * 顺序筛选字节码的下标 * @return [BaseFinder.IndexTypeCondition] diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt index cabc325d..dcb3a34f 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt @@ -40,6 +40,7 @@ import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool import com.highcapable.yukihookapi.hook.core.finder.type.factory.FieldConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectConditions import com.highcapable.yukihookapi.hook.factory.checkingInternal import com.highcapable.yukihookapi.hook.factory.current import com.highcapable.yukihookapi.hook.factory.hasExtends @@ -157,6 +158,26 @@ class FieldFinder @PublishedApi internal constructor( return IndexTypeCondition(IndexConfigType.MATCH) } + /** + * 设置 [Field] 类型条件 + * + * - 可不填写类型 + * + * 使用示例如下 ↓ + * + * ```kotlin + * type { it == StringClass || it.name == "java.lang.String" } + * ``` + * + * - ❗存在多个 [BaseFinder.IndexTypeCondition] 时除了 [order] 只会生效最后一个 + * @param conditions 条件方法体 + * @return [BaseFinder.IndexTypeCondition] + */ + fun type(conditions: ObjectConditions): IndexTypeCondition { + rulesData.typeConditions = conditions + return IndexTypeCondition(IndexConfigType.MATCH) + } + /** * 设置在 [classSet] 的所有父类中查找当前 [Field] * diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt index c00b3948..2b2bfabc 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt @@ -36,10 +36,7 @@ import com.highcapable.yukihookapi.hook.core.finder.base.BaseFinder import com.highcapable.yukihookapi.hook.core.finder.base.MemberBaseFinder import com.highcapable.yukihookapi.hook.core.finder.members.data.MethodRulesData import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool -import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions -import com.highcapable.yukihookapi.hook.core.finder.type.factory.MethodConditions -import com.highcapable.yukihookapi.hook.core.finder.type.factory.ModifierConditions -import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.* import com.highcapable.yukihookapi.hook.factory.checkingInternal import com.highcapable.yukihookapi.hook.factory.hasExtends import com.highcapable.yukihookapi.hook.log.yLoggerW @@ -166,6 +163,28 @@ class MethodFinder @PublishedApi internal constructor( return IndexTypeCondition(IndexConfigType.MATCH) } + /** + * 设置 [Method] 参数条件 + * + * 使用示例如下 ↓ + * + * ```kotlin + * param { it[1] == StringClass || it[2].name == "java.lang.String" } + * ``` + * + * - ❗无参 [Method] 请使用 [emptyParam] 设置查找条件 + * + * - ❗有参 [Method] 必须使用此方法设定参数或使用 [paramCount] 指定个数 + * + * - ❗存在多个 [BaseFinder.IndexTypeCondition] 时除了 [order] 只会生效最后一个 + * @param conditions 条件方法体 + * @return [BaseFinder.IndexTypeCondition] + */ + fun param(conditions: ObjectsConditions): IndexTypeCondition { + rulesData.paramTypesConditions = conditions + return IndexTypeCondition(IndexConfigType.MATCH) + } + /** * 顺序筛选字节码的下标 * @return [BaseFinder.IndexTypeCondition] @@ -270,6 +289,26 @@ class MethodFinder @PublishedApi internal constructor( return IndexTypeCondition(IndexConfigType.MATCH) } + /** + * 设置 [Method] 返回值条件 + * + * - 可不填写返回值 + * + * 使用示例如下 ↓ + * + * ```kotlin + * returnType { it == StringClass || it.name == "java.lang.String" } + * ``` + * + * - ❗存在多个 [BaseFinder.IndexTypeCondition] 时除了 [order] 只会生效最后一个 + * @param conditions 条件方法体 + * @return [BaseFinder.IndexTypeCondition] + */ + fun returnType(conditions: ObjectConditions): IndexTypeCondition { + rulesData.returnTypeConditions = conditions + return IndexTypeCondition(IndexConfigType.MATCH) + } + /** * 设置在 [classSet] 的所有父类中查找当前 [Method] * diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/ConstructorRulesData.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/ConstructorRulesData.kt index 870917b1..e4cc4f63 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/ConstructorRulesData.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/ConstructorRulesData.kt @@ -28,11 +28,13 @@ package com.highcapable.yukihookapi.hook.core.finder.members.data import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectsConditions import java.lang.reflect.Constructor /** * [Constructor] 规则查找数据类 * @param paramTypes 参数类型数组 + * @param paramTypesConditions 参数类型条件 * @param paramCount 参数个数 * @param paramCountRange 参数个数范围 * @param paramCountConditions 参数个数条件 @@ -40,6 +42,7 @@ import java.lang.reflect.Constructor @PublishedApi internal class ConstructorRulesData internal constructor( var paramTypes: Array>? = null, + var paramTypesConditions: ObjectsConditions? = null, var paramCount: Int = -1, var paramCountRange: IntRange = IntRange.EMPTY, var paramCountConditions: CountConditions? = null @@ -50,16 +53,17 @@ internal class ConstructorRulesData internal constructor( paramCount.takeIf { it >= 0 }?.let { "paramCount:[$it]" } ?: "", paramCountRange.takeIf { it.isEmpty().not() }?.let { "paramCountRange:[$it]" } ?: "", paramCountConditions?.let { "paramCountConditions:[existed]" } ?: "", - paramTypes?.typeOfString()?.let { "paramTypes:[$it]" } ?: "", *super.templates + paramTypes?.typeOfString()?.let { "paramTypes:[$it]" } ?: "", + paramTypesConditions?.let { "paramTypesConditions:[existed]" } ?: "", *super.templates ) override val objectName get() = "Constructor" override val isInitialize - get() = super.isInitializeOfSuper || paramTypes != null || paramCount >= 0 || + get() = super.isInitializeOfSuper || paramTypes != null || paramTypesConditions != null || paramCount >= 0 || paramCountRange.isEmpty().not() || paramCountConditions != null override fun hashCode(other: Any?) = super.hashCode(other) + toString().hashCode() - override fun toString() = "[$paramTypes][$paramCount][$paramCountRange]" + override fun toString() = "[$paramTypes][$paramTypesConditions][$paramCount][$paramCountRange]" } \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/FieldRulesData.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/FieldRulesData.kt index 19356274..d1391723 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/FieldRulesData.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/FieldRulesData.kt @@ -28,6 +28,7 @@ package com.highcapable.yukihookapi.hook.core.finder.members.data import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectConditions import java.lang.reflect.Field /** @@ -35,26 +36,30 @@ import java.lang.reflect.Field * @param name 名称 * @param nameConditions 名称规则 * @param type 类型 + * @param typeConditions 类型条件 */ @PublishedApi internal class FieldRulesData internal constructor( var name: String = "", var nameConditions: NameConditions? = null, - var type: Any? = null + var type: Any? = null, + var typeConditions: ObjectConditions? = null ) : MemberRulesData() { override val templates get() = arrayOf( name.takeIf { it.isNotBlank() }?.let { "name:[$it]" } ?: "", nameConditions?.let { "nameConditions:[existed]" } ?: "", - type?.let { "type:[$it]" } ?: "", *super.templates + type?.let { "type:[$it]" } ?: "", + typeConditions?.let { "typeConditions:[existed]" } ?: "", *super.templates ) override val objectName get() = "Field" - override val isInitialize get() = super.isInitializeOfSuper || name.isNotBlank() || nameConditions != null || type != null + override val isInitialize + get() = super.isInitializeOfSuper || name.isNotBlank() || nameConditions != null || type != null || typeConditions != null override fun hashCode(other: Any?) = super.hashCode(other) + toString().hashCode() - override fun toString() = "[$name][$nameConditions][$type]" + override fun toString() = "[$name][$nameConditions][$type][$typeConditions]" } \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/MethodRulesData.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/MethodRulesData.kt index 58d3200c..8f8747bd 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/MethodRulesData.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/members/data/MethodRulesData.kt @@ -29,6 +29,8 @@ package com.highcapable.yukihookapi.hook.core.finder.members.data import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectConditions +import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectsConditions import java.lang.reflect.Method /** @@ -36,20 +38,24 @@ import java.lang.reflect.Method * @param name 名称 * @param nameConditions 名称规则 * @param paramTypes 参数类型数组 + * @param paramTypesConditions 参数类型条件 * @param paramCount 参数个数 * @param paramCountRange 参数个数范围 * @param paramCountConditions 参数个数条件 * @param returnType 返回值类型 + * @param returnTypeConditions 返回值类型条件 */ @PublishedApi internal class MethodRulesData internal constructor( var name: String = "", var nameConditions: NameConditions? = null, var paramTypes: Array>? = null, + var paramTypesConditions: ObjectsConditions? = null, var paramCount: Int = -1, var paramCountRange: IntRange = IntRange.EMPTY, var paramCountConditions: CountConditions? = null, - var returnType: Any? = null + var returnType: Any? = null, + var returnTypeConditions: ObjectConditions? = null ) : MemberRulesData() { override val templates @@ -60,16 +66,20 @@ internal class MethodRulesData internal constructor( paramCountRange.takeIf { it.isEmpty().not() }?.let { "paramCountRange:[$it]" } ?: "", paramCountConditions?.let { "paramCountConditions:[existed]" } ?: "", paramTypes?.typeOfString()?.let { "paramTypes:[$it]" } ?: "", - returnType?.let { "returnType:[$it]" } ?: "", *super.templates + paramTypesConditions?.let { "paramTypesConditions:[existed]" } ?: "", + returnType?.let { "returnType:[$it]" } ?: "", + returnTypeConditions?.let { "returnTypeConditions:[existed]" } ?: "", *super.templates ) override val objectName get() = "Method" override val isInitialize - get() = super.isInitializeOfSuper || name.isNotBlank() || nameConditions != null || paramTypes != null || - paramCount >= 0 || paramCountRange.isEmpty().not() || paramCountConditions != null || returnType != null + get() = super.isInitializeOfSuper || name.isNotBlank() || nameConditions != null || paramTypes != null || paramTypesConditions != null || + paramCount >= 0 || paramCountRange.isEmpty().not() || paramCountConditions != null || + returnType != null || returnTypeConditions != null override fun hashCode(other: Any?) = super.hashCode(other) + toString().hashCode() - override fun toString() = "[$name][$nameConditions][$paramTypes][$paramCount][$paramCountRange][$returnType]" + override fun toString() = "[$name][$nameConditions][$paramTypes][$paramTypesConditions][$paramCount]" + + "[$paramCountRange][$returnType][$returnTypeConditions]" } \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt index 0a468ab2..0a36e409 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt @@ -30,7 +30,6 @@ package com.highcapable.yukihookapi.hook.core.finder.tools import com.highcapable.yukihookapi.hook.core.finder.base.data.BaseRulesData -import com.highcapable.yukihookapi.hook.core.finder.base.rules.CountRules import com.highcapable.yukihookapi.hook.core.finder.classes.data.ClassRulesData import com.highcapable.yukihookapi.hook.core.finder.members.data.ConstructorRulesData import com.highcapable.yukihookapi.hook.core.finder.members.data.FieldRulesData @@ -45,9 +44,7 @@ import com.highcapable.yukihookapi.hook.type.java.DalvikBaseDexClassLoader import com.highcapable.yukihookapi.hook.type.java.NoClassDefFoundErrorClass import com.highcapable.yukihookapi.hook.type.java.NoSuchFieldErrorClass import com.highcapable.yukihookapi.hook.type.java.NoSuchMethodErrorClass -import com.highcapable.yukihookapi.hook.utils.conditions -import com.highcapable.yukihookapi.hook.utils.let -import com.highcapable.yukihookapi.hook.utils.takeIf +import com.highcapable.yukihookapi.hook.utils.* import com.highcapable.yukihookapi.hook.utils.value import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge import com.highcapable.yukihookapi.hook.xposed.bridge.factory.YukiHookHelper @@ -134,10 +131,10 @@ internal object ReflectionTool { fullName?.also { it.equals(instance, it.TYPE_NAME).also { e -> if (it.isOptional) opt(e) else and(e) } } simpleName?.also { it.equals(instance, it.TYPE_SIMPLE_NAME).also { e -> if (it.isOptional) opt(e) else and(e) } } singleName?.also { it.equals(instance, it.TYPE_SINGLE_NAME).also { e -> if (it.isOptional) opt(e) else and(e) } } - fullNameConditions?.also { instance.name.also { n -> and(it(n.cast(), n)) } } - simpleNameConditions?.also { instance.simpleName.also { n -> and(it(n.cast(), n)) } } - singleNameConditions?.also { classSingleName(instance).also { n -> and(it(n.cast(), n)) } } - modifiers?.also { and(it(instance.cast())) } + fullNameConditions?.also { instance.name.also { n -> runCatching { and(it(n.cast(), n)) } } } + simpleNameConditions?.also { instance.simpleName.also { n -> runCatching { and(it(n.cast(), n)) } } } + singleNameConditions?.also { classSingleName(instance).also { n -> runCatching { and(it(n.cast(), n)) } } } + modifiers?.also { runCatching { and(it(instance.cast())) } } extendsClass.takeIf { it.isNotEmpty() }?.also { and(instance.hasExtends && it.contains(instance.superclass.name)) } implementsClass.takeIf { it.isNotEmpty() } ?.also { and(instance.interfaces.isNotEmpty() && instance.interfaces.any { e -> it.contains(e.name) }) } @@ -156,7 +153,7 @@ internal object ReflectionTool { rule.conditions { value.matchCount.takeIf { it >= 0 }?.also { and(it == size) } value.matchCountRange.takeIf { it.isEmpty().not() }?.also { and(size in it) } - value.matchCountConditions?.also { and(it(CountRules.with(size), size)) } + value.matchCountConditions?.also { runCatching { and(it(size.cast(), size)) } } }.finally { result(true) }.without { result(false) } } ?: result(true) } @@ -179,7 +176,7 @@ internal object ReflectionTool { var numberOfFound = 0 if (rule.isInitializeOfSuper) forEach { member -> rule.conditions { - value.modifiers?.also { and(it(member.cast())) } + value.modifiers?.also { runCatching { and(it(member.cast())) } } }.finally { numberOfFound++ } }.run { rule.matchCount(numberOfFound) { and(it && numberOfFound > 0) } } else rule.matchCount(size) { and(it) } @@ -192,8 +189,9 @@ internal object ReflectionTool { rule.conditions { value.type?.takeIf { value.exists(it) }?.also { and(it == field.type) } value.name.takeIf { it.isNotBlank() }?.also { and(it == field.name) } - value.modifiers?.also { and(it(field.cast())) } - value.nameConditions?.also { field.name.also { n -> and(it(n.cast(), n)) } } + value.modifiers?.also { runCatching { and(it(field.cast())) } } + value.nameConditions?.also { field.name.also { n -> runCatching { and(it(n.cast(), n)) } } } + value.typeConditions?.also { field.also { t -> runCatching { and(it(t.type(), t.type)) } } } }.finally { numberOfFound++ } }.run { rule.matchCount(numberOfFound) { and(it && numberOfFound > 0) } } else rule.matchCount(size) { and(it) } @@ -206,12 +204,17 @@ internal object ReflectionTool { rule.conditions { value.name.takeIf { it.isNotBlank() }?.also { and(it == method.name) } value.returnType?.takeIf { value.exists(it) }?.also { and(it == method.returnType) } + value.returnTypeConditions + ?.also { method.also { r -> runCatching { and(it(r.returnType(), r.returnType)) } } } value.paramCount.takeIf { it >= 0 }?.also { and(method.parameterTypes.size == it) } value.paramCountRange.takeIf { it.isEmpty().not() }?.also { and(method.parameterTypes.size in it) } - value.paramCountConditions?.also { method.parameterTypes.size.also { s -> and(it(s.cast(), s)) } } + value.paramCountConditions + ?.also { method.parameterTypes.size.also { s -> runCatching { and(it(s.cast(), s)) } } } value.paramTypes?.takeIf { value.exists(*it) }?.also { and(paramTypesEq(it, method.parameterTypes)) } - value.modifiers?.also { and(it(method.cast())) } - value.nameConditions?.also { method.name.also { n -> and(it(n.cast(), n)) } } + value.paramTypesConditions + ?.also { method.also { t -> runCatching { and(it(t.paramTypes(), t.parameterTypes)) } } } + value.modifiers?.also { runCatching { and(it(method.cast())) } } + value.nameConditions?.also { method.name.also { n -> runCatching { and(it(n.cast(), n)) } } } }.finally { numberOfFound++ } }.run { rule.matchCount(numberOfFound) { and(it && numberOfFound > 0) } } else rule.matchCount(size) { and(it) } @@ -224,9 +227,12 @@ internal object ReflectionTool { rule.conditions { value.paramCount.takeIf { it >= 0 }?.also { and(constructor.parameterTypes.size == it) } value.paramCountRange.takeIf { it.isEmpty().not() }?.also { and(constructor.parameterTypes.size in it) } - value.paramCountConditions?.also { constructor.parameterTypes.size.also { s -> and(it(s.cast(), s)) } } + value.paramCountConditions + ?.also { constructor.parameterTypes.size.also { s -> runCatching { and(it(s.cast(), s)) } } } value.paramTypes?.takeIf { value.exists(*it) }?.also { and(paramTypesEq(it, constructor.parameterTypes)) } - value.modifiers?.also { and(it(constructor.cast())) } + value.paramTypesConditions + ?.also { constructor.also { t -> runCatching { and(it(t.paramTypes(), t.parameterTypes)) } } } + value.modifiers?.also { runCatching { and(it(constructor.cast())) } } }.finally { numberOfFound++ } }.run { rule.matchCount(numberOfFound) { and(it && numberOfFound > 0) } } else rule.matchCount(size) { and(it) } @@ -265,10 +271,13 @@ internal object ReflectionTool { var iName = -1 var iModify = -1 var iNameCds = -1 + var iTypeCds = -1 val iLType = type?.let(matchIndex) { e -> declares.filter { e == it.type }.lastIndex } ?: -1 val iLName = name.takeIf(matchIndex) { it.isNotBlank() }?.let { e -> declares.filter { e == it.name }.lastIndex } ?: -1 - val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { e(it.cast()) }.lastIndex } ?: -1 - val iLNameCds = nameConditions?.let(matchIndex) { e -> declares.filter { it.name.let { n -> e(n.cast(), n) } }.lastIndex } ?: -1 + val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.cast()) } }.lastIndex } ?: -1 + val iLNameCds = nameConditions + ?.let(matchIndex) { e -> declares.filter { it.name.let { n -> runOrFalse { e(n.cast(), n) } } }.lastIndex } ?: -1 + val iLTypeCds = typeConditions?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.type(), it.type) } }.lastIndex } ?: -1 declares.forEachIndexed { index, instance -> conditions { type?.also { @@ -284,17 +293,23 @@ internal object ReflectionTool { }) } modifiers?.also { - and(it(instance.cast()).let { hold -> + and(runOrFalse { it(instance.cast()) }.let { hold -> if (hold) iModify++ hold && matchIndex.compare(iModify, iLModify) }) } nameConditions?.also { - and(instance.name.let { n -> it(n.cast(), n) }.let { hold -> + and(instance.name.let { n -> runOrFalse { it(n.cast(), n) } }.let { hold -> if (hold) iNameCds++ hold && matchIndex.compare(iNameCds, iLNameCds) }) } + typeConditions?.also { + and(instance.let { t -> runOrFalse { it(t.type(), t.type) } }.let { hold -> + if (hold) iTypeCds++ + hold && matchIndex.compare(iTypeCds, iLTypeCds) + }) + } orderIndex.compare(index, declares.lastIndex) { and(it) } }.finally { fields.add(instance.apply { isAccessible = true }) } } @@ -318,7 +333,9 @@ internal object ReflectionTool { ReflectsCacheStore.findMethods(hashCode(classSet)) ?: hashSetOf().also { methods -> classSet.existMethods?.also { declares -> var iReturnType = -1 + var iReturnTypeCds = -1 var iParamTypes = -1 + var iParamTypesCds = -1 var iParamCount = -1 var iParamCountRange = -1 var iParamCountCds = -1 @@ -326,16 +343,22 @@ internal object ReflectionTool { var iModify = -1 var iNameCds = -1 val iLReturnType = returnType?.let(matchIndex) { e -> declares.filter { e == it.returnType }.lastIndex } ?: -1 + val iLReturnTypeCds = returnTypeConditions + ?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.returnType(), it.returnType) } }.lastIndex } ?: -1 val iLParamCount = paramCount.takeIf(matchIndex) { it >= 0 } ?.let { e -> declares.filter { e == it.parameterTypes.size }.lastIndex } ?: -1 val iLParamCountRange = paramCountRange.takeIf(matchIndex) { it.isEmpty().not() } ?.let { e -> declares.filter { it.parameterTypes.size in e }.lastIndex } ?: -1 - val iLParamCountCds = paramCountConditions - ?.let(matchIndex) { e -> declares.filter { it.parameterTypes.size.let { s -> e(s.cast(), s) } }.lastIndex } ?: -1 + val iLParamCountCds = paramCountConditions?.let(matchIndex) { e -> + declares.filter { it.parameterTypes.size.let { s -> runOrFalse { e(s.cast(), s) } } }.lastIndex + } ?: -1 val iLParamTypes = paramTypes?.let(matchIndex) { e -> declares.filter { paramTypesEq(e, it.parameterTypes) }.lastIndex } ?: -1 + val iLParamTypesCds = paramTypesConditions + ?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.paramTypes(), it.parameterTypes) } }.lastIndex } ?: -1 val iLName = name.takeIf(matchIndex) { it.isNotBlank() }?.let { e -> declares.filter { e == it.name }.lastIndex } ?: -1 - val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { e(it.cast()) }.lastIndex } ?: -1 - val iLNameCds = nameConditions?.let(matchIndex) { e -> declares.filter { it.name.let { n -> e(n.cast(), n) } }.lastIndex } ?: -1 + val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.cast()) } }.lastIndex } ?: -1 + val iLNameCds = nameConditions + ?.let(matchIndex) { e -> declares.filter { it.name.let { n -> runOrFalse { e(n.cast(), n) } } }.lastIndex } ?: -1 declares.forEachIndexed { index, instance -> conditions { name.takeIf { it.isNotBlank() }?.also { @@ -350,6 +373,12 @@ internal object ReflectionTool { hold && matchIndex.compare(iReturnType, iLReturnType) }) } + returnTypeConditions?.also { + and(instance.let { r -> runOrFalse { it(r.returnType(), r.returnType) } }.let { hold -> + if (hold) iReturnTypeCds++ + hold && matchIndex.compare(iReturnTypeCds, iLReturnTypeCds) + }) + } paramCount.takeIf { it >= 0 }?.also { and((instance.parameterTypes.size == it).let { hold -> if (hold) iParamCount++ @@ -363,7 +392,7 @@ internal object ReflectionTool { }) } paramCountConditions?.also { - and(instance.parameterTypes.size.let { s -> it(s.cast(), s) }.let { hold -> + and(instance.parameterTypes.size.let { s -> runOrFalse { it(s.cast(), s) } }.let { hold -> if (hold) iParamCountCds++ hold && matchIndex.compare(iParamCountCds, iLParamCountCds) }) @@ -374,14 +403,20 @@ internal object ReflectionTool { hold && matchIndex.compare(iParamTypes, iLParamTypes) }) } + paramTypesConditions?.also { + and(instance.let { t -> runOrFalse { it(t.paramTypes(), t.parameterTypes) } }.let { hold -> + if (hold) iParamTypesCds++ + hold && matchIndex.compare(iParamTypesCds, iLParamTypesCds) + }) + } modifiers?.also { - and(it(instance.cast()).let { hold -> + and(runOrFalse { it(instance.cast()) }.let { hold -> if (hold) iModify++ hold && matchIndex.compare(iModify, iLModify) }) } nameConditions?.also { - and(instance.name.let { n -> it(n.cast(), n) }.let { hold -> + and(instance.name.let { n -> runOrFalse { it(n.cast(), n) } }.let { hold -> if (hold) iNameCds++ hold && matchIndex.compare(iNameCds, iLNameCds) }) @@ -408,6 +443,7 @@ internal object ReflectionTool { ReflectsCacheStore.findConstructors(hashCode(classSet)) ?: hashSetOf>().also { constructors -> classSet.existConstructors?.also { declares -> var iParamTypes = -1 + var iParamTypesCds = -1 var iParamCount = -1 var iParamCountRange = -1 var iParamCountCds = -1 @@ -416,10 +452,13 @@ internal object ReflectionTool { ?.let { e -> declares.filter { e == it.parameterTypes.size }.lastIndex } ?: -1 val iLParamCountRange = paramCountRange.takeIf(matchIndex) { it.isEmpty().not() } ?.let { e -> declares.filter { it.parameterTypes.size in e }.lastIndex } ?: -1 - val iLParamCountCds = paramCountConditions - ?.let(matchIndex) { e -> declares.filter { it.parameterTypes.size.let { s -> e(s.cast(), s) } }.lastIndex } ?: -1 + val iLParamCountCds = paramCountConditions?.let(matchIndex) { e -> + declares.filter { it.parameterTypes.size.let { s -> runOrFalse { e(s.cast(), s) } } }.lastIndex + } ?: -1 val iLParamTypes = paramTypes?.let(matchIndex) { e -> declares.filter { paramTypesEq(e, it.parameterTypes) }.lastIndex } ?: -1 - val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { e(it.cast()) }.lastIndex } ?: -1 + val iLParamTypesCds = paramTypesConditions + ?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.paramTypes(), it.parameterTypes) } }.lastIndex } ?: -1 + val iLModify = modifiers?.let(matchIndex) { e -> declares.filter { runOrFalse { e(it.cast()) } }.lastIndex } ?: -1 declares.forEachIndexed { index, instance -> conditions { paramCount.takeIf { it >= 0 }?.also { @@ -435,7 +474,7 @@ internal object ReflectionTool { }) } paramCountConditions?.also { - and(instance.parameterTypes.size.let { s -> it(s.cast(), s) }.let { hold -> + and(instance.parameterTypes.size.let { s -> runOrFalse { it(s.cast(), s) } }.let { hold -> if (hold) iParamCountCds++ hold && matchIndex.compare(iParamCountCds, iLParamCountCds) }) @@ -446,8 +485,14 @@ internal object ReflectionTool { hold && matchIndex.compare(iParamTypes, iLParamTypes) }) } + paramTypesConditions?.also { + and(instance.let { t -> runOrFalse { it(t.paramTypes(), t.parameterTypes) } }.let { hold -> + if (hold) iParamTypesCds++ + hold && matchIndex.compare(iParamTypesCds, iLParamTypesCds) + }) + } modifiers?.also { - and(it(instance.cast()).let { hold -> + and(runOrFalse { it(instance.cast()) }.let { hold -> if (hold) iModify++ hold && matchIndex.compare(iModify, iLModify) }) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/factory/TypeAliasFactory.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/factory/TypeAliasFactory.kt index f34b3d73..d7aff8e0 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/factory/TypeAliasFactory.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/type/factory/TypeAliasFactory.kt @@ -30,6 +30,7 @@ package com.highcapable.yukihookapi.hook.core.finder.type.factory import com.highcapable.yukihookapi.hook.core.finder.base.rules.CountRules import com.highcapable.yukihookapi.hook.core.finder.base.rules.ModifierRules import com.highcapable.yukihookapi.hook.core.finder.base.rules.NameRules +import com.highcapable.yukihookapi.hook.core.finder.base.rules.ObjectRules import com.highcapable.yukihookapi.hook.core.finder.classes.DexClassFinder import com.highcapable.yukihookapi.hook.core.finder.members.ConstructorFinder import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder @@ -54,4 +55,10 @@ internal typealias NameConditions = NameRules.(String) -> Boolean internal typealias CountConditions = CountRules.(Int) -> Boolean /** 定义 [ModifierRules] 方法体类型 */ -internal typealias ModifierConditions = ModifierRules.() -> Boolean \ No newline at end of file +internal typealias ModifierConditions = ModifierRules.() -> Boolean + +/** 定义 [ObjectRules] 方法体类型 */ +internal typealias ObjectConditions = ObjectRules.(Class<*>) -> Boolean + +/** 定义 [ObjectRules] 方法体类型 */ +internal typealias ObjectsConditions = ObjectRules.(Array>) -> Boolean \ No newline at end of file