mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 10:45:47 +08:00
refactor: optimize core finder code
- fix remedy plan not show any errors problem - rearrange some code
This commit is contained in:
@@ -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.YukiMemberHook
|
||||||
import com.highcapable.yukihookapi.hook.core.api.proxy.YukiMemberReplacement
|
import com.highcapable.yukihookapi.hook.core.api.proxy.YukiMemberReplacement
|
||||||
import com.highcapable.yukihookapi.hook.core.api.result.YukiHookResult
|
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.ConstructorFinder
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder
|
import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder
|
||||||
import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder
|
import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder
|
||||||
@@ -304,10 +303,6 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal var isHookMemberSetup = false
|
internal var isHookMemberSetup = false
|
||||||
|
|
||||||
/** 当前的查找实例 */
|
|
||||||
@PublishedApi
|
|
||||||
internal var finder: MemberBaseFinder? = null
|
|
||||||
|
|
||||||
/** 当前被 Hook 的 [Method]、[Constructor] 实例数组 */
|
/** 当前被 Hook 的 [Method]、[Constructor] 实例数组 */
|
||||||
private val hookedMembers = HashSet<YukiMemberHook.HookedMember>()
|
private val hookedMembers = HashSet<YukiMemberHook.HookedMember>()
|
||||||
|
|
||||||
@@ -385,7 +380,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
*/
|
*/
|
||||||
inline fun method(initiate: MethodConditions) = runCatching {
|
inline fun method(initiate: MethodConditions) = runCatching {
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
MethodFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process()
|
MethodFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
findingThrowable = it
|
findingThrowable = it
|
||||||
MethodFinder.fromHooker(hookInstance = this).denied(it)
|
MethodFinder.fromHooker(hookInstance = this).denied(it)
|
||||||
@@ -400,7 +395,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
*/
|
*/
|
||||||
inline fun constructor(initiate: ConstructorConditions = { emptyParam() }) = runCatching {
|
inline fun constructor(initiate: ConstructorConditions = { emptyParam() }) = runCatching {
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
ConstructorFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).apply { finder = this }.process()
|
ConstructorFinder.fromHooker(hookInstance = this, hookClass.instance).apply(initiate).process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
findingThrowable = it
|
findingThrowable = it
|
||||||
ConstructorFinder.fromHooker(hookInstance = this).denied(it)
|
ConstructorFinder.fromHooker(hookInstance = this).denied(it)
|
||||||
@@ -563,12 +558,11 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
internal fun hook() {
|
internal fun hook() {
|
||||||
if (HookApiCategoryHelper.hasAvailableHookApi.not() || isHooked || isDisableMemberRunHook) return
|
if (HookApiCategoryHelper.hasAvailableHookApi.not() || isHooked || isDisableMemberRunHook) return
|
||||||
isHooked = true
|
isHooked = true
|
||||||
finder?.printLogIfExist()
|
|
||||||
if (hookClass.instance == null) {
|
if (hookClass.instance == null) {
|
||||||
(hookClass.throwable ?: Throwable("HookClass [${hookClass.name}] not found")).also {
|
(hookClass.throwable ?: Throwable("HookClass [${hookClass.name}] not found")).also {
|
||||||
onHookingFailureCallback?.invoke(it)
|
onHookingFailureCallback?.invoke(it)
|
||||||
onAllFailureCallback?.invoke(it)
|
onAllFailureCallback?.invoke(it)
|
||||||
if (isNotIgnoredHookingFailure) onHookFailureMsg(it)
|
if (isNotIgnoredHookingFailure) hookErrorMsg(it)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -587,7 +581,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
}.onFailure {
|
}.onFailure {
|
||||||
onHookingFailureCallback?.invoke(it)
|
onHookingFailureCallback?.invoke(it)
|
||||||
onAllFailureCallback?.invoke(it)
|
onAllFailureCallback?.invoke(it)
|
||||||
if (isNotIgnoredHookingFailure) onHookFailureMsg(it, member)
|
if (isNotIgnoredHookingFailure) hookErrorMsg(it, member)
|
||||||
}
|
}
|
||||||
} ?: Throwable("Finding Error isSetUpMember [$isHookMemberSetup] [$tag]").also {
|
} ?: Throwable("Finding Error isSetUpMember [$isHookMemberSetup] [$tag]").also {
|
||||||
onNoSuchMemberFailureCallback?.invoke(it)
|
onNoSuchMemberFailureCallback?.invoke(it)
|
||||||
@@ -617,13 +611,13 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
runCatching {
|
runCatching {
|
||||||
replaceHookCallback?.invoke(assign).also {
|
replaceHookCallback?.invoke(assign).also {
|
||||||
checkingReturnType((param.member as? Method?)?.returnType, it?.javaClass)
|
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()
|
HookParam.invoke()
|
||||||
}
|
}
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onConductFailureCallback?.invoke(assign, it)
|
onConductFailureCallback?.invoke(assign, it)
|
||||||
onAllFailureCallback?.invoke(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 正常运行 */
|
/** 若发生异常则会自动调用未经 Hook 的原始 [Member] 保证 Hook APP 正常运行 */
|
||||||
assign.callOriginal()
|
assign.callOriginal()
|
||||||
}
|
}
|
||||||
@@ -643,12 +637,12 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
runCatching {
|
runCatching {
|
||||||
beforeHookCallback?.invoke(assign)
|
beforeHookCallback?.invoke(assign)
|
||||||
checkingReturnType((param.member as? Method?)?.returnType, param.result?.javaClass)
|
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()
|
HookParam.invoke()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
onConductFailureCallback?.invoke(assign, it)
|
onConductFailureCallback?.invoke(assign, it)
|
||||||
onAllFailureCallback?.invoke(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
|
if (isOnFailureThrowToApp) param.throwable = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -658,12 +652,12 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
afterHookParam.assign(afterHookId, param).also { assign ->
|
afterHookParam.assign(afterHookId, param).also { assign ->
|
||||||
runCatching {
|
runCatching {
|
||||||
afterHookCallback?.invoke(assign)
|
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()
|
HookParam.invoke()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
onConductFailureCallback?.invoke(assign, it)
|
onConductFailureCallback?.invoke(assign, it)
|
||||||
onAllFailureCallback?.invoke(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
|
if (isOnFailureThrowToApp) param.throwable = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -692,19 +686,17 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
* Hook 过程中开启了 [YukiHookAPI.Configs.isDebug] 输出调试信息
|
* Hook 过程中开启了 [YukiHookAPI.Configs.isDebug] 输出调试信息
|
||||||
* @param msg 调试日志内容
|
* @param msg 调试日志内容
|
||||||
*/
|
*/
|
||||||
private fun onHookLogMsg(msg: String) {
|
private fun hookDebugMsg(msg: String) {
|
||||||
if (YukiHookAPI.Configs.isDebug) yLoggerD(msg = msg)
|
if (YukiHookAPI.Configs.isDebug) yLoggerD(msg = msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook 失败但未设置 [onAllFailureCallback] 将默认输出失败信息
|
* Hook 失败但未设置 [onAllFailureCallback] 将默认输出失败信息
|
||||||
* @param throwable 异常信息
|
* @param e 异常堆栈
|
||||||
* @param member 异常 [Member] - 可空
|
* @param member 异常 [Member] - 可空
|
||||||
*/
|
*/
|
||||||
private fun onHookFailureMsg(throwable: Throwable, member: Member? = null) = yLoggerE(
|
private fun hookErrorMsg(e: Throwable, member: Member? = null) =
|
||||||
msg = "Try to hook [${hookClass.instance ?: hookClass.name}]${member?.let { "[$it]" } ?: ""} got an Exception [$tag]",
|
yLoggerE(msg = "Try to hook [${hookClass.instance ?: hookClass.name}]${member?.let { "[$it]" } ?: ""} got an Exception [$tag]", e = e)
|
||||||
e = throwable
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否没有设置 Hook 过程中的任何异常拦截
|
* 判断是否没有设置 Hook 过程中的任何异常拦截
|
||||||
@@ -858,7 +850,7 @@ class YukiMemberHookCreator @PublishedApi internal constructor(
|
|||||||
hookedMembers.takeIf { it.isNotEmpty() }?.apply {
|
hookedMembers.takeIf { it.isNotEmpty() }?.apply {
|
||||||
forEach {
|
forEach {
|
||||||
it.remove()
|
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()) }
|
runCatching { preHookMembers.remove(this@MemberHookCreator.toString()) }
|
||||||
clear()
|
clear()
|
||||||
|
@@ -49,7 +49,7 @@ abstract class ClassBaseFinder internal constructor(internal open val loaderSet:
|
|||||||
internal var classInstances = HashSet<Class<*>>()
|
internal var classInstances = HashSet<Class<*>>()
|
||||||
|
|
||||||
/** 是否开启忽略错误警告功能 */
|
/** 是否开启忽略错误警告功能 */
|
||||||
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] 情况下输出调试信息
|
* 在开启 [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)
|
if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi) yLoggerD(msg = msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发生错误时输出日志
|
* 发生错误时输出日志
|
||||||
* @param throwable 错误
|
* @param e 异常堆栈 - 默认空
|
||||||
*/
|
*/
|
||||||
internal fun onFailureMsg(throwable: Throwable? = null) {
|
internal fun errorMsg(e: Throwable? = null) {
|
||||||
if (isShutErrorPrinting) return
|
if (isIgnoreErrorLogs) return
|
||||||
/** 判断是否为 [LOADERSET_IS_NULL] */
|
/** 判断是否为 [LOADERSET_IS_NULL] */
|
||||||
if (throwable?.message == LOADERSET_IS_NULL) return
|
if (e?.message == LOADERSET_IS_NULL) return
|
||||||
yLoggerE(msg = "NoClassDefFound happend in [$loaderSet]", e = throwable)
|
yLoggerE(msg = "NoClassDefFound happend in [$loaderSet]", e = e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@YukiPrivateApi
|
@YukiPrivateApi
|
||||||
|
@@ -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.yLoggerD
|
||||||
import com.highcapable.yukihookapi.hook.log.yLoggerE
|
import com.highcapable.yukihookapi.hook.log.yLoggerE
|
||||||
import com.highcapable.yukihookapi.hook.utils.factory.await
|
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.Constructor
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
import java.lang.reflect.Member
|
import java.lang.reflect.Member
|
||||||
@@ -65,14 +64,11 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
internal var isUsingRemedyPlan = false
|
internal var isUsingRemedyPlan = false
|
||||||
|
|
||||||
/** 是否开启忽略错误警告功能 */
|
/** 是否开启忽略错误警告功能 */
|
||||||
internal var isShutErrorPrinting = false
|
internal var isIgnoreErrorLogs = false
|
||||||
|
|
||||||
/** 当前找到的 [Member] 数组 */
|
/** 当前找到的 [Member] 数组 */
|
||||||
internal var memberInstances = HashSet<Member>()
|
internal var memberInstances = HashSet<Member>()
|
||||||
|
|
||||||
/** 需要输出的日志内容 */
|
|
||||||
private var loggingContent: Pair<String, Throwable?>? = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 [HashSet]<[Member]> 转换为 [HashSet]<[Field]>
|
* 将 [HashSet]<[Member]> 转换为 [HashSet]<[Field]>
|
||||||
* @return [HashSet]<[Field]>
|
* @return [HashSet]<[Field]>
|
||||||
@@ -101,43 +97,30 @@ abstract class MemberBaseFinder internal constructor(
|
|||||||
internal fun Any?.compat() = compat(tag, classSet?.classLoader)
|
internal fun Any?.compat() = compat(tag, classSet?.classLoader)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发生错误时输出日志
|
* 在开启 [YukiHookAPI.Configs.isDebug] 且在 [HookApiCategoryHelper.hasAvailableHookApi] 且在 Hook 过程中情况下输出调试信息
|
||||||
* @param msg 消息日志
|
* @param msg 消息内容
|
||||||
* @param throwable 错误
|
|
||||||
* @param isAlwaysPrint 忽略条件每次都打印错误
|
|
||||||
*/
|
*/
|
||||||
internal fun onFailureMsg(msg: String = "", throwable: Throwable? = null, isAlwaysPrint: Boolean = false) {
|
internal fun debugMsg(msg: String) {
|
||||||
/** 创建日志 */
|
if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi && hookerManager.instance != null)
|
||||||
fun build() {
|
yLoggerD(msg = "$msg${hookerManager.tailTag}")
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在开启 [YukiHookAPI.Configs.isDebug] 且在 [HookApiCategoryHelper.hasAvailableHookApi] 且在 Hook 过程中情况下输出调试信息
|
* 发生错误时输出日志
|
||||||
* @param msg 调试日志内容
|
* @param msg 消息内容
|
||||||
|
* @param e 异常堆栈 - 默认空
|
||||||
|
* @param e 异常堆栈数组 - 默认空
|
||||||
|
* @param isAlwaysMode 忽略条件每次都输出日志
|
||||||
*/
|
*/
|
||||||
internal fun onDebuggingMsg(msg: String) {
|
internal fun errorMsg(msg: String = "", e: Throwable? = null, es: List<Throwable> = emptyList(), isAlwaysMode: Boolean = false) {
|
||||||
if (YukiHookAPI.Configs.isDebug && HookApiCategoryHelper.hasAvailableHookApi && hookerManager.instance != null)
|
/** 判断是否为 [CLASSSET_IS_NULL] */
|
||||||
yLoggerD(msg = "$msg${hookerManager.tailTag}")
|
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) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -484,7 +484,7 @@ class DexClassFinder @PublishedApi internal constructor(
|
|||||||
fun startProcess() {
|
fun startProcess() {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(readFromCache().takeIf { it.isNotEmpty() } ?: result)
|
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 ->
|
Result().also { e ->
|
||||||
if (async) e.await {
|
if (async) e.await {
|
||||||
@@ -497,12 +497,12 @@ class DexClassFinder @PublishedApi internal constructor(
|
|||||||
it.isNotFound = true
|
it.isNotFound = true
|
||||||
it.throwable = e
|
it.throwable = e
|
||||||
it.noClassDefFoundErrorCallback?.invoke()
|
it.noClassDefFoundErrorCallback?.invoke()
|
||||||
onFailureMsg(throwable = e)
|
errorMsg(e = e)
|
||||||
}
|
}
|
||||||
} else startProcess()
|
} else startProcess()
|
||||||
}
|
}
|
||||||
} else Result(isNotFound = true, Throwable(LOADERSET_IS_NULL)).await { onFailureMsg() }
|
} else Result(isNotFound = true, Throwable(LOADERSET_IS_NULL)).await { errorMsg() }
|
||||||
}.getOrElse { e -> Result(isNotFound = true, e).await { onFailureMsg(throwable = e) } }
|
}.getOrElse { e -> Result(isNotFound = true, e).await { errorMsg(e = e) } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [Class] 查找结果实现类
|
* [Class] 查找结果实现类
|
||||||
@@ -620,7 +620,7 @@ class DexClassFinder @PublishedApi internal constructor(
|
|||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
*/
|
*/
|
||||||
fun ignored(): Result {
|
fun ignored(): Result {
|
||||||
isShutErrorPrinting = true
|
isIgnoreErrorLogs = true
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -265,7 +265,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
|
|||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(result)
|
setInstance(result)
|
||||||
}.result { ms ->
|
}.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()
|
internalBuild()
|
||||||
Result()
|
Result()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
errorMsg(e = it)
|
||||||
Result(isNoSuch = true, it)
|
Result(isNoSuch = true, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
|
|||||||
internalBuild()
|
internalBuild()
|
||||||
Process()
|
Process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
errorMsg(e = it)
|
||||||
Process(isNoSuch = true, it)
|
Process(isNoSuch = true, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,35 +323,27 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun build() {
|
internal fun build() {
|
||||||
if (classSet == null) return
|
if (classSet == null) return
|
||||||
if (remedyPlans.isNotEmpty()) run {
|
if (remedyPlans.isNotEmpty()) {
|
||||||
|
val errors = mutableListOf<Throwable>()
|
||||||
var isFindSuccess = false
|
var isFindSuccess = false
|
||||||
var lastError: Throwable? = null
|
remedyPlans.forEachIndexed { index, plan ->
|
||||||
remedyPlans.forEachIndexed { p, it ->
|
|
||||||
runCatching {
|
runCatching {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(it.first.result)
|
setInstance(plan.first.result)
|
||||||
}.result { ms ->
|
}.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
|
isFindSuccess = true
|
||||||
it.second.onFindCallback?.invoke(memberInstances.constructors())
|
plan.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") }
|
?.forEach { debugMsg(msg = "RemedyPlan successed after ${index + 1} attempts of Constructor [$it]") }
|
||||||
return@run
|
return
|
||||||
}.onFailure {
|
}.onFailure { errors.add(it) }
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
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}")
|
} else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,7 +553,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
|
|||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
*/
|
*/
|
||||||
fun ignored(): Result {
|
fun ignored(): Result {
|
||||||
isShutErrorPrinting = true
|
isIgnoreErrorLogs = true
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -220,7 +220,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(result)
|
setInstance(result)
|
||||||
}.result { ms ->
|
}.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()
|
internalBuild()
|
||||||
Result()
|
Result()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
errorMsg(e = it)
|
||||||
Result(isNoSuch = true, it)
|
Result(isNoSuch = true, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,45 +263,36 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
* @return [Result] 结果
|
* @return [Result] 结果
|
||||||
*/
|
*/
|
||||||
inline fun field(initiate: FieldConditions) = Result().apply {
|
inline fun field(initiate: FieldConditions) = Result().apply {
|
||||||
remedyPlans.add(Pair(FieldFinder(classSet).apply {
|
remedyPlans.add(FieldFinder(classSet).apply {
|
||||||
hookerManager = this@FieldFinder.hookerManager
|
hookerManager = this@FieldFinder.hookerManager
|
||||||
}.apply(initiate), this))
|
}.apply(initiate) to this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 开始重查找 */
|
/** 开始重查找 */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun build() {
|
internal fun build() {
|
||||||
if (classSet == null) return
|
if (classSet == null) return
|
||||||
if (remedyPlans.isNotEmpty()) run {
|
if (remedyPlans.isNotEmpty()) {
|
||||||
|
val errors = mutableListOf<Throwable>()
|
||||||
var isFindSuccess = false
|
var isFindSuccess = false
|
||||||
var lastError: Throwable? = null
|
remedyPlans.forEachIndexed { index, plan ->
|
||||||
remedyPlans.forEachIndexed { p, it ->
|
|
||||||
runCatching {
|
runCatching {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(it.first.result)
|
setInstance(plan.first.result)
|
||||||
}.result { ms ->
|
}.result { ms ->
|
||||||
memberInstances.takeIf { it.isNotEmpty() }
|
memberInstances.takeIf { it.isNotEmpty() }?.forEach { debugMsg(msg = "Find Field [$it] takes ${ms}ms") }
|
||||||
?.forEach { onDebuggingMsg(msg = "Find Field [$it] takes ${ms}ms") }
|
|
||||||
}
|
}
|
||||||
isFindSuccess = true
|
isFindSuccess = true
|
||||||
it.second.onFindCallback?.invoke(memberInstances.fields())
|
plan.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") }
|
?.forEach { debugMsg(msg = "RemedyPlan successed after ${index + 1} attempts of Field [$it]") }
|
||||||
return@run
|
return
|
||||||
}.onFailure {
|
}.onFailure { errors.add(it) }
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
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}")
|
} else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,7 +455,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
*/
|
*/
|
||||||
fun ignored(): Result {
|
fun ignored(): Result {
|
||||||
isShutErrorPrinting = true
|
isIgnoreErrorLogs = true
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -358,7 +358,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(result)
|
setInstance(result)
|
||||||
}.result { ms ->
|
}.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()
|
internalBuild()
|
||||||
Result()
|
Result()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
errorMsg(e = it)
|
||||||
Result(isNoSuch = true, it)
|
Result(isNoSuch = true, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
internalBuild()
|
internalBuild()
|
||||||
Process()
|
Process()
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
onFailureMsg(throwable = it)
|
errorMsg(e = it)
|
||||||
Process(isNoSuch = true, it)
|
Process(isNoSuch = true, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,35 +417,27 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun build() {
|
internal fun build() {
|
||||||
if (classSet == null) return
|
if (classSet == null) return
|
||||||
if (remedyPlans.isNotEmpty()) run {
|
if (remedyPlans.isNotEmpty()) {
|
||||||
|
val errors = mutableListOf<Throwable>()
|
||||||
var isFindSuccess = false
|
var isFindSuccess = false
|
||||||
var lastError: Throwable? = null
|
remedyPlans.forEachIndexed { index, plan ->
|
||||||
remedyPlans.forEachIndexed { p, it ->
|
|
||||||
runCatching {
|
runCatching {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
setInstance(it.first.result)
|
setInstance(plan.first.result)
|
||||||
}.result { ms ->
|
}.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
|
isFindSuccess = true
|
||||||
it.second.onFindCallback?.invoke(memberInstances.methods())
|
plan.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") }
|
?.forEach { debugMsg(msg = "RemedyPlan successed after ${index + 1} attempts of Method [$it]") }
|
||||||
return@run
|
return
|
||||||
}.onFailure {
|
}.onFailure { errors.add(it) }
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
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}")
|
} else yLoggerW(msg = "RemedyPlan is empty, forgot it?${hookerManager.tailTag}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,7 +654,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
|
|||||||
* @return [Result] 可继续向下监听
|
* @return [Result] 可继续向下监听
|
||||||
*/
|
*/
|
||||||
fun ignored(): Result {
|
fun ignored(): Result {
|
||||||
isShutErrorPrinting = true
|
isIgnoreErrorLogs = true
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user