mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 02:35:40 +08:00
Fix a potentially hidden bug that would cause a problem in one place to interrupt the entire process
This commit is contained in:
@@ -135,6 +135,9 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
|
|||||||
/** 全部错误回调 */
|
/** 全部错误回调 */
|
||||||
private var onAllFailureCallback: ((Throwable) -> Unit)? = null
|
private var onAllFailureCallback: ((Throwable) -> Unit)? = null
|
||||||
|
|
||||||
|
/** 查找过程中发生的异常 */
|
||||||
|
private var findingThrowable: Throwable? = null
|
||||||
|
|
||||||
/** 是否为替换 Hook 模式 */
|
/** 是否为替换 Hook 模式 */
|
||||||
private var isReplaceHookMode = false
|
private var isReplaceHookMode = false
|
||||||
|
|
||||||
@@ -188,11 +191,13 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
|
|||||||
* @param initiate 方法体
|
* @param initiate 方法体
|
||||||
* @return [MethodFinder.Result]
|
* @return [MethodFinder.Result]
|
||||||
*/
|
*/
|
||||||
fun method(initiate: MethodFinder.() -> Unit): MethodFinder.Result {
|
fun method(initiate: MethodFinder.() -> Unit) = try {
|
||||||
if (hookClass.instance == null) return MethodFinder(hookInstance = this).failure(hookClass.throwable)
|
|
||||||
hookAllMembers = HookAllMembers.HOOK_NONE
|
hookAllMembers = HookAllMembers.HOOK_NONE
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
return MethodFinder(hookInstance = this, hookClass.instance).apply(initiate).build(isBind = true)
|
MethodFinder(hookInstance = this, hookClass.instance).apply(initiate).build(isBind = true)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
findingThrowable = e
|
||||||
|
MethodFinder(hookInstance = this).failure(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,11 +207,13 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
|
|||||||
* @param initiate 方法体
|
* @param initiate 方法体
|
||||||
* @return [ConstructorFinder.Result]
|
* @return [ConstructorFinder.Result]
|
||||||
*/
|
*/
|
||||||
fun constructor(initiate: ConstructorFinder.() -> Unit = {}): ConstructorFinder.Result {
|
fun constructor(initiate: ConstructorFinder.() -> Unit = {}) = try {
|
||||||
if (hookClass.instance == null) return ConstructorFinder(hookInstance = this).failure(hookClass.throwable)
|
|
||||||
hookAllMembers = HookAllMembers.HOOK_NONE
|
hookAllMembers = HookAllMembers.HOOK_NONE
|
||||||
isHookMemberSetup = true
|
isHookMemberSetup = true
|
||||||
return ConstructorFinder(hookInstance = this, hookClass.instance).apply(initiate).build(isBind = true)
|
ConstructorFinder(hookInstance = this, hookClass.instance).apply(initiate).build(isBind = true)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
findingThrowable = e
|
||||||
|
ConstructorFinder(hookInstance = this).failure(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -416,16 +423,15 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
|
|||||||
if (isNotIgnoredHookingFailure) onHookFailureMsg(it)
|
if (isNotIgnoredHookingFailure) onHookFailureMsg(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else Throwable("Finding Error isSetUpMember [$isHookMemberSetup] [$tag]").also {
|
||||||
Throwable(message = "Finding Error isSetUpMember [$isHookMemberSetup] [$tag]").also {
|
onHookingFailureCallback?.invoke(it)
|
||||||
onHookingFailureCallback?.invoke(it)
|
onAllFailureCallback?.invoke(it)
|
||||||
onAllFailureCallback?.invoke(it)
|
|
||||||
}
|
|
||||||
if (isNotIgnoredHookingFailure)
|
if (isNotIgnoredHookingFailure)
|
||||||
loggerE(
|
loggerE(
|
||||||
msg = if (isHookMemberSetup)
|
msg = if (isHookMemberSetup)
|
||||||
"Hooked Member with a finding error in Class [$hookClass] [$tag]"
|
"Hooked Member with a finding error by $hookClass [$tag]"
|
||||||
else "Hooked Member cannot be non-null in Class [$hookClass] [$tag]"
|
else "Hooked Member cannot be non-null by $hookClass [$tag]",
|
||||||
|
e = findingThrowable ?: it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else runCatching {
|
else runCatching {
|
||||||
|
Reference in New Issue
Block a user