From cb74c7ed113b9e9dff793e8fb5efb90df8b7149a Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Fri, 1 Apr 2022 23:24:21 +0800 Subject: [PATCH] Fix Hooking failed no printing throwable bug --- .../yukihookapi/demo_module/hook/HookEntry.kt | 2 +- .../yukihookapi/hook/core/YukiHookCreater.kt | 5 +- .../hook/core/finder/FieldFinder.kt | 68 +++++++++++-------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt b/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt index d199db15..51eafef8 100644 --- a/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt +++ b/demo-module/src/main/java/com/highcapable/yukihookapi/demo_module/hook/HookEntry.kt @@ -162,7 +162,7 @@ class HookEntry : YukiHookXposedInitProxy { } // 注入要 Hook 的方法 injectMember { - allMethods(name = "getTestResultLast") + allMethods(name = "getTestResultLast111111111111111111111111111111") // 执行替换 Hook replaceTo("I am hook all methods last") } diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt index c5c19347..25f29bef 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiHookCreater.kt @@ -473,11 +473,12 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl else -> error("Hooked got a no error possible") } }.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) onAllFailureCallback?.invoke(it) 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) } } 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 400054ed..6a7a9bc1 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 @@ -53,20 +53,14 @@ class FieldFinder( /** [ModifierRules] 实例 */ private var modifiers: ModifierRules? = null - /** - * [Field] 在当前类中的位置 - * - * - 设置后将筛选 [Class.getDeclaredFields] 的数组下标 - * - * - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标 - * - * - ❗受到字节码顺序影响 - 请勿完全依赖于此功能 - * - * 若 index 小于零则忽略此条件 (等于 -2 为取最后一个) - * - * 可使用 [firstIndex] 和 [lastIndex] 设置首位和末位筛选条件 - */ - var index = -1 + private object IndexConfig { + + var orderIndex = -1 + + var nameIndex = -1 + + var typeIndex = -1 + } /** * [Field] 名称 @@ -82,23 +76,12 @@ class FieldFinder( */ var type: Class<*>? = null - /** - * 设置 [Field] 在当前类中的位置为首位 - * - * - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标 - */ - fun firstIndex() { - index = 0 - } + /** 筛选字节码的顺序下标 */ + fun order() = IndexTypeCondition() - /** - * 设置 [Field] 在当前类中的位置为末位 - * - * - ❗若你同时设置了 [type] 将仅过滤类型为 [type] 的数组下标 - */ - fun lastIndex() { - index = -2 - } + fun name(value: String) = IndexTypeCondition() + + fun type(value: Class<*>) = IndexTypeCondition() /** * [Field] 筛选条件 @@ -122,6 +105,7 @@ class FieldFinder( override fun build(isBind: Boolean) = try { if (classSet != null) { runBlocking { + val index=-1 memberInstance = ReflectionTool.findField(classSet, index, name, modifiers, type) }.result { onHookLogMsg(msg = "Find Field [${memberInstance}] takes ${it}ms [${hookTag}]") } Result() @@ -145,6 +129,30 @@ class FieldFinder( @DoNotUseMethod override fun failure(throwable: Throwable?) = Result(isNoSuch = true, throwable) + /** + * 字节码下标筛选实现类 + */ + inner class IndexTypeCondition { + + /** + * 设置下标 + * @param num 下标 + */ + fun index(num: Int) { + + } + + /** 设置满足条件的第一个*/ + fun firstIndex() { + + } + + /** 设置满足条件的最后一个*/ + fun lastIndex() { + + } + } + /** * [Field] 查找结果实现类 *