From 03148eb9d65bc0998658b2d14b2d7be9989511ca Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Fri, 30 Sep 2022 03:09:11 +0800 Subject: [PATCH] Added ClassLoader.listOfClasses function in ReflectionFactory --- .../hook/factory/ReflectionFactory.md | 22 +++++++++++++++++++ .../hook/factory/ReflectionFactory.md | 22 +++++++++++++++++++ .../hook/core/finder/tools/ReflectionTool.kt | 2 +- .../hook/factory/ReflectionFactory.kt | 12 ++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md index 8eab2d8c..f8e23cdf 100644 --- a/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md +++ b/docs-source/src/en/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md @@ -76,6 +76,28 @@ CONSTRUCTOR > 全部 `Constructor`。 +## ClassLoader.listOfClasses - ext-method + +```kotlin:no-line-numbers +fun ClassLoader.listOfClasses(): List +``` + +**Change Records** + +`v1.1.2` `added` + +**Function Illustrate** + +> 写出当前 `ClassLoader` 下所有 `Class` 名称数组。 + +::: warning + +此方法在 **Class** 数量过多时会非常耗时。 + +若要按指定规则查找一个 **Class**,请使用 [ClassLoader.searchClass](#classloader-searchclass-ext-method) 方法。 + +::: + ## ClassLoader.searchClass - ext-method ```kotlin:no-line-numbers diff --git a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md index 34bc6db3..834965b2 100644 --- a/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md +++ b/docs-source/src/zh-cn/api/public/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.md @@ -68,6 +68,28 @@ CONSTRUCTOR > 全部 `Constructor`。 +## ClassLoader.listOfClasses - ext-method + +```kotlin:no-line-numbers +fun ClassLoader.listOfClasses(): List +``` + +**变更记录** + +`v1.1.2` `新增` + +**功能描述** + +> 写出当前 `ClassLoader` 下所有 `Class` 名称数组。 + +::: warning + +此方法在 **Class** 数量过多时会非常耗时。 + +若要按指定规则查找一个 **Class**,请使用 [ClassLoader.searchClass](#classloader-searchclass-ext-method) 方法。 + +::: + ## ClassLoader.searchClass - ext-method ```kotlin:no-line-numbers diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt index 941d087d..79115c6e 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/tools/ReflectionTool.kt @@ -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 diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt index 8170d85d..2b99d70d 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/factory/ReflectionFactory.kt @@ -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] *