mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 02:35:40 +08:00
Modify merge finder lambda to typealias
This commit is contained in:
@@ -29,6 +29,8 @@ package com.highcapable.yukihookapi.hook.bean
|
||||
|
||||
import com.highcapable.yukihookapi.hook.core.finder.FieldFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.MethodFinder
|
||||
import com.highcapable.yukihookapi.hook.factory.FieldCondition
|
||||
import com.highcapable.yukihookapi.hook.factory.MethodCondition
|
||||
import com.highcapable.yukihookapi.hook.factory.field
|
||||
import com.highcapable.yukihookapi.hook.factory.method
|
||||
|
||||
@@ -50,14 +52,14 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
|
||||
* @param initiate 查找方法体
|
||||
* @return [FieldFinder.Result.Instance]
|
||||
*/
|
||||
inline fun field(initiate: FieldFinder.() -> Unit) = classSet.field(initiate).get(instance)
|
||||
inline fun field(initiate: FieldCondition) = classSet.field(initiate).get(instance)
|
||||
|
||||
/**
|
||||
* 调用当前实例中的方法
|
||||
* @param initiate 查找方法体
|
||||
* @return [MethodFinder.Result.Instance]
|
||||
*/
|
||||
inline fun method(initiate: MethodFinder.() -> Unit) = classSet.method(initiate).get(instance)
|
||||
inline fun method(initiate: MethodCondition) = classSet.method(initiate).get(instance)
|
||||
|
||||
/**
|
||||
* 当前类的父类实例的类操作对象
|
||||
@@ -71,13 +73,13 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
|
||||
* @param initiate 查找方法体
|
||||
* @return [FieldFinder.Result.Instance]
|
||||
*/
|
||||
inline fun field(initiate: FieldFinder.() -> Unit) = classSet.superclass.field(initiate).get(instance)
|
||||
inline fun field(initiate: FieldCondition) = classSet.superclass.field(initiate).get(instance)
|
||||
|
||||
/**
|
||||
* 调用父类实例中的方法
|
||||
* @param initiate 查找方法体
|
||||
* @return [MethodFinder.Result.Instance]
|
||||
*/
|
||||
inline fun method(initiate: MethodFinder.() -> Unit) = classSet.superclass.method(initiate).get(instance)
|
||||
inline fun method(initiate: MethodCondition) = classSet.superclass.method(initiate).get(instance)
|
||||
}
|
||||
}
|
@@ -35,8 +35,7 @@ import com.highcapable.yukihookapi.hook.core.finder.ConstructorFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.FieldFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.MethodFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.base.BaseFinder
|
||||
import com.highcapable.yukihookapi.hook.factory.allConstructors
|
||||
import com.highcapable.yukihookapi.hook.factory.allMethods
|
||||
import com.highcapable.yukihookapi.hook.factory.*
|
||||
import com.highcapable.yukihookapi.hook.log.yLoggerE
|
||||
import com.highcapable.yukihookapi.hook.log.yLoggerI
|
||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||
@@ -279,7 +278,7 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara
|
||||
* @param initiate 方法体
|
||||
* @return [MethodFinder.Result]
|
||||
*/
|
||||
inline fun method(initiate: MethodFinder.() -> Unit) = try {
|
||||
inline fun method(initiate: MethodCondition) = try {
|
||||
isHookMemberSetup = true
|
||||
MethodFinder(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.build(isBind = true)
|
||||
} catch (e: Throwable) {
|
||||
@@ -294,7 +293,7 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara
|
||||
* @param initiate 方法体
|
||||
* @return [ConstructorFinder.Result]
|
||||
*/
|
||||
inline fun constructor(initiate: ConstructorFinder.() -> Unit = { emptyParam() }) = try {
|
||||
inline fun constructor(initiate: ConstructorCondition = { emptyParam() }) = try {
|
||||
isHookMemberSetup = true
|
||||
ConstructorFinder(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.build(isBind = true)
|
||||
} catch (e: Throwable) {
|
||||
@@ -307,7 +306,7 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara
|
||||
* @param initiate 方法体
|
||||
* @return [FieldFinder.Result]
|
||||
*/
|
||||
inline fun HookParam.field(initiate: FieldFinder.() -> Unit) =
|
||||
inline fun HookParam.field(initiate: FieldCondition) =
|
||||
if (hookClass.instance == null) FieldFinder(hookInstance = this@MemberHookCreater).failure(hookClass.throwable)
|
||||
else FieldFinder(hookInstance = this@MemberHookCreater, hookClass.instance).apply(initiate).build()
|
||||
|
||||
@@ -316,7 +315,7 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara
|
||||
* @param initiate 方法体
|
||||
* @return [MethodFinder.Result]
|
||||
*/
|
||||
inline fun HookParam.method(initiate: MethodFinder.() -> Unit) =
|
||||
inline fun HookParam.method(initiate: MethodCondition) =
|
||||
if (hookClass.instance == null) MethodFinder(hookInstance = this@MemberHookCreater).failure(hookClass.throwable)
|
||||
else MethodFinder(hookInstance = this@MemberHookCreater, hookClass.instance).apply(initiate).build()
|
||||
|
||||
@@ -325,7 +324,7 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara
|
||||
* @param initiate 方法体
|
||||
* @return [ConstructorFinder.Result]
|
||||
*/
|
||||
inline fun HookParam.constructor(initiate: ConstructorFinder.() -> Unit = { emptyParam() }) =
|
||||
inline fun HookParam.constructor(initiate: ConstructorCondition = { emptyParam() }) =
|
||||
if (hookClass.instance == null) ConstructorFinder(hookInstance = this@MemberHookCreater).failure(hookClass.throwable)
|
||||
else ConstructorFinder(hookInstance = this@MemberHookCreater, hookClass.instance).apply(initiate).build()
|
||||
|
||||
|
@@ -35,6 +35,7 @@ import com.highcapable.yukihookapi.hook.core.YukiMemberHookCreater
|
||||
import com.highcapable.yukihookapi.hook.core.finder.base.BaseFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.ModifierRules
|
||||
import com.highcapable.yukihookapi.hook.core.reflex.tools.ReflectionTool
|
||||
import com.highcapable.yukihookapi.hook.factory.ConstructorCondition
|
||||
import com.highcapable.yukihookapi.hook.factory.hasExtends
|
||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
||||
@@ -245,7 +246,7 @@ class ConstructorFinder @PublishedApi internal constructor(
|
||||
* 若最后依然失败 - 将停止查找并输出错误日志
|
||||
* @param initiate 方法体
|
||||
*/
|
||||
inline fun constructor(initiate: ConstructorFinder.() -> Unit) =
|
||||
inline fun constructor(initiate: ConstructorCondition) =
|
||||
Result().apply { remedyPlans.add(Pair(ConstructorFinder(hookInstance, classSet).apply(initiate), this)) }
|
||||
|
||||
/** 开始重查找 */
|
||||
|
@@ -36,6 +36,7 @@ import com.highcapable.yukihookapi.hook.core.finder.base.BaseFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.ModifierRules
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.NameConditions
|
||||
import com.highcapable.yukihookapi.hook.core.reflex.tools.ReflectionTool
|
||||
import com.highcapable.yukihookapi.hook.factory.FieldCondition
|
||||
import com.highcapable.yukihookapi.hook.factory.hasExtends
|
||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||
import com.highcapable.yukihookapi.hook.utils.await
|
||||
@@ -236,7 +237,7 @@ class FieldFinder @PublishedApi internal constructor(
|
||||
* @param initiate 方法体
|
||||
* @return [Result] 结果
|
||||
*/
|
||||
inline fun field(initiate: FieldFinder.() -> Unit) =
|
||||
inline fun field(initiate: FieldCondition) =
|
||||
Result().apply { remedyPlans.add(Pair(FieldFinder(hookInstance, classSet).apply(initiate), this)) }
|
||||
|
||||
/** 开始重查找 */
|
||||
|
@@ -36,6 +36,7 @@ import com.highcapable.yukihookapi.hook.core.finder.base.BaseFinder
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.ModifierRules
|
||||
import com.highcapable.yukihookapi.hook.core.finder.type.NameConditions
|
||||
import com.highcapable.yukihookapi.hook.core.reflex.tools.ReflectionTool
|
||||
import com.highcapable.yukihookapi.hook.factory.MethodCondition
|
||||
import com.highcapable.yukihookapi.hook.factory.hasExtends
|
||||
import com.highcapable.yukihookapi.hook.log.yLoggerW
|
||||
import com.highcapable.yukihookapi.hook.type.defined.UndefinedType
|
||||
@@ -313,7 +314,7 @@ class MethodFinder @PublishedApi internal constructor(
|
||||
* @param initiate 方法体
|
||||
* @return [Result] 结果
|
||||
*/
|
||||
inline fun method(initiate: MethodFinder.() -> Unit) =
|
||||
inline fun method(initiate: MethodCondition) =
|
||||
Result().apply { remedyPlans.add(Pair(MethodFinder(hookInstance, classSet).apply(initiate), this)) }
|
||||
|
||||
/** 开始重查找 */
|
||||
|
@@ -42,6 +42,15 @@ import java.lang.reflect.Field
|
||||
import java.lang.reflect.Member
|
||||
import java.lang.reflect.Method
|
||||
|
||||
/** 定义 [FieldFinder] 方法体类型 */
|
||||
internal typealias FieldCondition = FieldFinder.() -> Unit
|
||||
|
||||
/** 定义 [MethodFinder] 方法体类型 */
|
||||
internal typealias MethodCondition = MethodFinder.() -> Unit
|
||||
|
||||
/** 定义 [ConstructorFinder] 方法体类型 */
|
||||
internal typealias ConstructorCondition = ConstructorFinder.() -> Unit
|
||||
|
||||
/**
|
||||
* 当前 [Class] 是否有继承关系 - 父类是 [Any] 将被认为没有继承关系
|
||||
* @return [Boolean]
|
||||
@@ -96,21 +105,21 @@ fun String.hasClass(loader: ClassLoader? = null) = try {
|
||||
* @param initiate 方法体
|
||||
* @return [Boolean] 是否存在
|
||||
*/
|
||||
inline fun Class<*>.hasField(initiate: FieldFinder.() -> Unit) = field(initiate).ignored().isNoSuch.not()
|
||||
inline fun Class<*>.hasField(initiate: FieldCondition) = field(initiate).ignored().isNoSuch.not()
|
||||
|
||||
/**
|
||||
* 查找方法是否存在
|
||||
* @param initiate 方法体
|
||||
* @return [Boolean] 是否存在
|
||||
*/
|
||||
inline fun Class<*>.hasMethod(initiate: MethodFinder.() -> Unit) = method(initiate).ignored().isNoSuch.not()
|
||||
inline fun Class<*>.hasMethod(initiate: MethodCondition) = method(initiate).ignored().isNoSuch.not()
|
||||
|
||||
/**
|
||||
* 查找构造方法是否存在
|
||||
* @param initiate 方法体
|
||||
* @return [Boolean] 是否存在
|
||||
*/
|
||||
inline fun Class<*>.hasConstructor(initiate: ConstructorFinder.() -> Unit = { emptyParam() }) = constructor(initiate).ignored().isNoSuch.not()
|
||||
inline fun Class<*>.hasConstructor(initiate: ConstructorCondition = { emptyParam() }) = constructor(initiate).ignored().isNoSuch.not()
|
||||
|
||||
/**
|
||||
* 查询 [Member] 中匹配的描述符
|
||||
@@ -124,22 +133,21 @@ inline fun Member.hasModifiers(initiate: ModifierRules.() -> Unit) = ModifierRul
|
||||
* @param initiate 查找方法体
|
||||
* @return [FieldFinder.Result]
|
||||
*/
|
||||
inline fun Class<*>.field(initiate: FieldFinder.() -> Unit) = FieldFinder(classSet = this).apply(initiate).build()
|
||||
inline fun Class<*>.field(initiate: FieldCondition) = FieldFinder(classSet = this).apply(initiate).build()
|
||||
|
||||
/**
|
||||
* 查找并得到方法
|
||||
* @param initiate 查找方法体
|
||||
* @return [MethodFinder.Result]
|
||||
*/
|
||||
inline fun Class<*>.method(initiate: MethodFinder.() -> Unit) = MethodFinder(classSet = this).apply(initiate).build()
|
||||
inline fun Class<*>.method(initiate: MethodCondition) = MethodFinder(classSet = this).apply(initiate).build()
|
||||
|
||||
/**
|
||||
* 查找并得到构造方法
|
||||
* @param initiate 查找方法体
|
||||
* @return [ConstructorFinder.Result]
|
||||
*/
|
||||
inline fun Class<*>.constructor(initiate: ConstructorFinder.() -> Unit = { emptyParam() }) =
|
||||
ConstructorFinder(classSet = this).apply(initiate).build()
|
||||
inline fun Class<*>.constructor(initiate: ConstructorCondition = { emptyParam() }) = ConstructorFinder(classSet = this).apply(initiate).build()
|
||||
|
||||
/**
|
||||
* 获得当前实例的类操作对象
|
||||
@@ -167,7 +175,7 @@ inline fun <reified T : Any> T.current(): CurrentClass {
|
||||
* @param initiate 查找方法体
|
||||
* @return [Any] or null
|
||||
*/
|
||||
inline fun Class<*>.buildOfAny(vararg param: Any?, initiate: ConstructorFinder.() -> Unit = { emptyParam() }) =
|
||||
inline fun Class<*>.buildOfAny(vararg param: Any?, initiate: ConstructorCondition = { emptyParam() }) =
|
||||
constructor(initiate).get().call(*param)
|
||||
|
||||
/**
|
||||
@@ -176,7 +184,7 @@ inline fun Class<*>.buildOfAny(vararg param: Any?, initiate: ConstructorFinder.(
|
||||
* @param initiate 查找方法体
|
||||
* @return [T] or null
|
||||
*/
|
||||
inline fun <T> Class<*>.buildOf(vararg param: Any?, initiate: ConstructorFinder.() -> Unit = { emptyParam() }) =
|
||||
inline fun <T> Class<*>.buildOf(vararg param: Any?, initiate: ConstructorCondition = { emptyParam() }) =
|
||||
constructor(initiate).get().newInstance<T>(*param)
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user