From 5ba8cab9f94cee514a66873b6b17ed608897cd87 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Fri, 30 Dec 2022 21:27:01 +0800 Subject: [PATCH] Modify add "isAccessible" param in allMethods, allConstructors, allFields function in ReflectionFactory --- .../hook/factory/ReflectionFactory.md | 18 +++++++++++++++--- .../hook/factory/ReflectionFactory.md | 18 +++++++++++++++--- .../hook/factory/ReflectionFactory.kt | 15 +++++++++------ 3 files changed, 39 insertions(+), 12 deletions(-) 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 98070c15..1b1d9971 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 @@ -903,7 +903,7 @@ inline fun Class<*>.buildOf(vararg param: Any?, initiate: ConstructorConditi ## Class.allMethods - ext-method ```kotlin:no-line-numbers -inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) +inline fun Class<*>.allMethods(isAccessible: Boolean, result: (index: Int, method: Method) -> Unit) ``` **Change Records** @@ -914,6 +914,10 @@ inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) 将方法体进行 inline +`v1.1.5` `modified` + +新增 `isAccessible` 参数 + **Function Illustrate** > 遍历当前类中的所有方法。 @@ -921,7 +925,7 @@ inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) ## Class.allConstructors - ext-method ```kotlin:no-line-numbers -inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructor<*>) -> Unit) +inline fun Class<*>.allConstructors(isAccessible: Boolean, result: (index: Int, constructor: Constructor<*>) -> Unit) ``` **Change Records** @@ -932,6 +936,10 @@ inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructo 将方法体进行 inline +`v1.1.5` `modified` + +新增 `isAccessible` 参数 + **Function Illustrate** > 遍历当前类中的所有构造方法。 @@ -939,7 +947,7 @@ inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructo ## Class.allFields - ext-method ```kotlin:no-line-numbers -inline fun Class<*>.allFields(result: (index: Int, field: Field) -> Unit) +inline fun Class<*>.allFields(isAccessible: Boolean, result: (index: Int, field: Field) -> Unit) ``` **Change Records** @@ -950,6 +958,10 @@ inline fun Class<*>.allFields(result: (index: Int, field: Field) -> Unit) 将方法体进行 inline +`v1.1.5` `modified` + +新增 `isAccessible` 参数 + **Function Illustrate** > 遍历当前类中的所有变量。 \ No newline at end of file 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 ed1c239e..b07c6eba 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 @@ -895,7 +895,7 @@ inline fun Class<*>.buildOf(vararg param: Any?, initiate: ConstructorConditi ## Class.allMethods - ext-method ```kotlin:no-line-numbers -inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) +inline fun Class<*>.allMethods(isAccessible: Boolean, result: (index: Int, method: Method) -> Unit) ``` **变更记录** @@ -906,6 +906,10 @@ inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) 将方法体进行 inline +`v1.1.5` `修改` + +新增 `isAccessible` 参数 + **功能描述** > 遍历当前类中的所有方法。 @@ -913,7 +917,7 @@ inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) ## Class.allConstructors - ext-method ```kotlin:no-line-numbers -inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructor<*>) -> Unit) +inline fun Class<*>.allConstructors(isAccessible: Boolean, result: (index: Int, constructor: Constructor<*>) -> Unit) ``` **变更记录** @@ -924,6 +928,10 @@ inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructo 将方法体进行 inline +`v1.1.5` `修改` + +新增 `isAccessible` 参数 + **功能描述** > 遍历当前类中的所有构造方法。 @@ -931,7 +939,7 @@ inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructo ## Class.allFields - ext-method ```kotlin:no-line-numbers -inline fun Class<*>.allFields(result: (index: Int, field: Field) -> Unit) +inline fun Class<*>.allFields(isAccessible: Boolean, result: (index: Int, field: Field) -> Unit) ``` **变更记录** @@ -942,6 +950,10 @@ inline fun Class<*>.allFields(result: (index: Int, field: Field) -> Unit) 将方法体进行 inline +`v1.1.5` `修改` + +新增 `isAccessible` 参数 + **功能描述** > 遍历当前类中的所有变量。 \ No newline at end of file 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 6db11196..6576367d 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 @@ -386,24 +386,27 @@ inline fun Class<*>.buildOf(vararg param: Any?, initiate: ConstructorConditi /** * 遍历当前类中的所有方法 + * @param isAccessible 是否强制设置成员为可访问类型 - 默认是 * @param result 回调 - ([Int] 下标,[Method] 实例) */ -inline fun Class<*>.allMethods(result: (index: Int, method: Method) -> Unit) = - declaredMethods.forEachIndexed { p, it -> result(p, it.apply { isAccessible = true }) } +inline fun Class<*>.allMethods(isAccessible: Boolean = true, result: (index: Int, method: Method) -> Unit) = + declaredMethods.forEachIndexed { p, it -> result(p, it.also { e -> e.isAccessible = isAccessible }) } /** * 遍历当前类中的所有构造方法 + * @param isAccessible 是否强制设置成员为可访问类型 - 默认是 * @param result 回调 - ([Int] 下标,[Constructor] 实例) */ -inline fun Class<*>.allConstructors(result: (index: Int, constructor: Constructor<*>) -> Unit) = - declaredConstructors.forEachIndexed { p, it -> result(p, it.apply { isAccessible = true }) } +inline fun Class<*>.allConstructors(isAccessible: Boolean = true, result: (index: Int, constructor: Constructor<*>) -> Unit) = + declaredConstructors.forEachIndexed { p, it -> result(p, it.also { e -> e.isAccessible = isAccessible }) } /** * 遍历当前类中的所有变量 + * @param isAccessible 是否强制设置成员为可访问类型 - 默认是 * @param result 回调 - ([Int] 下标,[Field] 实例) */ -inline fun Class<*>.allFields(result: (index: Int, field: Field) -> Unit) = - declaredFields.forEachIndexed { p, it -> result(p, it.apply { isAccessible = true }) } +inline fun Class<*>.allFields(isAccessible: Boolean = true, result: (index: Int, field: Field) -> Unit) = + declaredFields.forEachIndexed { p, it -> result(p, it.also { e -> e.isAccessible = isAccessible }) } /** * 检查内部类调用