diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt index bf2ba779..7c0dedfc 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt @@ -36,6 +36,7 @@ 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.* +import com.highcapable.yukihookapi.hook.log.loggerW import com.highcapable.yukihookapi.hook.log.yLoggerE import com.highcapable.yukihookapi.hook.log.yLoggerI import com.highcapable.yukihookapi.hook.log.yLoggerW @@ -113,13 +114,18 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara YukiHookBridge.hasXposedBridge.not() -> Result() /** 过滤 [HookEntryType.ZYGOTE] 与 [HookEntryType.PACKAGE] 或 [HookParam.isCallbackCalled] 已被执行 */ packageParam.wrapper?.type == HookEntryType.RESOURCES && HookParam.isCallbackCalled.not() -> Result() - preHookMembers.isEmpty() -> error("Hook Members is empty, hook aborted") + preHookMembers.isEmpty() -> Result().also { loggerW(msg = "Hook Members is empty in [${hookClass.name}], hook aborted") } else -> Result().await { warnTerribleHookClass() when { - isDisableCreaterRunHook.not() && hookClass.instance != null -> { + isDisableCreaterRunHook.not() && hookClass.instance != null -> runCatching { + hookClass.instance?.checkingInternal() it.onPrepareHook?.invoke() preHookMembers.forEach { (_, m) -> m.hook() } + }.onFailure { + if (onHookClassNotFoundFailureCallback == null) + yLoggerE(msg = "Hook initialization failed because got an Exception", e = it) + else onHookClassNotFoundFailureCallback?.invoke(it) } isDisableCreaterRunHook.not() && hookClass.instance == null -> if (onHookClassNotFoundFailureCallback == null) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiResourcesHookCreater.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiResourcesHookCreater.kt index 1a7b32a3..2a470b93 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiResourcesHookCreater.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiResourcesHookCreater.kt @@ -32,6 +32,7 @@ package com.highcapable.yukihookapi.hook.core import android.content.res.Resources import com.highcapable.yukihookapi.YukiHookAPI import com.highcapable.yukihookapi.hook.bean.HookResources +import com.highcapable.yukihookapi.hook.log.loggerW import com.highcapable.yukihookapi.hook.log.yLoggerE import com.highcapable.yukihookapi.hook.log.yLoggerI import com.highcapable.yukihookapi.hook.param.PackageParam @@ -69,7 +70,7 @@ class YukiResourcesHookCreater(@PublishedApi internal val packageParam: PackageP if (YukiHookBridge.hasXposedBridge.not()) return /** 过滤 [HookEntryType.ZYGOTE] 与 [HookEntryType.RESOURCES] */ if (packageParam.wrapper?.type == HookEntryType.PACKAGE) return - if (preHookResources.isEmpty()) error("Hook Resources is empty, hook aborted") + if (preHookResources.isEmpty()) return loggerW(msg = "Hook Resources is empty, hook aborted") preHookResources.forEach { (_, r) -> r.hook() } } diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt index bffd3b49..a72124da 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt @@ -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.reflex.tools.ReflectionTool import com.highcapable.yukihookapi.hook.factory.ConstructorCondition +import com.highcapable.yukihookapi.hook.factory.checkingInternal import com.highcapable.yukihookapi.hook.factory.hasExtends import com.highcapable.yukihookapi.hook.log.yLoggerW import com.highcapable.yukihookapi.hook.type.defined.UndefinedType @@ -204,6 +205,7 @@ class ConstructorFinder @PublishedApi internal constructor( @YukiPrivateApi override fun build(isBind: Boolean) = try { if (classSet != null) { + classSet.checkingInternal() runBlocking { isBindToHooker = isBind setInstance(isBind, result) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt index 9d475a7c..b38076db 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt @@ -38,6 +38,7 @@ 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.checkingInternal import com.highcapable.yukihookapi.hook.factory.current import com.highcapable.yukihookapi.hook.factory.hasExtends import com.highcapable.yukihookapi.hook.log.yLoggerW @@ -198,6 +199,7 @@ class FieldFinder @PublishedApi internal constructor( @YukiPrivateApi override fun build(isBind: Boolean) = try { if (classSet != null) { + classSet.checkingInternal() runBlocking { setInstance(result) }.result { ms -> diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt index fc006a06..8d116d00 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt @@ -37,6 +37,7 @@ 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.checkingInternal import com.highcapable.yukihookapi.hook.factory.hasExtends import com.highcapable.yukihookapi.hook.log.yLoggerW import com.highcapable.yukihookapi.hook.type.defined.UndefinedType @@ -271,6 +272,7 @@ class MethodFinder @PublishedApi internal constructor( @YukiPrivateApi override fun build(isBind: Boolean) = try { if (classSet != null) { + classSet.checkingInternal() runBlocking { isBindToHooker = isBind setInstance(isBind, result) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt index 2c801a98..c0e6d3f0 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt @@ -29,6 +29,7 @@ package com.highcapable.yukihookapi.hook.factory +import com.highcapable.yukihookapi.YukiHookAPI import com.highcapable.yukihookapi.hook.bean.CurrentClass import com.highcapable.yukihookapi.hook.core.finder.ConstructorFinder import com.highcapable.yukihookapi.hook.core.finder.FieldFinder @@ -36,6 +37,7 @@ import com.highcapable.yukihookapi.hook.core.finder.MethodFinder import com.highcapable.yukihookapi.hook.core.finder.type.ModifierRules import com.highcapable.yukihookapi.hook.store.MemberCacheStore import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge +import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus import de.robv.android.xposed.XposedHelpers import java.lang.reflect.Constructor import java.lang.reflect.Field @@ -169,7 +171,7 @@ inline fun Class<*>.constructor(initiate: ConstructorCondition = { emptyParam() * @return [T] */ inline fun T.current(initiate: CurrentClass.() -> Unit): T { - if (javaClass.name == CurrentClass::class.java.name) error("Cannot create itself within CurrentClass itself") + javaClass.checkingInternal() CurrentClass(javaClass, instance = this).apply(initiate) return this } @@ -179,7 +181,7 @@ inline fun T.current(initiate: CurrentClass.() -> Unit): T { * @return [CurrentClass] */ inline fun T.current(): CurrentClass { - if (javaClass.name == CurrentClass::class.java.name) error("Cannot create itself within CurrentClass itself") + javaClass.checkingInternal() return CurrentClass(javaClass, instance = this) } @@ -220,4 +222,15 @@ inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructo * @param result 回调 - ([Int] 下标,[Field] 实例) */ inline fun Class<*>.allFields(result: (index: Int, field: Field) -> Unit) = - declaredFields.forEachIndexed { p, it -> result(p, it.apply { isAccessible = true }) } \ No newline at end of file + declaredFields.forEachIndexed { p, it -> result(p, it.apply { isAccessible = true }) } + +/** + * 检查内部类调用 + * @throws RuntimeException 如果遇到非法调用 + */ +@PublishedApi +internal fun Class<*>.checkingInternal() { + if (name == classOf().name) return + if (name == classOf().name || name.startsWith(prefix = "com.highcapable.yukihookapi.hook")) + throw RuntimeException("!!!DO NOT ALLOWED!!! You cannot hook or reflection to call the internal class of the YukiHookAPI itself") +} \ No newline at end of file