Fix Hooking failed no printing throwable bug

This commit is contained in:
2022-04-01 23:24:21 +08:00
parent c66705c77b
commit cb74c7ed11
3 changed files with 42 additions and 33 deletions

View File

@@ -162,7 +162,7 @@ class HookEntry : YukiHookXposedInitProxy {
} }
// 注入要 Hook 的方法 // 注入要 Hook 的方法
injectMember { injectMember {
allMethods(name = "getTestResultLast") allMethods(name = "getTestResultLast111111111111111111111111111111")
// 执行替换 Hook // 执行替换 Hook
replaceTo("I am hook all methods last") replaceTo("I am hook all methods last")
} }

View File

@@ -473,11 +473,12 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
else -> error("Hooked got a no error possible") else -> error("Hooked got a no error possible")
} }
}.onFailure { }.onFailure {
val isMemberNotFound = it.message?.lowercase()?.contains(other = "nosuch") == true val isMemberNotFound = it.message?.lowercase()?.contains(other = "nosuch") == true ||
it is NoSuchMethodError || it is NoSuchFieldError
if (isMemberNotFound) onNoSuchMemberFailureCallback?.invoke(it) if (isMemberNotFound) onNoSuchMemberFailureCallback?.invoke(it)
onAllFailureCallback?.invoke(it) onAllFailureCallback?.invoke(it)
if ((isNotIgnoredHookingFailure && isMemberNotFound.not()) || (isNotIgnoredNoSuchMemberFailure && isMemberNotFound)) if ((isNotIgnoredHookingFailure && isMemberNotFound.not()) || (isNotIgnoredNoSuchMemberFailure && isMemberNotFound))
yLoggerE(msg = "Hooked All Members with an error in Class [$hookClass] [$tag]") yLoggerE(msg = "Hooked All Members with an error in Class [$hookClass] [$tag]", e = it)
} }
} }

View File

@@ -53,20 +53,14 @@ class FieldFinder(
/** [ModifierRules] 实例 */ /** [ModifierRules] 实例 */
private var modifiers: ModifierRules? = null private var modifiers: ModifierRules? = null
/** private object IndexConfig {
* [Field] 在当前类中的位置
* var orderIndex = -1
* - 设置后将筛选 [Class.getDeclaredFields] 的数组下标
* var nameIndex = -1
* - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标
* var typeIndex = -1
* - ❗受到字节码顺序影响 - 请勿完全依赖于此功能 }
*
* 若 index 小于零则忽略此条件 (等于 -2 为取最后一个)
*
* 可使用 [firstIndex] 和 [lastIndex] 设置首位和末位筛选条件
*/
var index = -1
/** /**
* [Field] 名称 * [Field] 名称
@@ -82,23 +76,12 @@ class FieldFinder(
*/ */
var type: Class<*>? = null var type: Class<*>? = null
/** /** 筛选字节码的顺序下标 */
* 设置 [Field] 在当前类中的位置为首位 fun order() = IndexTypeCondition()
*
* - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标
*/
fun firstIndex() {
index = 0
}
/** fun name(value: String) = IndexTypeCondition()
* 设置 [Field] 在当前类中的位置为末位
* fun type(value: Class<*>) = IndexTypeCondition()
* - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标
*/
fun lastIndex() {
index = -2
}
/** /**
* [Field] 筛选条件 * [Field] 筛选条件
@@ -122,6 +105,7 @@ class FieldFinder(
override fun build(isBind: Boolean) = try { override fun build(isBind: Boolean) = try {
if (classSet != null) { if (classSet != null) {
runBlocking { runBlocking {
val index=-1
memberInstance = ReflectionTool.findField(classSet, index, name, modifiers, type) memberInstance = ReflectionTool.findField(classSet, index, name, modifiers, type)
}.result { onHookLogMsg(msg = "Find Field [${memberInstance}] takes ${it}ms [${hookTag}]") } }.result { onHookLogMsg(msg = "Find Field [${memberInstance}] takes ${it}ms [${hookTag}]") }
Result() Result()
@@ -145,6 +129,30 @@ class FieldFinder(
@DoNotUseMethod @DoNotUseMethod
override fun failure(throwable: Throwable?) = Result(isNoSuch = true, throwable) override fun failure(throwable: Throwable?) = Result(isNoSuch = true, throwable)
/**
* 字节码下标筛选实现类
*/
inner class IndexTypeCondition {
/**
* 设置下标
* @param num 下标
*/
fun index(num: Int) {
}
/** 设置满足条件的第一个*/
fun firstIndex() {
}
/** 设置满足条件的最后一个*/
fun lastIndex() {
}
}
/** /**
* [Field] 查找结果实现类 * [Field] 查找结果实现类
* *