mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 17:55:24 +08:00
...
This commit is contained in:
@@ -9,15 +9,9 @@ java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceSets.main { java.srcDir("src/api/kotlin") }
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.addStringOption("charset", "UTF-8")
|
||||
if (JavaVersion.current().isJava9Compatible()) options.addBooleanOption("html5", true)
|
||||
}
|
||||
|
||||
kotlin { sourceSets.main { kotlin.srcDir("src/api/kotlin") } }
|
||||
|
||||
dependencies {
|
||||
|
@@ -41,11 +41,18 @@ import de.robv.android.xposed.XposedHelpers;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@DoNotUseClass
|
||||
/**
|
||||
* ReflectionUtils
|
||||
*/
|
||||
public class ReflectionUtils {
|
||||
|
||||
private static final HashMap<String, Field> fieldCache = new HashMap<>();
|
||||
private static final HashMap<String, Method> methodCache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param clazzes
|
||||
* @return String
|
||||
*/
|
||||
private static String getParametersString(Class<?>... clazzes) {
|
||||
StringBuilder sb = new StringBuilder("(");
|
||||
boolean first = true;
|
||||
@@ -64,12 +71,26 @@ public class ReflectionUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clazz
|
||||
* @param fieldType
|
||||
* @param fieldName
|
||||
* @param value
|
||||
* @return Field
|
||||
*/
|
||||
@Deprecated
|
||||
public static void setStaticObjectField(Class<?> clazz, Class<?> fieldType, String fieldName, Object value)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
findFieldIfExists(clazz, fieldType, fieldName).set(null, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fieldType
|
||||
* @param fieldName
|
||||
* @param value
|
||||
* @param obj
|
||||
* @return Field
|
||||
*/
|
||||
@Deprecated
|
||||
public static void setObjectField(Object obj, Class<?> fieldType, String fieldName, Object value)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
@@ -81,12 +102,12 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Field findFieldIfExists(Class<?> clazz, Class<?> fieldType, String fieldName)
|
||||
private static Field findFieldIfExists(Class<?> clazz, Class<?> fieldType, String fieldName)
|
||||
throws NoSuchFieldException {
|
||||
return findFieldIfExists(clazz, fieldType.getName(), fieldName);
|
||||
}
|
||||
|
||||
public static boolean isCallingFrom(String className) {
|
||||
private static boolean isCallingFrom(String className) {
|
||||
StackTraceElement[] stackTraceElements = Thread.currentThread()
|
||||
.getStackTrace();
|
||||
for (StackTraceElement element : stackTraceElements) {
|
||||
@@ -98,7 +119,7 @@ public class ReflectionUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCallingFromEither(String... classname) {
|
||||
private static boolean isCallingFromEither(String... classname) {
|
||||
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement element : stackTraceElements) {
|
||||
for (String name : classname) {
|
||||
@@ -110,6 +131,12 @@ public class ReflectionUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clazz
|
||||
* @param typeName
|
||||
* @param fieldName
|
||||
* @return Field
|
||||
*/
|
||||
public static Field findFieldIfExists(Class<?> clazz, String typeName, String fieldName) throws NoSuchFieldException {
|
||||
String fullFieldName = "name:[" + fieldName + "] type:[" + typeName + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||
if (!fieldCache.containsKey(fullFieldName)) {
|
||||
@@ -144,6 +171,7 @@ public class ReflectionUtils {
|
||||
* @param clazz 方法所在类
|
||||
* @param returnType 返回类型
|
||||
* @param methodName 方法名
|
||||
* @return Method
|
||||
*/
|
||||
public static Method findMethodNoParam(Class<?> clazz, Class<?> returnType, String methodName) {
|
||||
String fullMethodName = "name:[" + methodName + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||
@@ -163,6 +191,7 @@ public class ReflectionUtils {
|
||||
* @param returnType 返回类型
|
||||
* @param methodName 方法名
|
||||
* @param parameterTypes 方法参数类型数组
|
||||
* @return Method
|
||||
*/
|
||||
public static Method findMethodBestMatch(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
|
||||
String fullMethodName = "name:[" + methodName + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||
@@ -180,6 +209,7 @@ public class ReflectionUtils {
|
||||
*
|
||||
* @param clazz 构造类所在类
|
||||
* @param parameterTypes 构造类方法参数类型数组
|
||||
* @return Constructor
|
||||
*/
|
||||
public static Constructor<?> findConstructorExact(Class<?> clazz, Class<?>... parameterTypes) {
|
||||
String fullConstructorName = "paramType:[" + getParametersString(parameterTypes) + "in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||
|
Reference in New Issue
Block a user