mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-05 18:25:28 +08:00
Modify change hooker functions to MemberBaseFinder.MemberHookerManager in FieldFinder, MethodFinder, ConstructorFinder, MemberBaseFinder
This commit is contained in:
@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
|
|||||||
# ConstructorFinder <span class="symbol">- class</span>
|
# ConstructorFinder <span class="symbol">- class</span>
|
||||||
|
|
||||||
```kotlin:no-line-numbers
|
```kotlin:no-line-numbers
|
||||||
class ConstructorFinder internal constructor(override val hookInstance: YukiMemberHookCreator.MemberHookCreator?, override val classSet: Class<*>) : MemberBaseFinder
|
class ConstructorFinder internal constructor(override val classSet: Class<*>) : MemberBaseFinder
|
||||||
```
|
```
|
||||||
|
|
||||||
**Change Records**
|
**Change Records**
|
||||||
@@ -28,6 +28,10 @@ class ConstructorFinder internal constructor(override val hookInstance: YukiMemb
|
|||||||
|
|
||||||
合并到 `MemberBaseFinder`
|
合并到 `MemberBaseFinder`
|
||||||
|
|
||||||
|
`v1.1.7` `modified`
|
||||||
|
|
||||||
|
移动 `hookInstance` 参数到 `MemberBaseFinder.MemberHookerManager`
|
||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> `Constructor` 查找类。
|
> `Constructor` 查找类。
|
||||||
@@ -328,7 +332,7 @@ inner class Process internal constructor(internal val isNoSuch: Boolean, interna
|
|||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> `Constructor` 查找结果处理类,为 `hookInstance` 提供。
|
> `Constructor` 查找结果处理类,为 `hookManager` 提供。
|
||||||
|
|
||||||
### result <span class="symbol">- method</span>
|
### result <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -372,7 +376,7 @@ fun all(): Process
|
|||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> 设置全部查找条件匹配的多个 `Constructor` 实例结果到 `hookInstance`。
|
> 设置全部查找条件匹配的多个 `Constructor` 实例结果到 `hookManager`。
|
||||||
|
|
||||||
### remedys <span class="symbol">- method</span>
|
### remedys <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -723,7 +727,7 @@ fun ignored(): Result
|
|||||||
|
|
||||||
> 忽略异常并停止打印任何错误日志。
|
> 忽略异常并停止打印任何错误日志。
|
||||||
|
|
||||||
若 `isNotIgnoredHookingFailure` 为 `false` 则自动忽略。
|
若 `MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure` 为 `false` 则自动忽略。
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
|
|||||||
# FieldFinder <span class="symbol">- class</span>
|
# FieldFinder <span class="symbol">- class</span>
|
||||||
|
|
||||||
```kotlin:no-line-numbers
|
```kotlin:no-line-numbers
|
||||||
class FieldFinder internal constructor(override val hookInstance: YukiMemberHookCreator.MemberHookCreator?, override val classSet: Class<*>?) : MemberBaseFinder
|
class FieldFinder internal constructor(override val classSet: Class<*>?) : MemberBaseFinder
|
||||||
```
|
```
|
||||||
|
|
||||||
**Change Records**
|
**Change Records**
|
||||||
@@ -28,6 +28,10 @@ class FieldFinder internal constructor(override val hookInstance: YukiMemberHook
|
|||||||
|
|
||||||
合并到 `MemberBaseFinder`
|
合并到 `MemberBaseFinder`
|
||||||
|
|
||||||
|
`v1.1.7` `modified`
|
||||||
|
|
||||||
|
移动 `hookInstance` 参数到 `MemberBaseFinder.MemberHookerManager`
|
||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> `Field` 查找类。
|
> `Field` 查找类。
|
||||||
@@ -582,7 +586,7 @@ fun ignored(): Result
|
|||||||
|
|
||||||
> 忽略异常并停止打印任何错误日志。
|
> 忽略异常并停止打印任何错误日志。
|
||||||
|
|
||||||
若 `isNotIgnoredHookingFailure` 为 `false` 则自动忽略。
|
若 `MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure` 为 `false` 则自动忽略。
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
|
|||||||
# MethodFinder <span class="symbol">- class</span>
|
# MethodFinder <span class="symbol">- class</span>
|
||||||
|
|
||||||
```kotlin:no-line-numbers
|
```kotlin:no-line-numbers
|
||||||
class MethodFinder internal constructor(override val hookInstance: YukiMemberHookCreator.MemberHookCreator?, override val classSet: Class<*>) : MemberBaseFinder
|
class MethodFinder internal constructor(override val classSet: Class<*>) : MemberBaseFinder
|
||||||
```
|
```
|
||||||
|
|
||||||
**Change Records**
|
**Change Records**
|
||||||
@@ -28,6 +28,10 @@ class MethodFinder internal constructor(override val hookInstance: YukiMemberHoo
|
|||||||
|
|
||||||
合并到 `MemberBaseFinder`
|
合并到 `MemberBaseFinder`
|
||||||
|
|
||||||
|
`v1.1.7` `modified`
|
||||||
|
|
||||||
|
移动 `hookInstance` 参数到 `MemberBaseFinder.MemberHookerManager`
|
||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> `Method` 查找类。
|
> `Method` 查找类。
|
||||||
@@ -472,7 +476,7 @@ inner class Process internal constructor(internal val isNoSuch: Boolean, interna
|
|||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> `Method` 查找结果处理类,为 `hookInstance` 提供。
|
> `Method` 查找结果处理类,为 `hookManager` 提供。
|
||||||
|
|
||||||
### result <span class="symbol">- method</span>
|
### result <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -516,7 +520,7 @@ fun all(): Process
|
|||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> 设置全部查找条件匹配的多个 `Method` 实例结果到 `hookInstance`。
|
> 设置全部查找条件匹配的多个 `Method` 实例结果到 `hookManager`。
|
||||||
|
|
||||||
### remedys <span class="symbol">- method</span>
|
### remedys <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -853,7 +857,7 @@ fun ignored(): Result
|
|||||||
|
|
||||||
> 忽略异常并停止打印任何错误日志。
|
> 忽略异常并停止打印任何错误日志。
|
||||||
|
|
||||||
若 `isNotIgnoredHookingFailure` 为 `false` 则自动忽略。
|
若 `MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure` 为 `false` 则自动忽略。
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ pageClass: code-page
|
|||||||
# ConstructorFinder <span class="symbol">- class</span>
|
# ConstructorFinder <span class="symbol">- class</span>
|
||||||
|
|
||||||
```kotlin:no-line-numbers
|
```kotlin:no-line-numbers
|
||||||
class ConstructorFinder internal constructor(override val hookInstance: YukiMemberHookCreator.MemberHookCreator?, override val classSet: Class<*>) : MemberBaseFinder
|
class ConstructorFinder internal constructor(override val classSet: Class<*>) : MemberBaseFinder
|
||||||
```
|
```
|
||||||
|
|
||||||
**变更记录**
|
**变更记录**
|
||||||
@@ -20,6 +20,10 @@ class ConstructorFinder internal constructor(override val hookInstance: YukiMemb
|
|||||||
|
|
||||||
合并到 `MemberBaseFinder`
|
合并到 `MemberBaseFinder`
|
||||||
|
|
||||||
|
`v1.1.7` `修改`
|
||||||
|
|
||||||
|
移动 `hookInstance` 参数到 `MemberBaseFinder.MemberHookerManager`
|
||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> `Constructor` 查找类。
|
> `Constructor` 查找类。
|
||||||
@@ -320,7 +324,7 @@ inner class Process internal constructor(internal val isNoSuch: Boolean, interna
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> `Constructor` 查找结果处理类,为 `hookInstance` 提供。
|
> `Constructor` 查找结果处理类,为 `hookManager` 提供。
|
||||||
|
|
||||||
### result <span class="symbol">- method</span>
|
### result <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -364,7 +368,7 @@ fun all(): Process
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> 设置全部查找条件匹配的多个 `Constructor` 实例结果到 `hookInstance`。
|
> 设置全部查找条件匹配的多个 `Constructor` 实例结果到 `hookManager`。
|
||||||
|
|
||||||
### remedys <span class="symbol">- method</span>
|
### remedys <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -715,7 +719,7 @@ fun ignored(): Result
|
|||||||
|
|
||||||
> 忽略异常并停止打印任何错误日志。
|
> 忽略异常并停止打印任何错误日志。
|
||||||
|
|
||||||
若 `isNotIgnoredHookingFailure` 为 `false` 则自动忽略。
|
若 `MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure` 为 `false` 则自动忽略。
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ pageClass: code-page
|
|||||||
# FieldFinder <span class="symbol">- class</span>
|
# FieldFinder <span class="symbol">- class</span>
|
||||||
|
|
||||||
```kotlin:no-line-numbers
|
```kotlin:no-line-numbers
|
||||||
class FieldFinder internal constructor(override val hookInstance: YukiMemberHookCreator.MemberHookCreator?, override val classSet: Class<*>?) : MemberBaseFinder
|
class FieldFinder internal constructor(override val classSet: Class<*>?) : MemberBaseFinder
|
||||||
```
|
```
|
||||||
|
|
||||||
**变更记录**
|
**变更记录**
|
||||||
@@ -20,6 +20,10 @@ class FieldFinder internal constructor(override val hookInstance: YukiMemberHook
|
|||||||
|
|
||||||
合并到 `MemberBaseFinder`
|
合并到 `MemberBaseFinder`
|
||||||
|
|
||||||
|
`v1.1.7` `修改`
|
||||||
|
|
||||||
|
移动 `hookInstance` 参数到 `MemberBaseFinder.MemberHookerManager`
|
||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> `Field` 查找类。
|
> `Field` 查找类。
|
||||||
@@ -574,7 +578,7 @@ fun ignored(): Result
|
|||||||
|
|
||||||
> 忽略异常并停止打印任何错误日志。
|
> 忽略异常并停止打印任何错误日志。
|
||||||
|
|
||||||
若 `isNotIgnoredHookingFailure` 为 `false` 则自动忽略。
|
若 `MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure` 为 `false` 则自动忽略。
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ pageClass: code-page
|
|||||||
# MethodFinder <span class="symbol">- class</span>
|
# MethodFinder <span class="symbol">- class</span>
|
||||||
|
|
||||||
```kotlin:no-line-numbers
|
```kotlin:no-line-numbers
|
||||||
class MethodFinder internal constructor(override val hookInstance: YukiMemberHookCreator.MemberHookCreator?, override val classSet: Class<*>) : MemberBaseFinder
|
class MethodFinder internal constructor(override val classSet: Class<*>) : MemberBaseFinder
|
||||||
```
|
```
|
||||||
|
|
||||||
**变更记录**
|
**变更记录**
|
||||||
@@ -20,6 +20,10 @@ class MethodFinder internal constructor(override val hookInstance: YukiMemberHoo
|
|||||||
|
|
||||||
合并到 `MemberBaseFinder`
|
合并到 `MemberBaseFinder`
|
||||||
|
|
||||||
|
`v1.1.7` `修改`
|
||||||
|
|
||||||
|
移动 `hookInstance` 参数到 `MemberBaseFinder.MemberHookerManager`
|
||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> `Method` 查找类。
|
> `Method` 查找类。
|
||||||
@@ -464,7 +468,7 @@ inner class Process internal constructor(internal val isNoSuch: Boolean, interna
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> `Method` 查找结果处理类,为 `hookInstance` 提供。
|
> `Method` 查找结果处理类,为 `hookManager` 提供。
|
||||||
|
|
||||||
### result <span class="symbol">- method</span>
|
### result <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -508,7 +512,7 @@ fun all(): Process
|
|||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> 设置全部查找条件匹配的多个 `Method` 实例结果到 `hookInstance`。
|
> 设置全部查找条件匹配的多个 `Method` 实例结果到 `hookManager`。
|
||||||
|
|
||||||
### remedys <span class="symbol">- method</span>
|
### remedys <span class="symbol">- method</span>
|
||||||
|
|
||||||
@@ -845,7 +849,7 @@ fun ignored(): Result
|
|||||||
|
|
||||||
> 忽略异常并停止打印任何错误日志。
|
> 忽略异常并停止打印任何错误日志。
|
||||||
|
|
||||||
若 `isNotIgnoredHookingFailure` 为 `false` 则自动忽略。
|
若 `MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure` 为 `false` 则自动忽略。
|
||||||
|
|
||||||
::: warning
|
::: warning
|
||||||
|
|
||||||
|
@@ -371,10 +371,10 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
*/
|
*/
|
||||||
inline fun method(initiate: MethodConditions) = runCatching {
|
inline fun method(initiate: MethodConditions) = runCatching {
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
MethodFinder(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process()
|
MethodFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
findingThrowable = it
|
findingThrowable = it
|
||||||
MethodFinder(hookInstance = this).denied(it)
|
MethodFinder.fromHooker(hookInstance = this).denied(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,10 +386,10 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
*/
|
*/
|
||||||
inline fun constructor(initiate: ConstructorConditions = { emptyParam() }) = runCatching {
|
inline fun constructor(initiate: ConstructorConditions = { emptyParam() }) = runCatching {
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
ConstructorFinder(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process()
|
ConstructorFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
findingThrowable = it
|
findingThrowable = it
|
||||||
ConstructorFinder(hookInstance = this).denied(it)
|
ConstructorFinder.fromHooker(hookInstance = this).denied(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -398,8 +398,8 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
* @return [FieldFinder.Result]
|
* @return [FieldFinder.Result]
|
||||||
*/
|
*/
|
||||||
inline fun HookParam.field(initiate: FieldConditions) =
|
inline fun HookParam.field(initiate: FieldConditions) =
|
||||||
if (hookClass.instance == null) FieldFinder(hookInstance = this@MemberHookCreator).failure(hookClass.throwable)
|
if (hookClass.instance == null) FieldFinder.fromHooker(hookInstance = this@MemberHookCreator).failure(hookClass.throwable)
|
||||||
else FieldFinder(hookInstance = this@MemberHookCreator, hookClass.instance).apply(initiate).build()
|
else FieldFinder.fromHooker(hookInstance = this@MemberHookCreator, hookClass.instance).apply(initiate).build()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用当前 [hookClass] 查找并得到 [Method]
|
* 使用当前 [hookClass] 查找并得到 [Method]
|
||||||
@@ -407,8 +407,8 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
* @return [MethodFinder.Result]
|
* @return [MethodFinder.Result]
|
||||||
*/
|
*/
|
||||||
inline fun HookParam.method(initiate: MethodConditions) =
|
inline fun HookParam.method(initiate: MethodConditions) =
|
||||||
if (hookClass.instance == null) MethodFinder(hookInstance = this@MemberHookCreator).failure(hookClass.throwable)
|
if (hookClass.instance == null) MethodFinder.fromHooker(hookInstance = this@MemberHookCreator).failure(hookClass.throwable)
|
||||||
else MethodFinder(hookInstance = this@MemberHookCreator, hookClass.instance).apply(initiate).build()
|
else MethodFinder.fromHooker(hookInstance = this@MemberHookCreator, hookClass.instance).apply(initiate).build()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用当前 [hookClass] 查找并得到 [Constructor]
|
* 使用当前 [hookClass] 查找并得到 [Constructor]
|
||||||
@@ -416,8 +416,8 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
* @return [ConstructorFinder.Result]
|
* @return [ConstructorFinder.Result]
|
||||||
*/
|
*/
|
||||||
inline fun HookParam.constructor(initiate: ConstructorConditions = { emptyParam() }) =
|
inline fun HookParam.constructor(initiate: ConstructorConditions = { emptyParam() }) =
|
||||||
if (hookClass.instance == null) ConstructorFinder(hookInstance = this@MemberHookCreator).failure(hookClass.throwable)
|
if (hookClass.instance == null) ConstructorFinder.fromHooker(hookInstance = this@MemberHookCreator).failure(hookClass.throwable)
|
||||||
else ConstructorFinder(hookInstance = this@MemberHookCreator, hookClass.instance).apply(initiate).build()
|
else ConstructorFinder.fromHooker(hookInstance = this@MemberHookCreator, hookClass.instance).apply(initiate).build()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入要 Hook 的 [Method]、[Constructor] (嵌套 Hook)
|
* 注入要 Hook 的 [Method]、[Constructor] (嵌套 Hook)
|
||||||
|
@@ -43,12 +43,10 @@ import java.lang.reflect.Method
|
|||||||
/**
|
/**
|
||||||
* 这是 [Member] 查找类功能的基本类实现
|
* 这是 [Member] 查找类功能的基本类实现
|
||||||
* @param tag 当前查找类的标识
|
* @param tag 当前查找类的标识
|
||||||
* @param hookInstance 当前 Hook 实例
|
|
||||||
* @param classSet 当前需要查找的 [Class] 实例
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
*/
|
*/
|
||||||
abstract class MemberBaseFinder internal constructor(
|
abstract class MemberBaseFinder internal constructor(
|
||||||
private val tag: String,
|
private val tag: String,
|
||||||
@PublishedApi internal open val hookInstance: YukiMemberHookCreator.MemberHookCreator? = null,
|
|
||||||
@PublishedApi internal open val classSet: Class<*>? = null
|
@PublishedApi internal open val classSet: Class<*>? = null
|
||||||
) : BaseFinder() {
|
) : BaseFinder() {
|
||||||
|
|
||||||
@@ -58,31 +56,20 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
internal const val CLASSSET_IS_NULL = "classSet is null"
|
internal const val CLASSSET_IS_NULL = "classSet is null"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 当前 [MemberHookerManager] */
|
||||||
|
@PublishedApi
|
||||||
|
internal var hookerManager = MemberHookerManager()
|
||||||
|
|
||||||
/** 是否使用了重查找功能 */
|
/** 是否使用了重查找功能 */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal var isUsingRemedyPlan = false
|
internal var isUsingRemedyPlan = false
|
||||||
|
|
||||||
/** 是否将结果设置到目标 [YukiMemberHookCreator.MemberHookCreator] */
|
|
||||||
internal var isBindToHooker = false
|
|
||||||
|
|
||||||
/** 是否开启忽略错误警告功能 */
|
/** 是否开启忽略错误警告功能 */
|
||||||
internal var isShutErrorPrinting = false
|
internal var isShutErrorPrinting = false
|
||||||
|
|
||||||
/** 当前找到的 [Member] 数组 */
|
/** 当前找到的 [Member] 数组 */
|
||||||
internal var memberInstances = HashSet<Member>()
|
internal var memberInstances = HashSet<Member>()
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前使用的 TAG
|
|
||||||
* @return [String] 使用的 TAG
|
|
||||||
*/
|
|
||||||
internal val hookTag get() = hookInstance?.tag ?: "FinderMode"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否没有设置 Hook 过程中 方法、构造方法、变量 找不到的任何异常拦截
|
|
||||||
* @return [Boolean] 没有设置任何异常拦截
|
|
||||||
*/
|
|
||||||
internal val isNotIgnoredNoSuchMemberFailure get() = hookInstance?.isNotIgnoredNoSuchMemberFailure ?: true
|
|
||||||
|
|
||||||
/** 需要输出的日志内容 */
|
/** 需要输出的日志内容 */
|
||||||
private var loggingContent: Pair<String, Throwable?>? = null
|
private var loggingContent: Pair<String, Throwable?>? = null
|
||||||
|
|
||||||
@@ -122,13 +109,13 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
internal fun onFailureMsg(msg: String = "", throwable: Throwable? = null, isAlwaysPrint: Boolean = false) {
|
internal fun onFailureMsg(msg: String = "", throwable: Throwable? = null, isAlwaysPrint: Boolean = false) {
|
||||||
/** 创建日志 */
|
/** 创建日志 */
|
||||||
fun build() {
|
fun build() {
|
||||||
if (isNotIgnoredNoSuchMemberFailure && isUsingRemedyPlan.not() && isShutErrorPrinting.not())
|
if (hookerManager.isNotIgnoredNoSuchMemberFailure && isUsingRemedyPlan.not() && isShutErrorPrinting.not())
|
||||||
loggingContent = Pair(msg, throwable)
|
loggingContent = Pair(msg, throwable)
|
||||||
}
|
}
|
||||||
/** 判断是否为 [CLASSSET_IS_NULL] */
|
/** 判断是否为 [CLASSSET_IS_NULL] */
|
||||||
if (throwable?.message == CLASSSET_IS_NULL) return
|
if (throwable?.message == CLASSSET_IS_NULL) return
|
||||||
/** 判断绑定到 Hooker 时仅创建日志 */
|
/** 判断绑定到 Hooker 时仅创建日志 */
|
||||||
if (isBindToHooker) return await { build() }.unit()
|
if (hookerManager.instance != null) return await { build() }.unit()
|
||||||
/** 判断始终输出日志或等待结果后输出日志 */
|
/** 判断始终输出日志或等待结果后输出日志 */
|
||||||
if (isAlwaysPrint) build().run { printLogIfExist() }
|
if (isAlwaysPrint) build().run { printLogIfExist() }
|
||||||
else await { build().run { printLogIfExist() } }
|
else await { build().run { printLogIfExist() } }
|
||||||
@@ -137,7 +124,7 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
/** 存在日志时输出日志 */
|
/** 存在日志时输出日志 */
|
||||||
internal fun printLogIfExist() {
|
internal fun printLogIfExist() {
|
||||||
if (loggingContent != null) yLoggerE(
|
if (loggingContent != null) yLoggerE(
|
||||||
msg = "NoSuch$tag happend in [$classSet] ${loggingContent?.first} [${hookTag}]",
|
msg = "NoSuch$tag happend in [$classSet] ${loggingContent?.first}${hookerManager.tailTag}",
|
||||||
e = loggingContent?.second
|
e = loggingContent?.second
|
||||||
)
|
)
|
||||||
/** 仅输出一次 - 然后清掉日志 */
|
/** 仅输出一次 - 然后清掉日志 */
|
||||||
@@ -149,7 +136,8 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
* @param msg 调试日志内容
|
* @param msg 调试日志内容
|
||||||
*/
|
*/
|
||||||
internal fun onDebuggingMsg(msg: String) {
|
internal fun onDebuggingMsg(msg: String) {
|
||||||
if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi && hookInstance != null) yLoggerI(msg = msg)
|
if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi && hookerManager.instance != null)
|
||||||
|
yLoggerI(msg = "$msg${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,4 +158,46 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
*/
|
*/
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
abstract fun denied(throwable: Throwable?): BaseResult
|
abstract fun denied(throwable: Throwable?): BaseResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前 Hooker 管理实现类
|
||||||
|
*/
|
||||||
|
internal inner class MemberHookerManager {
|
||||||
|
|
||||||
|
/** 当前 Hooker */
|
||||||
|
internal var instance: YukiMemberHookCreator.MemberHookCreator? = null
|
||||||
|
|
||||||
|
/** 当前 [Member] 是否设置到当前 Hooker */
|
||||||
|
internal var isMemberBinded = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否没有设置 Hook 过程中 方法、构造方法、变量 找不到的任何异常拦截
|
||||||
|
* @return [Boolean] 没有设置任何异常拦截
|
||||||
|
*/
|
||||||
|
internal val isNotIgnoredNoSuchMemberFailure get() = instance?.isNotIgnoredNoSuchMemberFailure ?: true
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日志尾部打印的 TAG 用于标识当前 Hook 实例
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
internal val tailTag get() = instance?.tag?.let { if (it.isNotBlank()) " [$it]" else "" } ?: ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定当前 [Member] 到当前 Hooker
|
||||||
|
* @param member 当前 [Member]
|
||||||
|
*/
|
||||||
|
internal fun bindMember(member: Member?) {
|
||||||
|
instance?.members?.clear()
|
||||||
|
member?.also { instance?.members?.add(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定 [Member] 数组到当前 Hooker
|
||||||
|
* @param members 当前 [Member] 数组
|
||||||
|
*/
|
||||||
|
internal fun bindMembers(members: HashSet<Member>) {
|
||||||
|
instance?.members?.clear()
|
||||||
|
members.forEach { instance?.members?.add(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -40,7 +40,6 @@ import com.highcapable.yukihookapi.hook.core.finder.type.factory.ConstructorCond
|
|||||||
import com.highcapable.yukihookapi.hook.core.finder.type.factory.CountConditions
|
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.ModifierConditions
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.type.factory.ObjectsConditions
|
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.factory.hasExtends
|
||||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||||
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
||||||
@@ -54,13 +53,24 @@ import java.lang.reflect.Member
|
|||||||
* [Constructor] 查找类
|
* [Constructor] 查找类
|
||||||
*
|
*
|
||||||
* 可通过指定类型查找指定 [Constructor] 或一组 [Constructor]
|
* 可通过指定类型查找指定 [Constructor] 或一组 [Constructor]
|
||||||
* @param hookInstance 当前 Hook 实例 - 填写后将自动设置 [YukiMemberHookCreator.MemberHookCreator.members]
|
|
||||||
* @param classSet 当前需要查找的 [Class] 实例
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
*/
|
*/
|
||||||
class ConstructorFinder @PublishedApi internal constructor(
|
class ConstructorFinder @PublishedApi internal constructor(@PublishedApi override val classSet: Class<*>? = null) :
|
||||||
@PublishedApi override val hookInstance: YukiMemberHookCreator.MemberHookCreator? = null,
|
MemberBaseFinder(tag = "Constructor", classSet) {
|
||||||
@PublishedApi override val classSet: Class<*>? = null
|
|
||||||
) : MemberBaseFinder(tag = "Constructor", hookInstance, classSet) {
|
@PublishedApi
|
||||||
|
internal companion object {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 [YukiMemberHookCreator.MemberHookCreator] 创建 [Constructor] 查找类
|
||||||
|
* @param hookInstance 当前 Hooker
|
||||||
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
|
* @return [ConstructorFinder]
|
||||||
|
*/
|
||||||
|
@PublishedApi
|
||||||
|
internal fun fromHooker(hookInstance: YukiMemberHookCreator.MemberHookCreator, classSet: Class<*>? = null) =
|
||||||
|
ConstructorFinder(classSet).apply { hookerManager.instance = hookInstance }
|
||||||
|
}
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
override var rulesData = ConstructorRulesData()
|
override var rulesData = ConstructorRulesData()
|
||||||
@@ -241,36 +251,27 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置实例
|
* 设置实例
|
||||||
* @param isBind 是否将结果设置到目标 [YukiMemberHookCreator.MemberHookCreator]
|
|
||||||
* @param constructors 当前找到的 [Constructor] 数组
|
* @param constructors 当前找到的 [Constructor] 数组
|
||||||
*/
|
*/
|
||||||
private fun setInstance(isBind: Boolean, constructors: HashSet<Constructor<*>>) {
|
private fun setInstance(constructors: HashSet<Constructor<*>>) {
|
||||||
memberInstances.clear()
|
memberInstances.clear()
|
||||||
val result = constructors.takeIf { it.isNotEmpty() }?.onEach { memberInstances.add(it) }?.first()
|
constructors.takeIf { it.isNotEmpty() }?.onEach { memberInstances.add(it) }
|
||||||
if (isBind) hookInstance?.members?.apply {
|
?.first()?.apply { if (hookerManager.isMemberBinded) hookerManager.bindMember(member = this) }
|
||||||
clear()
|
|
||||||
result?.also { add(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 得到 [Constructor] 结果 */
|
||||||
* 得到 [Constructor] 结果
|
private fun internalBuild() {
|
||||||
* @param isBind 是否将结果设置到目标 [YukiMemberHookCreator.MemberHookCreator]
|
|
||||||
*/
|
|
||||||
private fun build(isBind: Boolean) {
|
|
||||||
if (classSet == null) error(CLASSSET_IS_NULL)
|
if (classSet == null) error(CLASSSET_IS_NULL)
|
||||||
classSet.checkingInternal()
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
isBindToHooker = isBind
|
setInstance(result)
|
||||||
setInstance(isBind, result)
|
|
||||||
}.result { ms ->
|
}.result { ms ->
|
||||||
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Constructor [$it] takes ${ms}ms [${hookTag}]") }
|
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Constructor [$it] takes ${ms}ms") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
override fun build() = runCatching {
|
override fun build() = runCatching {
|
||||||
build(isBind = false)
|
internalBuild()
|
||||||
Result()
|
Result()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
onFailureMsg(throwable = it)
|
||||||
@@ -279,7 +280,8 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
override fun process() = runCatching {
|
override fun process() = runCatching {
|
||||||
build(isBind = true)
|
hookerManager.isMemberBinded = true
|
||||||
|
internalBuild()
|
||||||
Process()
|
Process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
onFailureMsg(throwable = it)
|
||||||
@@ -311,8 +313,11 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
* 若最后依然失败 - 将停止查找并输出错误日志
|
* 若最后依然失败 - 将停止查找并输出错误日志
|
||||||
* @param initiate 方法体
|
* @param initiate 方法体
|
||||||
*/
|
*/
|
||||||
inline fun constructor(initiate: ConstructorConditions) =
|
inline fun constructor(initiate: ConstructorConditions) = Result().apply {
|
||||||
Result().apply { remedyPlans.add(Pair(ConstructorFinder(hookInstance, classSet).apply(initiate), this)) }
|
remedyPlans.add(Pair(ConstructorFinder(classSet).apply {
|
||||||
|
hookerManager = this@ConstructorFinder.hookerManager
|
||||||
|
}.apply(initiate), this))
|
||||||
|
}
|
||||||
|
|
||||||
/** 开始重查找 */
|
/** 开始重查找 */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -324,16 +329,15 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
remedyPlans.forEachIndexed { p, it ->
|
remedyPlans.forEachIndexed { p, it ->
|
||||||
runCatching {
|
runCatching {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(isBindToHooker, it.first.result)
|
setInstance(it.first.result)
|
||||||
}.result { ms ->
|
}.result { ms ->
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Constructor [$it] takes ${ms}ms") }
|
||||||
?.forEach { onDebuggingMsg(msg = "Find Constructor [$it] takes ${ms}ms [${hookTag}]") }
|
|
||||||
}
|
}
|
||||||
isFindSuccess = true
|
isFindSuccess = true
|
||||||
it.second.onFindCallback?.invoke(memberInstances.constructors())
|
it.second.onFindCallback?.invoke(memberInstances.constructors())
|
||||||
remedyPlansCallback?.invoke()
|
remedyPlansCallback?.invoke()
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }
|
||||||
?.forEach { onDebuggingMsg(msg = "Constructor [$it] trying ${p + 1} times success by RemedyPlan [${hookTag}]") }
|
?.forEach { onDebuggingMsg(msg = "Constructor [$it] trying ${p + 1} times success by RemedyPlan") }
|
||||||
return@run
|
return@run
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
lastError = it
|
lastError = it
|
||||||
@@ -348,7 +352,7 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
)
|
)
|
||||||
remedyPlans.clear()
|
remedyPlans.clear()
|
||||||
}
|
}
|
||||||
} else yLoggerW(msg = "RemedyPlan is empty, forgot it? [${hookTag}]")
|
} else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -372,7 +376,7 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [Constructor] 查找结果处理类 - 为 [hookInstance] 提供
|
* [Constructor] 查找结果处理类 - 为 [hookerManager] 提供
|
||||||
* @param isNoSuch 是否没有找到 [Constructor] - 默认否
|
* @param isNoSuch 是否没有找到 [Constructor] - 默认否
|
||||||
* @param throwable 错误信息
|
* @param throwable 错误信息
|
||||||
*/
|
*/
|
||||||
@@ -389,14 +393,11 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
inline fun result(initiate: Process.() -> Unit) = apply(initiate)
|
inline fun result(initiate: Process.() -> Unit) = apply(initiate)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置全部查找条件匹配的多个 [Constructor] 实例结果到 [hookInstance]
|
* 设置全部查找条件匹配的多个 [Constructor] 实例结果到 [hookerManager]
|
||||||
* @return [Process] 可继续向下监听
|
* @return [Process] 可继续向下监听
|
||||||
*/
|
*/
|
||||||
fun all(): Process {
|
fun all(): Process {
|
||||||
fun HashSet<Member>.bind() = takeIf { it.isNotEmpty() }?.apply {
|
fun HashSet<Member>.bind() = takeIf { it.isNotEmpty() }?.apply { hookerManager.bindMembers(members = this) }.unit()
|
||||||
hookInstance?.members?.clear()
|
|
||||||
forEach { hookInstance?.members?.add(it) }
|
|
||||||
}.unit()
|
|
||||||
if (isUsingRemedyPlan)
|
if (isUsingRemedyPlan)
|
||||||
remedyPlansCallback = { memberInstances.bind() }
|
remedyPlansCallback = { memberInstances.bind() }
|
||||||
else memberInstances.bind()
|
else memberInstances.bind()
|
||||||
@@ -554,7 +555,7 @@ class ConstructorFinder @PublishedApi internal constructor(
|
|||||||
/**
|
/**
|
||||||
* 忽略异常并停止打印任何错误日志
|
* 忽略异常并停止打印任何错误日志
|
||||||
*
|
*
|
||||||
* - 若 [isNotIgnoredNoSuchMemberFailure] 为 false 则自动忽略
|
* - 若 [MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure] 为 false 则自动忽略
|
||||||
*
|
*
|
||||||
* - ❗此时若要监听异常结果 - 你需要手动实现 [onNoSuchConstructor] 方法
|
* - ❗此时若要监听异常结果 - 你需要手动实现 [onNoSuchConstructor] 方法
|
||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
|
@@ -41,11 +41,9 @@ 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.ModifierConditions
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.type.factory.NameConditions
|
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.ObjectConditions
|
||||||
import com.highcapable.yukihookapi.hook.factory.checkingInternal
|
|
||||||
import com.highcapable.yukihookapi.hook.factory.current
|
import com.highcapable.yukihookapi.hook.factory.current
|
||||||
import com.highcapable.yukihookapi.hook.factory.hasExtends
|
import com.highcapable.yukihookapi.hook.factory.hasExtends
|
||||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||||
import com.highcapable.yukihookapi.hook.utils.await
|
|
||||||
import com.highcapable.yukihookapi.hook.utils.runBlocking
|
import com.highcapable.yukihookapi.hook.utils.runBlocking
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
|
|
||||||
@@ -53,13 +51,24 @@ import java.lang.reflect.Field
|
|||||||
* [Field] 查找类
|
* [Field] 查找类
|
||||||
*
|
*
|
||||||
* 可通过指定类型查找指定 [Field] 或一组 [Field]
|
* 可通过指定类型查找指定 [Field] 或一组 [Field]
|
||||||
* @param hookInstance 当前 Hook 实例
|
|
||||||
* @param classSet 当前需要查找的 [Class] 实例
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
*/
|
*/
|
||||||
class FieldFinder @PublishedApi internal constructor(
|
class FieldFinder @PublishedApi internal constructor(@PublishedApi override val classSet: Class<*>? = null) :
|
||||||
@PublishedApi override val hookInstance: YukiMemberHookCreator.MemberHookCreator? = null,
|
MemberBaseFinder(tag = "Field", classSet) {
|
||||||
@PublishedApi override val classSet: Class<*>? = null
|
|
||||||
) : MemberBaseFinder(tag = "Field", hookInstance, classSet) {
|
@PublishedApi
|
||||||
|
internal companion object {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 [YukiMemberHookCreator.MemberHookCreator] 创建 [Field] 查找类
|
||||||
|
* @param hookInstance 当前 Hooker
|
||||||
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
|
* @return [FieldFinder]
|
||||||
|
*/
|
||||||
|
@PublishedApi
|
||||||
|
internal fun fromHooker(hookInstance: YukiMemberHookCreator.MemberHookCreator, classSet: Class<*>? = null) =
|
||||||
|
FieldFinder(classSet).apply { hookerManager.instance = hookInstance }
|
||||||
|
}
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
override var rulesData = FieldRulesData()
|
override var rulesData = FieldRulesData()
|
||||||
@@ -205,18 +214,24 @@ class FieldFinder @PublishedApi internal constructor(
|
|||||||
fields.takeIf { it.isNotEmpty() }?.forEach { memberInstances.add(it) }
|
fields.takeIf { it.isNotEmpty() }?.forEach { memberInstances.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 得到 [Field] 结果 */
|
||||||
|
private fun internalBuild() {
|
||||||
|
if (classSet == null) error(CLASSSET_IS_NULL)
|
||||||
|
runBlocking {
|
||||||
|
setInstance(result)
|
||||||
|
}.result { ms ->
|
||||||
|
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
override fun build() = runCatching {
|
override fun build() = runCatching {
|
||||||
if (classSet != null) {
|
internalBuild()
|
||||||
classSet.checkingInternal()
|
Result()
|
||||||
runBlocking {
|
}.getOrElse {
|
||||||
setInstance(result)
|
onFailureMsg(throwable = it)
|
||||||
}.result { ms ->
|
Result(isNoSuch = true, it)
|
||||||
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms [${hookTag}]") }
|
}
|
||||||
}
|
|
||||||
Result()
|
|
||||||
} else Result(isNoSuch = true, Throwable(CLASSSET_IS_NULL))
|
|
||||||
}.getOrElse { e -> Result(isNoSuch = true, e).await { onFailureMsg(throwable = e) } }
|
|
||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
override fun process() = error("FieldFinder does not contain this usage")
|
override fun process() = error("FieldFinder does not contain this usage")
|
||||||
@@ -247,8 +262,11 @@ class FieldFinder @PublishedApi internal constructor(
|
|||||||
* @param initiate 方法体
|
* @param initiate 方法体
|
||||||
* @return [Result] 结果
|
* @return [Result] 结果
|
||||||
*/
|
*/
|
||||||
inline fun field(initiate: FieldConditions) =
|
inline fun field(initiate: FieldConditions) = Result().apply {
|
||||||
Result().apply { remedyPlans.add(Pair(FieldFinder(hookInstance, classSet).apply(initiate), this)) }
|
remedyPlans.add(Pair(FieldFinder(classSet).apply {
|
||||||
|
hookerManager = this@FieldFinder.hookerManager
|
||||||
|
}.apply(initiate), this))
|
||||||
|
}
|
||||||
|
|
||||||
/** 开始重查找 */
|
/** 开始重查找 */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -263,13 +281,13 @@ class FieldFinder @PublishedApi internal constructor(
|
|||||||
setInstance(it.first.result)
|
setInstance(it.first.result)
|
||||||
}.result { ms ->
|
}.result { ms ->
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }
|
||||||
?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms [${hookTag}]") }
|
?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms") }
|
||||||
}
|
}
|
||||||
isFindSuccess = true
|
isFindSuccess = true
|
||||||
it.second.onFindCallback?.invoke(memberInstances.fields())
|
it.second.onFindCallback?.invoke(memberInstances.fields())
|
||||||
remedyPlansCallback?.invoke()
|
remedyPlansCallback?.invoke()
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }
|
||||||
?.forEach { onDebuggingMsg(msg = "Field [$it] trying ${p + 1} times success by RemedyPlan [${hookTag}]") }
|
?.forEach { onDebuggingMsg(msg = "Field [$it] trying ${p + 1} times success by RemedyPlan") }
|
||||||
return@run
|
return@run
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
lastError = it
|
lastError = it
|
||||||
@@ -284,7 +302,7 @@ class FieldFinder @PublishedApi internal constructor(
|
|||||||
)
|
)
|
||||||
remedyPlans.clear()
|
remedyPlans.clear()
|
||||||
}
|
}
|
||||||
} else yLoggerW(msg = "RemedyPlan is empty, forgot it? [${hookTag}]")
|
} else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -440,7 +458,7 @@ class FieldFinder @PublishedApi internal constructor(
|
|||||||
/**
|
/**
|
||||||
* 忽略异常并停止打印任何错误日志
|
* 忽略异常并停止打印任何错误日志
|
||||||
*
|
*
|
||||||
* - 若 [isNotIgnoredNoSuchMemberFailure] 为 false 则自动忽略
|
* - 若 [MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure] 为 false 则自动忽略
|
||||||
*
|
*
|
||||||
* - ❗此时若要监听异常结果 - 你需要手动实现 [onNoSuchField] 方法
|
* - ❗此时若要监听异常结果 - 你需要手动实现 [onNoSuchField] 方法
|
||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
|
@@ -38,7 +38,6 @@ 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.members.data.MethodRulesData
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool
|
import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.type.factory.*
|
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.factory.hasExtends
|
||||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||||
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
||||||
@@ -52,13 +51,24 @@ import java.lang.reflect.Method
|
|||||||
* [Method] 查找类
|
* [Method] 查找类
|
||||||
*
|
*
|
||||||
* 可通过指定类型查找指定 [Method] 或一组 [Method]
|
* 可通过指定类型查找指定 [Method] 或一组 [Method]
|
||||||
* @param hookInstance 当前 Hook 实例 - 填写后将自动设置 [YukiMemberHookCreator.MemberHookCreator.members]
|
|
||||||
* @param classSet 当前需要查找的 [Class] 实例
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
*/
|
*/
|
||||||
class MethodFinder @PublishedApi internal constructor(
|
class MethodFinder @PublishedApi internal constructor(@PublishedApi override val classSet: Class<*>? = null) :
|
||||||
@PublishedApi override val hookInstance: YukiMemberHookCreator.MemberHookCreator? = null,
|
MemberBaseFinder(tag = "Method", classSet) {
|
||||||
@PublishedApi override val classSet: Class<*>? = null
|
|
||||||
) : MemberBaseFinder(tag = "Method", hookInstance, classSet) {
|
@PublishedApi
|
||||||
|
internal companion object {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 [YukiMemberHookCreator.MemberHookCreator] 创建 [Method] 查找类
|
||||||
|
* @param hookInstance 当前 Hooker
|
||||||
|
* @param classSet 当前需要查找的 [Class] 实例
|
||||||
|
* @return [MethodFinder]
|
||||||
|
*/
|
||||||
|
@PublishedApi
|
||||||
|
internal fun fromHooker(hookInstance: YukiMemberHookCreator.MemberHookCreator, classSet: Class<*>? = null) =
|
||||||
|
MethodFinder(classSet).apply { hookerManager.instance = hookInstance }
|
||||||
|
}
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
override var rulesData = MethodRulesData()
|
override var rulesData = MethodRulesData()
|
||||||
@@ -329,36 +339,27 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置实例
|
* 设置实例
|
||||||
* @param isBind 是否将结果设置到目标 [YukiMemberHookCreator.MemberHookCreator]
|
|
||||||
* @param methods 当前找到的 [Method] 数组
|
* @param methods 当前找到的 [Method] 数组
|
||||||
*/
|
*/
|
||||||
private fun setInstance(isBind: Boolean, methods: HashSet<Method>) {
|
private fun setInstance(methods: HashSet<Method>) {
|
||||||
memberInstances.clear()
|
memberInstances.clear()
|
||||||
val result = methods.takeIf { it.isNotEmpty() }?.onEach { memberInstances.add(it) }?.first()
|
methods.takeIf { it.isNotEmpty() }?.onEach { memberInstances.add(it) }
|
||||||
if (isBind) hookInstance?.members?.apply {
|
?.first()?.apply { if (hookerManager.isMemberBinded) hookerManager.bindMember(member = this) }
|
||||||
clear()
|
|
||||||
result?.also { add(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 得到 [Method] 结果 */
|
||||||
* 得到 [Method] 结果
|
private fun internalBuild() {
|
||||||
* @param isBind 是否将结果设置到目标 [YukiMemberHookCreator.MemberHookCreator]
|
|
||||||
*/
|
|
||||||
private fun build(isBind: Boolean) {
|
|
||||||
if (classSet == null) error(CLASSSET_IS_NULL)
|
if (classSet == null) error(CLASSSET_IS_NULL)
|
||||||
classSet.checkingInternal()
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
isBindToHooker = isBind
|
setInstance(result)
|
||||||
setInstance(isBind, result)
|
|
||||||
}.result { ms ->
|
}.result { ms ->
|
||||||
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Method [$it] takes ${ms}ms [${hookTag}]") }
|
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Method [$it] takes ${ms}ms") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
override fun build() = runCatching {
|
override fun build() = runCatching {
|
||||||
build(isBind = false)
|
internalBuild()
|
||||||
Result()
|
Result()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
onFailureMsg(throwable = it)
|
||||||
@@ -367,7 +368,8 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
override fun process() = runCatching {
|
override fun process() = runCatching {
|
||||||
build(isBind = true)
|
hookerManager.isMemberBinded = true
|
||||||
|
internalBuild()
|
||||||
Process()
|
Process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
onFailureMsg(throwable = it)
|
||||||
@@ -400,8 +402,11 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
* @param initiate 方法体
|
* @param initiate 方法体
|
||||||
* @return [Result] 结果
|
* @return [Result] 结果
|
||||||
*/
|
*/
|
||||||
inline fun method(initiate: MethodConditions) =
|
inline fun method(initiate: MethodConditions) = Result().apply {
|
||||||
Result().apply { remedyPlans.add(Pair(MethodFinder(hookInstance, classSet).apply(initiate), this)) }
|
remedyPlans.add(Pair(MethodFinder(classSet).apply {
|
||||||
|
hookerManager = this@MethodFinder.hookerManager
|
||||||
|
}.apply(initiate), this))
|
||||||
|
}
|
||||||
|
|
||||||
/** 开始重查找 */
|
/** 开始重查找 */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -413,16 +418,15 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
remedyPlans.forEachIndexed { p, it ->
|
remedyPlans.forEachIndexed { p, it ->
|
||||||
runCatching {
|
runCatching {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(isBindToHooker, it.first.result)
|
setInstance(it.first.result)
|
||||||
}.result { ms ->
|
}.result { ms ->
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Method [$it] takes ${ms}ms") }
|
||||||
?.forEach { onDebuggingMsg(msg = "Find Method [$it] takes ${ms}ms [${hookTag}]") }
|
|
||||||
}
|
}
|
||||||
isFindSuccess = true
|
isFindSuccess = true
|
||||||
it.second.onFindCallback?.invoke(memberInstances.methods())
|
it.second.onFindCallback?.invoke(memberInstances.methods())
|
||||||
remedyPlansCallback?.invoke()
|
remedyPlansCallback?.invoke()
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }
|
||||||
?.forEach { onDebuggingMsg(msg = "Method [$it] trying ${p + 1} times success by RemedyPlan [${hookTag}]") }
|
?.forEach { onDebuggingMsg(msg = "Method [$it] trying ${p + 1} times success by RemedyPlan") }
|
||||||
return@run
|
return@run
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
lastError = it
|
lastError = it
|
||||||
@@ -437,7 +441,7 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
)
|
)
|
||||||
remedyPlans.clear()
|
remedyPlans.clear()
|
||||||
}
|
}
|
||||||
} else yLoggerW(msg = "RemedyPlan is empty, forgot it? [${hookTag}]")
|
} else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -461,7 +465,7 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [Method] 查找结果处理类 - 为 [hookInstance] 提供
|
* [Method] 查找结果处理类 - 为 [hookerManager] 提供
|
||||||
* @param isNoSuch 是否没有找 [Method] - 默认否
|
* @param isNoSuch 是否没有找 [Method] - 默认否
|
||||||
* @param throwable 错误信息
|
* @param throwable 错误信息
|
||||||
*/
|
*/
|
||||||
@@ -478,14 +482,11 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
inline fun result(initiate: Process.() -> Unit) = apply(initiate)
|
inline fun result(initiate: Process.() -> Unit) = apply(initiate)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置全部查找条件匹配的多个 [Method] 实例结果到 [hookInstance]
|
* 设置全部查找条件匹配的多个 [Method] 实例结果到 [hookerManager]
|
||||||
* @return [Process] 可继续向下监听
|
* @return [Process] 可继续向下监听
|
||||||
*/
|
*/
|
||||||
fun all(): Process {
|
fun all(): Process {
|
||||||
fun HashSet<Member>.bind() = takeIf { it.isNotEmpty() }?.apply {
|
fun HashSet<Member>.bind() = takeIf { it.isNotEmpty() }?.apply { hookerManager.bindMembers(members = this) }.unit()
|
||||||
hookInstance?.members?.clear()
|
|
||||||
forEach { hookInstance?.members?.add(it) }
|
|
||||||
}.unit()
|
|
||||||
if (isUsingRemedyPlan)
|
if (isUsingRemedyPlan)
|
||||||
remedyPlansCallback = { memberInstances.bind() }
|
remedyPlansCallback = { memberInstances.bind() }
|
||||||
else memberInstances.bind()
|
else memberInstances.bind()
|
||||||
@@ -650,7 +651,7 @@ class MethodFinder @PublishedApi internal constructor(
|
|||||||
/**
|
/**
|
||||||
* 忽略异常并停止打印任何错误日志
|
* 忽略异常并停止打印任何错误日志
|
||||||
*
|
*
|
||||||
* - 若 [isNotIgnoredNoSuchMemberFailure] 为 false 则自动忽略
|
* - 若 [MemberBaseFinder.MemberHookerManager.isNotIgnoredNoSuchMemberFailure] 为 false 则自动忽略
|
||||||
*
|
*
|
||||||
* - ❗此时若要监听异常结果 - 你需要手动实现 [onNoSuchMethod] 方法
|
* - ❗此时若要监听异常结果 - 你需要手动实现 [onNoSuchMethod] 方法
|
||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
|
Reference in New Issue
Block a user