mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 02:35:40 +08:00
Fix a reflection bug
This commit is contained in:
@@ -85,7 +85,7 @@ fun String.hasClass(loader: ClassLoader?) = try {
|
|||||||
*/
|
*/
|
||||||
fun Class<*>.hasMethod(name: String, vararg paramType: Class<*>): Boolean =
|
fun Class<*>.hasMethod(name: String, vararg paramType: Class<*>): Boolean =
|
||||||
try {
|
try {
|
||||||
getDeclaredMethod(name, *paramType)
|
obtainMethod(name, *paramType)
|
||||||
true
|
true
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
false
|
false
|
||||||
@@ -145,7 +145,9 @@ fun Class<*>.modifyField(any: Any?, name: String, value: Any?) {
|
|||||||
* @throws NoSuchMethodError
|
* @throws NoSuchMethodError
|
||||||
*/
|
*/
|
||||||
fun Class<*>.obtainMethod(name: String, vararg paramType: Class<*>): Method? =
|
fun Class<*>.obtainMethod(name: String, vararg paramType: Class<*>): Method? =
|
||||||
getDeclaredMethod(name, *paramType).apply { isAccessible = true }
|
if (paramType.isNotEmpty())
|
||||||
|
getDeclaredMethod(name, *paramType).apply { isAccessible = true }
|
||||||
|
else getDeclaredMethod(name).apply { isAccessible = true }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找并得到构造类
|
* 查找并得到构造类
|
||||||
@@ -154,7 +156,9 @@ fun Class<*>.obtainMethod(name: String, vararg paramType: Class<*>): Method? =
|
|||||||
* @throws NoSuchMethodError
|
* @throws NoSuchMethodError
|
||||||
*/
|
*/
|
||||||
fun Class<*>.obtainConstructor(vararg paramType: Class<*>): Constructor<out Any>? =
|
fun Class<*>.obtainConstructor(vararg paramType: Class<*>): Constructor<out Any>? =
|
||||||
getDeclaredConstructor(*paramType).apply { isAccessible = true }
|
if (paramType.isNotEmpty())
|
||||||
|
getDeclaredConstructor(*paramType).apply { isAccessible = true }
|
||||||
|
else getDeclaredConstructor().apply { isAccessible = true }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行静态方法
|
* 执行静态方法
|
||||||
|
Reference in New Issue
Block a user