mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-07 03:05:36 +08:00
...
This commit is contained in:
@@ -433,7 +433,7 @@ class YukiHookCreater(private val packageParam: PackageParam, private val hookCl
|
|||||||
private fun onHookFailureMsg(throwable: Throwable) =
|
private fun onHookFailureMsg(throwable: Throwable) =
|
||||||
loggerE(msg = "Try to hook ${hookClass.instance ?: hookClass.name}[$member] got an Exception [$tag]", e = throwable)
|
loggerE(msg = "Try to hook ${hookClass.instance ?: hookClass.name}[$member] got an Exception [$tag]", e = throwable)
|
||||||
|
|
||||||
override fun toString() = "$member$tag#YukiHook"
|
override fun toString() = "${hookClass.name}$member$tag#YukiHookAPI"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听 Hook 结果实现类
|
* 监听 Hook 结果实现类
|
||||||
|
@@ -121,7 +121,7 @@ class HookParam(private val wrapper: HookParamWrapper) {
|
|||||||
* @param args 参数实例
|
* @param args 参数实例
|
||||||
* @return [T]
|
* @return [T]
|
||||||
*/
|
*/
|
||||||
fun <T> Member.invokeOriginal(vararg args: Array<Any?>?) = wrapper.invokeOriginalMember(member = this, *args) as? T?
|
fun <T> Member.invokeOriginal(vararg args: Any?) = wrapper.invokeOriginalMember(member = this, *args) as? T?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置 [result] 返回值为 true
|
* 设置 [result] 返回值为 true
|
||||||
|
@@ -83,6 +83,6 @@ class HookParamWrapper(private val baseParam: XC_MethodHook.MethodHookParam) {
|
|||||||
* @param args 参数实例
|
* @param args 参数实例
|
||||||
* @return [Any] or null
|
* @return [Any] or null
|
||||||
*/
|
*/
|
||||||
fun invokeOriginalMember(member: Member, vararg args: Array<Any?>?): Any? =
|
fun invokeOriginalMember(member: Member, vararg args: Any?): Any? =
|
||||||
XposedBridge.invokeOriginalMethod(member, instance, args)
|
XposedBridge.invokeOriginalMethod(member, instance, args)
|
||||||
}
|
}
|
@@ -108,7 +108,7 @@ public class ReflectionUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Field findFieldIfExists(Class<?> clazz, String typeName, String fieldName) throws NoSuchFieldException {
|
public static Field findFieldIfExists(Class<?> clazz, String typeName, String fieldName) throws NoSuchFieldException {
|
||||||
String fullFieldName = "name:[" + fieldName + "] type:[" + typeName + "] in Class [" + clazz.getName() + "] by YukiHook#finder";
|
String fullFieldName = "name:[" + fieldName + "] type:[" + typeName + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||||
if (!fieldCache.containsKey(fullFieldName)) {
|
if (!fieldCache.containsKey(fullFieldName)) {
|
||||||
if (clazz != null && !TextUtils.isEmpty(typeName) && !TextUtils.isEmpty(fieldName)) {
|
if (clazz != null && !TextUtils.isEmpty(typeName) && !TextUtils.isEmpty(fieldName)) {
|
||||||
Class<?> clz = clazz;
|
Class<?> clz = clazz;
|
||||||
@@ -143,7 +143,7 @@ public class ReflectionUtils {
|
|||||||
* @param methodName 方法名
|
* @param methodName 方法名
|
||||||
*/
|
*/
|
||||||
public static Method findMethodNoParam(Class<?> clazz, Class<?> returnType, String methodName) {
|
public static Method findMethodNoParam(Class<?> clazz, Class<?> returnType, String methodName) {
|
||||||
String fullMethodName = "name:[" + methodName + "] in Class [" + clazz.getName() + "] by YukiHook#finder";
|
String fullMethodName = "name:[" + methodName + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||||
if (!methodCache.containsKey(fullMethodName)) {
|
if (!methodCache.containsKey(fullMethodName)) {
|
||||||
Method method = findMethodIfExists(clazz, returnType, methodName);
|
Method method = findMethodIfExists(clazz, returnType, methodName);
|
||||||
methodCache.put(fullMethodName, method);
|
methodCache.put(fullMethodName, method);
|
||||||
@@ -162,7 +162,7 @@ public class ReflectionUtils {
|
|||||||
* @param parameterTypes 方法参数类型数组
|
* @param parameterTypes 方法参数类型数组
|
||||||
*/
|
*/
|
||||||
public static Method findMethodBestMatch(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
|
public static Method findMethodBestMatch(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
|
||||||
String fullMethodName = "name:[" + methodName + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHook#finder";
|
String fullMethodName = "name:[" + methodName + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||||
if (!methodCache.containsKey(fullMethodName)) {
|
if (!methodCache.containsKey(fullMethodName)) {
|
||||||
Method method = findMethodIfExists(clazz, returnType, methodName, parameterTypes);
|
Method method = findMethodIfExists(clazz, returnType, methodName, parameterTypes);
|
||||||
methodCache.put(fullMethodName, method);
|
methodCache.put(fullMethodName, method);
|
||||||
@@ -179,7 +179,7 @@ public class ReflectionUtils {
|
|||||||
* @param parameterTypes 构造类方法参数类型数组
|
* @param parameterTypes 构造类方法参数类型数组
|
||||||
*/
|
*/
|
||||||
public static Constructor<?> findConstructorExact(Class<?> clazz, Class<?>... parameterTypes) {
|
public static Constructor<?> findConstructorExact(Class<?> clazz, Class<?>... parameterTypes) {
|
||||||
String fullConstructorName = "paramType:[" + getParametersString(parameterTypes) + "in Class [" + clazz.getName() + "] by YukiHook#finder";
|
String fullConstructorName = "paramType:[" + getParametersString(parameterTypes) + "in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||||
try {
|
try {
|
||||||
Constructor<?> constructor = clazz.getDeclaredConstructor(parameterTypes);
|
Constructor<?> constructor = clazz.getDeclaredConstructor(parameterTypes);
|
||||||
constructor.setAccessible(true);
|
constructor.setAccessible(true);
|
||||||
@@ -190,7 +190,7 @@ public class ReflectionUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Method findMethodExact(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
|
private static Method findMethodExact(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
|
||||||
String fullMethodName = "name:[" + methodName + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHook#finder";
|
String fullMethodName = "name:[" + methodName + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder";
|
||||||
try {
|
try {
|
||||||
Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
|
Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
@@ -210,6 +210,6 @@ public class ReflectionUtils {
|
|||||||
for (Method method : methods) if (method.getName().equals(methodName)) return method;
|
for (Method method : methods) if (method.getName().equals(methodName)) return method;
|
||||||
} while ((clz = clz.getSuperclass()) != null);
|
} while ((clz = clz.getSuperclass()) != null);
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Can't find this method --> name:[" + methodName + "] returnType:[" + returnType.getName() + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHook#finder");
|
throw new IllegalArgumentException("Can't find this method --> name:[" + methodName + "] returnType:[" + returnType.getName() + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user