Added ClassLoader.listOfClasses function in ReflectionFactory

This commit is contained in:
2022-09-30 03:09:11 +08:00
parent c71cb04646
commit 03148eb9d6
4 changed files with 57 additions and 1 deletions

View File

@@ -74,7 +74,7 @@ internal object ReflectionTool {
* @return [List]<[String]>
* @throws IllegalStateException 如果 [loader] 不是 [BaseDexClassLoader]
*/
private fun findDexClassList(loader: ClassLoader?) = ReflectsCacheStore.findDexClassList(loader.hashCode())
internal fun findDexClassList(loader: ClassLoader?) = ReflectsCacheStore.findDexClassList(loader.hashCode())
?: DalvikBaseDexClassLoader.field { name = "pathList" }.ignored().get(loader.value().let {
while (it.value !is BaseDexClassLoader) {
if (it.value?.parent != null) it.value = it.value?.parent

View File

@@ -41,6 +41,7 @@ import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool
import com.highcapable.yukihookapi.hook.core.finder.type.factory.*
import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus
import com.highcapable.yukihookapi.hook.xposed.parasitic.AppParasitics
import dalvik.system.BaseDexClassLoader
import java.lang.reflect.*
/**
@@ -57,6 +58,17 @@ enum class MembersType {
CONSTRUCTOR
}
/**
* 写出当前 [ClassLoader] 下所有 [Class] 名称数组
*
* - ❗此方法在 [Class] 数量过多时会非常耗时
*
* - ❗若要按指定规则查找一个 [Class] - 请使用 [searchClass] 方法
* @return [List]<[String]>
* @throws IllegalStateException 如果当前 [ClassLoader] 不是 [BaseDexClassLoader]
*/
fun ClassLoader.listOfClasses() = ReflectionTool.findDexClassList(loader = this)
/**
* 通过当前 [ClassLoader] 按指定条件查找并得到 Dex 中的 [Class]
*