@@ -3,6 +3,7 @@ package com.gh0u1l5.wechatmagician.spellbook.util
3
3
import com.gh0u1l5.wechatmagician.spellbook.WechatGlobal
4
4
import com.gh0u1l5.wechatmagician.spellbook.base.Classes
5
5
import com.gh0u1l5.wechatmagician.spellbook.parser.ApkFile
6
+ import com.gh0u1l5.wechatmagician.spellbook.parser.ClassTrie
6
7
import de.robv.android.xposed.XC_MethodHook
7
8
import de.robv.android.xposed.XposedBridge.hookMethod
8
9
import java.lang.reflect.Field
@@ -66,40 +67,21 @@ object ReflectionUtil {
66
67
* 里面其他包拥有的类.
67
68
*
68
69
* @param loader 用于取出 [Class] 对象的加载器
69
- * @param classes 所有已知的类名 , 由于 Java 的 [ClassLoader] 对象不支持读取所有类名, 我们必须先通过其他手段
70
- * 获取一个类名列表 , 详情请参见 [ApkFile] 和 [WechatGlobal]
70
+ * @param trie 整个 APK 的包结构 , 由于 Java 的 [ClassLoader] 对象不支持读取所有类名, 我们必须先通过其他手段
71
+ * 解析 APK 结构, 然后才能检索某个包内的所有类 , 详情请参见 [ApkFile] 和 [WechatGlobal]
71
72
* @param packageName 包名
72
73
* @param depth 深度
73
74
*/
74
- @JvmStatic fun findClassesFromPackage (loader : ClassLoader , classes : Array < String > , packageName : String , depth : Int = 0): Classes {
75
+ @JvmStatic fun findClassesFromPackage (loader : ClassLoader , trie : ClassTrie , packageName : String , depth : Int = 0): Classes {
75
76
val key = " $depth -$packageName "
76
77
val cached = classCache[key]
77
78
if (cached != null ) {
78
79
return cached
79
80
}
80
-
81
- val packageLength = packageName.count { it == ' .' } + 1
82
- val packageDescriptor = " L${packageName.replace(' .' , ' /' )} "
83
- val result = Classes (classes.filter { clazz ->
84
- val currentPackageLength = clazz.count { it == ' /' }
85
- if (currentPackageLength < packageLength) {
86
- return @filter false
87
- }
88
- // Check depth
89
- val currentDepth = currentPackageLength - packageLength
90
- if (depth != - 1 && depth != currentDepth) {
91
- return @filter false
92
- }
93
- // Check prefix
94
- if (! clazz.startsWith(packageDescriptor)) {
95
- return @filter false
96
- }
97
- return @filter true
98
- }.mapNotNull {
99
- findClassIfExists(it.substring(1 , it.length - 1 ).replace(' /' , ' .' ), loader)
81
+ val classes = Classes (trie.search(packageName, depth).mapNotNull { name ->
82
+ findClassIfExists(name, loader)
100
83
})
101
-
102
- return result.also { classCache[key] = result }
84
+ return classes.also { classCache[key] = classes }
103
85
}
104
86
105
87
/* *
0 commit comments