diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt index e2a66ffd..4669a514 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreator.kt @@ -39,7 +39,6 @@ import com.highcapable.yukihookapi.hook.core.api.priority.YukiHookPriority import com.highcapable.yukihookapi.hook.core.api.proxy.YukiMemberHook import com.highcapable.yukihookapi.hook.core.api.proxy.YukiMemberReplacement import com.highcapable.yukihookapi.hook.core.api.result.YukiHookResult -import com.highcapable.yukihookapi.hook.core.finder.base.MemberBaseFinder import com.highcapable.yukihookapi.hook.core.finder.members.ConstructorFinder import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder @@ -304,10 +303,6 @@ class YukiMemberHookCreator @PublishedApi internal constructor( @PublishedApi internal var isHookMemberSetup = false - /** 当前的查找实例 */ - @PublishedApi - internal var finder: MemberBaseFinder? = null - /** 当前被 Hook 的 [Method]、[Constructor] 实例数组 */ private val hookedMembers = HashSet() @@ -385,7 +380,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor( */ inline fun method(initiate: MethodConditions) = runCatching { isHookMemberSetup = true - MethodFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process() + MethodFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).process() }.getOrElse { findingThrowable = it MethodFinder.fromHooker(hookInstance = this).denied(it) @@ -400,7 +395,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor( */ inline fun constructor(initiate: ConstructorConditions = { emptyParam() }) = runCatching { isHookMemberSetup = true - ConstructorFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process() + ConstructorFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).process() }.getOrElse { findingThrowable = it ConstructorFinder.fromHooker(hookInstance = this).denied(it) @@ -563,12 +558,11 @@ class YukiMemberHookCreator @PublishedApi internal constructor( internal fun hook() { if (HookApiCategoryHelper.hasAvailableHookApi.not() || isHooked || isDisableMemberRunHook) return isHooked = true - finder?.printLogIfExist() if (hookClass.instance == null) { (hookClass.throwable ?: Throwable("HookClass [${hookClass.name}] not found")).also { onHookingFailureCallback?.invoke(it) onAllFailureCallback?.invoke(it) - if (isNotIgnoredHookingFailure) onHookFailureMsg(it) + if (isNotIgnoredHookingFailure) hookErrorMsg(it) } return } @@ -587,7 +581,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor( }.onFailure { onHookingFailureCallback?.invoke(it) onAllFailureCallback?.invoke(it) - if (isNotIgnoredHookingFailure) onHookFailureMsg(it, member) + if (isNotIgnoredHookingFailure) hookErrorMsg(it, member) } } ?: Throwable("Finding Error isSetUpMember [$isHookMemberSetup] [$tag]").also { onNoSuchMemberFailureCallback?.invoke(it) @@ -617,13 +611,13 @@ class YukiMemberHookCreator @PublishedApi internal constructor( runCatching { replaceHookCallback?.invoke(assign).also { checkingReturnType((param.member as? Method?)?.returnType, it?.javaClass) - if (replaceHookCallback != null) onHookLogMsg(msg = "Replace Hook Member [${this@hook}] done [$tag]") + if (replaceHookCallback != null) hookDebugMsg(msg = "Replace Hook Member [${this@hook}] done [$tag]") HookParam.invoke() } }.getOrElse { onConductFailureCallback?.invoke(assign, it) onAllFailureCallback?.invoke(it) - if (onConductFailureCallback == null && onAllFailureCallback == null) onHookFailureMsg(it, member = this@hook) + if (onConductFailureCallback == null && onAllFailureCallback == null) hookErrorMsg(it, member = this@hook) /** 若发生异常则会自动调用未经 Hook 的原始 [Member] 保证 Hook APP 正常运行 */ assign.callOriginal() } @@ -643,12 +637,12 @@ class YukiMemberHookCreator @PublishedApi internal constructor( runCatching { beforeHookCallback?.invoke(assign) checkingReturnType((param.member as? Method?)?.returnType, param.result?.javaClass) - if (beforeHookCallback != null) onHookLogMsg(msg = "Before Hook Member [${this@hook}] done [$tag]") + if (beforeHookCallback != null) hookDebugMsg(msg = "Before Hook Member [${this@hook}] done [$tag]") HookParam.invoke() }.onFailure { onConductFailureCallback?.invoke(assign, it) onAllFailureCallback?.invoke(it) - if (onConductFailureCallback == null && onAllFailureCallback == null) onHookFailureMsg(it, member = this@hook) + if (onConductFailureCallback == null && onAllFailureCallback == null) hookErrorMsg(it, member = this@hook) if (isOnFailureThrowToApp) param.throwable = it } } @@ -658,12 +652,12 @@ class YukiMemberHookCreator @PublishedApi internal constructor( afterHookParam.assign(afterHookId, param).also { assign -> runCatching { afterHookCallback?.invoke(assign) - if (afterHookCallback != null) onHookLogMsg(msg = "After Hook Member [${this@hook}] done [$tag]") + if (afterHookCallback != null) hookDebugMsg(msg = "After Hook Member [${this@hook}] done [$tag]") HookParam.invoke() }.onFailure { onConductFailureCallback?.invoke(assign, it) onAllFailureCallback?.invoke(it) - if (onConductFailureCallback == null && onAllFailureCallback == null) onHookFailureMsg(it, member = this@hook) + if (onConductFailureCallback == null && onAllFailureCallback == null) hookErrorMsg(it, member = this@hook) if (isOnFailureThrowToApp) param.throwable = it } } @@ -692,19 +686,17 @@ class YukiMemberHookCreator @PublishedApi internal constructor( * Hook 过程中开启了 [YukiHookAPI.Configs.isDebug] 输出调试信息 * @param msg 调试日志内容 */ - private fun onHookLogMsg(msg: String) { + private fun hookDebugMsg(msg: String) { if (YukiHookAPI.Configs.isDebug) yLoggerD(msg = msg) } /** * Hook 失败但未设置 [onAllFailureCallback] 将默认输出失败信息 - * @param throwable 异常信息 + * @param e 异常堆栈 * @param member 异常 [Member] - 可空 */ - private fun onHookFailureMsg(throwable: Throwable, member: Member? = null) = yLoggerE( - msg = "Try to hook [${hookClass.instance ?: hookClass.name}]${member?.let { "[$it]" } ?: ""} got an Exception [$tag]", - e = throwable - ) + private fun hookErrorMsg(e: Throwable, member: Member? = null) = + yLoggerE(msg = "Try to hook [${hookClass.instance ?: hookClass.name}]${member?.let { "[$it]" } ?: ""} got an Exception [$tag]", e = e) /** * 判断是否没有设置 Hook 过程中的任何异常拦截 @@ -858,7 +850,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor( hookedMembers.takeIf { it.isNotEmpty() }?.apply { forEach { it.remove() - onHookLogMsg(msg = "Remove Hooked Member [${it.member}] done [$tag]") + hookDebugMsg(msg = "Remove Hooked Member [${it.member}] done [$tag]") } runCatching { preHookMembers.remove(this@MemberHookCreator.toString()) } clear() diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/ClassBaseFinder.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/ClassBaseFinder.kt index f72c17a4..be4e8624 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/ClassBaseFinder.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/ClassBaseFinder.kt @@ -49,7 +49,7 @@ abstract class ClassBaseFinder internal constructor(internal open val loaderSet: internal var classInstances = HashSet>() /** 是否开启忽略错误警告功能 */ - internal var isShutErrorPrinting = false + internal var isIgnoreErrorLogs = false /** * 将目标类型转换为可识别的兼容类型 @@ -61,21 +61,21 @@ abstract class ClassBaseFinder internal constructor(internal open val loaderSet: /** * 在开启 [YukiHookAPI.Configs.isDebug] 且在 [HookApiCategoryHelper.hasAvailableHookApi] 情况下输出调试信息 - * @param msg 调试日志内容 + * @param msg 消息内容 */ - internal fun onDebuggingMsg(msg: String) { + internal fun debugMsg(msg: String) { if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi) yLoggerD(msg = msg) } /** * 发生错误时输出日志 - * @param throwable 错误 + * @param e 异常堆栈 - 默认空 */ - internal fun onFailureMsg(throwable: Throwable? = null) { - if (isShutErrorPrinting) return + internal fun errorMsg(e: Throwable? = null) { + if (isIgnoreErrorLogs) return /** 判断是否为 [LOADERSET_IS_NULL] */ - if (throwable?.message == LOADERSET_IS_NULL) return - yLoggerE(msg = "NoClassDefFound happend in [$loaderSet]", e = throwable) + if (e?.message == LOADERSET_IS_NULL) return + yLoggerE(msg = "NoClassDefFound happend in [$loaderSet]", e = e) } @YukiPrivateApi diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/MemberBaseFinder.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/MemberBaseFinder.kt index f7e4a344..162c337d 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/MemberBaseFinder.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/base/MemberBaseFinder.kt @@ -34,7 +34,6 @@ import com.highcapable.yukihookapi.hook.core.api.compat.HookApiCategoryHelper import com.highcapable.yukihookapi.hook.log.yLoggerD import com.highcapable.yukihookapi.hook.log.yLoggerE import com.highcapable.yukihookapi.hook.utils.factory.await -import com.highcapable.yukihookapi.hook.utils.factory.unit import java.lang.reflect.Constructor import java.lang.reflect.Field import java.lang.reflect.Member @@ -65,14 +64,11 @@ abstract class MemberBaseFinder internal constructor( internal var isUsingRemedyPlan = false /** 是否开启忽略错误警告功能 */ - internal var isShutErrorPrinting = false + internal var isIgnoreErrorLogs = false /** 当前找到的 [Member] 数组 */ internal var memberInstances = HashSet() - /** 需要输出的日志内容 */ - private var loggingContent: Pair? = null - /** * 将 [HashSet]<[Member]> 转换为 [HashSet]<[Field]> * @return [HashSet]<[Field]> @@ -101,43 +97,30 @@ abstract class MemberBaseFinder internal constructor( internal fun Any?.compat() = compat(tag, classSet?.classLoader) /** - * 发生错误时输出日志 - * @param msg 消息日志 - * @param throwable 错误 - * @param isAlwaysPrint 忽略条件每次都打印错误 + * 在开启 [YukiHookAPI.Configs.isDebug] 且在 [HookApiCategoryHelper.hasAvailableHookApi] 且在 Hook 过程中情况下输出调试信息 + * @param msg 消息内容 */ - internal fun onFailureMsg(msg: String = "", throwable: Throwable? = null, isAlwaysPrint: Boolean = false) { - /** 创建日志 */ - fun build() { - if (hookerManager.isNotIgnoredNoSuchMemberFailure && isUsingRemedyPlan.not() && isShutErrorPrinting.not()) - loggingContent = Pair(msg, throwable) - } - /** 判断是否为 [CLASSSET_IS_NULL] */ - if (throwable?.message == CLASSSET_IS_NULL) return - /** 判断绑定到 Hooker 时仅创建日志 */ - if (hookerManager.instance != null) return await { build() }.unit() - /** 判断始终输出日志或等待结果后输出日志 */ - if (isAlwaysPrint) build().run { printLogIfExist() } - else await { build().run { printLogIfExist() } } - } - - /** 存在日志时输出日志 */ - internal fun printLogIfExist() { - if (loggingContent != null) yLoggerE( - msg = "NoSuch$tag happend in [$classSet] ${loggingContent?.first}${hookerManager.tailTag}", - e = loggingContent?.second - ) - /** 仅输出一次 - 然后清掉日志 */ - loggingContent = null + internal fun debugMsg(msg: String) { + if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi && hookerManager.instance != null) + yLoggerD(msg = "$msg${hookerManager.tailTag}") } /** - * 在开启 [YukiHookAPI.Configs.isDebug] 且在 [HookApiCategoryHelper.hasAvailableHookApi] 且在 Hook 过程中情况下输出调试信息 - * @param msg 调试日志内容 + * 发生错误时输出日志 + * @param msg 消息内容 + * @param e 异常堆栈 - 默认空 + * @param e 异常堆栈数组 - 默认空 + * @param isAlwaysMode 忽略条件每次都输出日志 */ - internal fun onDebuggingMsg(msg: String) { - if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi && hookerManager.instance != null) - yLoggerD(msg = "$msg${hookerManager.tailTag}") + internal fun errorMsg(msg: String = "", e: Throwable? = null, es: List = emptyList(), isAlwaysMode: Boolean = false) { + /** 判断是否为 [CLASSSET_IS_NULL] */ + if (e?.message == CLASSSET_IS_NULL) return + await { + if (isIgnoreErrorLogs || hookerManager.isNotIgnoredNoSuchMemberFailure.not()) return@await + if (isAlwaysMode.not() && isUsingRemedyPlan) return@await + yLoggerE(msg = "NoSuch$tag happend in [$classSet] $msg${hookerManager.tailTag}".trim(), e = e) + es.forEachIndexed { index, e -> yLoggerE(msg = "Throwable [${index + 1}]", e = e) } + } } /** diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/classes/DexClassFinder.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/classes/DexClassFinder.kt index 083500ca..ba2f49a6 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/classes/DexClassFinder.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/classes/DexClassFinder.kt @@ -484,7 +484,7 @@ class DexClassFinder @PublishedApi internal constructor( fun startProcess() { runBlocking { setInstance(readFromCache().takeIf { it.isNotEmpty() } ?: result) - }.result { ms -> classInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Class [$it] takes ${ms}ms") } } + }.result { ms -> classInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Class [$it] takes ${ms}ms") } } } Result().also { e -> if (async) e.await { @@ -497,12 +497,12 @@ class DexClassFinder @PublishedApi internal constructor( it.isNotFound = true it.throwable = e it.noClassDefFoundErrorCallback?.invoke() - onFailureMsg(throwable = e) + errorMsg(e = e) } } else startProcess() } - } else Result(isNotFound = true, Throwable(LOADERSET_IS_NULL)).await { onFailureMsg() } - }.getOrElse { e -> Result(isNotFound = true, e).await { onFailureMsg(throwable = e) } } + } else Result(isNotFound = true, Throwable(LOADERSET_IS_NULL)).await { errorMsg() } + }.getOrElse { e -> Result(isNotFound = true, e).await { errorMsg(e = e) } } /** * [Class] 查找结果实现类 @@ -620,7 +620,7 @@ class DexClassFinder @PublishedApi internal constructor( * @return [Result] 可继续向下监听 */ fun ignored(): Result { - isShutErrorPrinting = true + isIgnoreErrorLogs = true return this } } diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt index c79020ca..360b3410 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/ConstructorFinder.kt @@ -265,7 +265,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid runBlocking { setInstance(result) }.result { ms -> - memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Constructor [$it] takes ${ms}ms") } + memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Constructor [$it] takes ${ms}ms") } } } @@ -274,7 +274,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid internalBuild() Result() }.getOrElse { - onFailureMsg(throwable = it) + errorMsg(e = it) Result(isNoSuch = true, it) } @@ -284,7 +284,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid internalBuild() Process() }.getOrElse { - onFailureMsg(throwable = it) + errorMsg(e = it) Process(isNoSuch = true, it) } @@ -323,35 +323,27 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid @PublishedApi internal fun build() { if (classSet == null) return - if (remedyPlans.isNotEmpty()) run { + if (remedyPlans.isNotEmpty()) { + val errors = mutableListOf() var isFindSuccess = false - var lastError: Throwable? = null - remedyPlans.forEachIndexed { p, it -> + remedyPlans.forEachIndexed { index, plan -> runCatching { runBlocking { - setInstance(it.first.result) + setInstance(plan.first.result) }.result { ms -> - memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Constructor [$it] takes ${ms}ms") } + memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Constructor [$it] takes ${ms}ms") } } isFindSuccess = true - it.second.onFindCallback?.invoke(memberInstances.constructors()) + plan.second.onFindCallback?.invoke(memberInstances.constructors()) remedyPlansCallback?.invoke() memberInstances.takeIf { it.isNotEmpty() } - ?.forEach { onDebuggingMsg(msg = "Constructor [$it] trying ${p + 1} times success by RemedyPlan") } - return@run - }.onFailure { - lastError = it - onFailureMsg(msg = "Trying ${p + 1} times by RemedyPlan --> $it", isAlwaysPrint = true) - } - } - if (isFindSuccess.not()) { - onFailureMsg( - msg = "Trying ${remedyPlans.size} times and all failure by RemedyPlan", - throwable = lastError, - isAlwaysPrint = true - ) - remedyPlans.clear() + ?.forEach { debugMsg(msg = "RemedyPlan successed after ${index + 1} attempts of Constructor [$it]") } + return + }.onFailure { errors.add(it) } } + if (isFindSuccess) return + errorMsg(msg = "RemedyPlan failed after ${remedyPlans.size} attempts", es = errors, isAlwaysMode = true) + remedyPlans.clear() } else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}") } @@ -561,7 +553,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid * @return [Result] 可继续向下监听 */ fun ignored(): Result { - isShutErrorPrinting = true + isIgnoreErrorLogs = true return this } diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt index 9353c100..122dbc2b 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/FieldFinder.kt @@ -220,7 +220,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val runBlocking { setInstance(result) }.result { ms -> - memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms") } + memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Field [$it] takes ${ms}ms") } } } @@ -229,7 +229,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val internalBuild() Result() }.getOrElse { - onFailureMsg(throwable = it) + errorMsg(e = it) Result(isNoSuch = true, it) } @@ -263,45 +263,36 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val * @return [Result] 结果 */ inline fun field(initiate: FieldConditions) = Result().apply { - remedyPlans.add(Pair(FieldFinder(classSet).apply { + remedyPlans.add(FieldFinder(classSet).apply { hookerManager = this@FieldFinder.hookerManager - }.apply(initiate), this)) + }.apply(initiate) to this) } /** 开始重查找 */ @PublishedApi internal fun build() { if (classSet == null) return - if (remedyPlans.isNotEmpty()) run { + if (remedyPlans.isNotEmpty()) { + val errors = mutableListOf() var isFindSuccess = false - var lastError: Throwable? = null - remedyPlans.forEachIndexed { p, it -> + remedyPlans.forEachIndexed { index, plan -> runCatching { runBlocking { - setInstance(it.first.result) + setInstance(plan.first.result) }.result { ms -> - memberInstances.takeIf { it.isNotEmpty() } - ?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms") } + memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Field [$it] takes ${ms}ms") } } isFindSuccess = true - it.second.onFindCallback?.invoke(memberInstances.fields()) + plan.second.onFindCallback?.invoke(memberInstances.fields()) remedyPlansCallback?.invoke() memberInstances.takeIf { it.isNotEmpty() } - ?.forEach { onDebuggingMsg(msg = "Field [$it] trying ${p + 1} times success by RemedyPlan") } - return@run - }.onFailure { - lastError = it - onFailureMsg(msg = "Trying ${p + 1} times by RemedyPlan --> $it", isAlwaysPrint = true) - } - } - if (isFindSuccess.not()) { - onFailureMsg( - msg = "Trying ${remedyPlans.size} times and all failure by RemedyPlan", - throwable = lastError, - isAlwaysPrint = true - ) - remedyPlans.clear() + ?.forEach { debugMsg(msg = "RemedyPlan successed after ${index + 1} attempts of Field [$it]") } + return + }.onFailure { errors.add(it) } } + if (isFindSuccess) return + errorMsg(msg = "RemedyPlan failed after ${remedyPlans.size} attempts", es = errors, isAlwaysMode = true) + remedyPlans.clear() } else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}") } @@ -464,7 +455,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val * @return [Result] 可继续向下监听 */ fun ignored(): Result { - isShutErrorPrinting = true + isIgnoreErrorLogs = true return this } diff --git a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt index 9702b282..d3680ad6 100644 --- a/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt +++ b/yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/core/finder/members/MethodFinder.kt @@ -358,7 +358,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val runBlocking { setInstance(result) }.result { ms -> - memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Method [$it] takes ${ms}ms") } + memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Method [$it] takes ${ms}ms") } } } @@ -367,7 +367,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val internalBuild() Result() }.getOrElse { - onFailureMsg(throwable = it) + errorMsg(e = it) Result(isNoSuch = true, it) } @@ -377,7 +377,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val internalBuild() Process() }.getOrElse { - onFailureMsg(throwable = it) + errorMsg(e = it) Process(isNoSuch = true, it) } @@ -417,35 +417,27 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val @PublishedApi internal fun build() { if (classSet == null) return - if (remedyPlans.isNotEmpty()) run { + if (remedyPlans.isNotEmpty()) { + val errors = mutableListOf() var isFindSuccess = false - var lastError: Throwable? = null - remedyPlans.forEachIndexed { p, it -> + remedyPlans.forEachIndexed { index, plan -> runCatching { runBlocking { - setInstance(it.first.result) + setInstance(plan.first.result) }.result { ms -> - memberInstances.takeIf { it.isNotEmpty() }?.forEach { onDebuggingMsg(msg = "Find Method [$it] takes ${ms}ms") } + memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Method [$it] takes ${ms}ms") } } isFindSuccess = true - it.second.onFindCallback?.invoke(memberInstances.methods()) + plan.second.onFindCallback?.invoke(memberInstances.methods()) remedyPlansCallback?.invoke() memberInstances.takeIf { it.isNotEmpty() } - ?.forEach { onDebuggingMsg(msg = "Method [$it] trying ${p + 1} times success by RemedyPlan") } - return@run - }.onFailure { - lastError = it - onFailureMsg(msg = "Trying ${p + 1} times by RemedyPlan --> $it", isAlwaysPrint = true) - } - } - if (isFindSuccess.not()) { - onFailureMsg( - msg = "Trying ${remedyPlans.size} times and all failure by RemedyPlan", - throwable = lastError, - isAlwaysPrint = true - ) - remedyPlans.clear() + ?.forEach { debugMsg(msg = "RemedyPlan successed after ${index + 1} attempts of Method [$it]") } + return + }.onFailure { errors.add(it) } } + if (isFindSuccess) return + errorMsg(msg = "RemedyPlan failed after ${remedyPlans.size} attempts", es = errors, isAlwaysMode = true) + remedyPlans.clear() } else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}") } @@ -662,7 +654,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val * @return [Result] 可继续向下监听 */ fun ignored(): Result { - isShutErrorPrinting = true + isIgnoreErrorLogs = true return this }