public final class XposedHelpers
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
XposedHelpers.ClassNotFoundError
Thrown when a class loader is unable to find a class.
|
static class |
XposedHelpers.InvocationTargetError
This class provides a wrapper for an exception thrown by a method invocation.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
assetAsByteArray(android.res.Resources res,
java.lang.String path)
Loads an asset from a resource object and returns the content as
byte array. |
static java.lang.Object |
callMethod(java.lang.Object obj,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Object... args)
Calls an instance or static method of the given object.
|
static java.lang.Object |
callMethod(java.lang.Object obj,
java.lang.String methodName,
java.lang.Object... args)
Calls an instance or static method of the given object.
|
static java.lang.Object |
callStaticMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Object... args)
Calls a static method of the given class.
|
static java.lang.Object |
callStaticMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Object... args)
Calls a static method of the given class.
|
static int |
decrementMethodDepth(java.lang.String method)
Decrements the depth counter for the given method.
|
static XC_MethodHook.Unhook |
findAndHookConstructor(java.lang.Class<?> clazz,
java.lang.Object... parameterTypesAndCallback)
Look up a constructor and hook it.
|
static XC_MethodHook.Unhook |
findAndHookConstructor(java.lang.String className,
java.lang.ClassLoader classLoader,
java.lang.Object... parameterTypesAndCallback)
Look up a constructor and hook it.
|
static XC_MethodHook.Unhook |
findAndHookMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Object... parameterTypesAndCallback)
Look up a method and hook it.
|
static XC_MethodHook.Unhook |
findAndHookMethod(java.lang.String className,
java.lang.ClassLoader classLoader,
java.lang.String methodName,
java.lang.Object... parameterTypesAndCallback)
Look up a method and hook it.
|
static java.lang.Class<?> |
findClass(java.lang.String className,
java.lang.ClassLoader classLoader)
Look up a class with the specified class loader.
|
static java.lang.Class<?> |
findClassIfExists(java.lang.String className,
java.lang.ClassLoader classLoader)
Look up and return a class if it exists.
|
static java.lang.reflect.Constructor<?> |
findConstructorBestMatch(java.lang.Class<?> clazz,
java.lang.Class<?>... parameterTypes)
Look up a constructor in a class and set it to accessible.
|
static java.lang.reflect.Constructor<?> |
findConstructorBestMatch(java.lang.Class<?> clazz,
java.lang.Class<?>[] parameterTypes,
java.lang.Object[] args)
Look up a constructor in a class and set it to accessible.
|
static java.lang.reflect.Constructor<?> |
findConstructorBestMatch(java.lang.Class<?> clazz,
java.lang.Object... args)
Look up a constructor in a class and set it to accessible.
|
static java.lang.reflect.Constructor<?> |
findConstructorExact(java.lang.Class<?> clazz,
java.lang.Class<?>... parameterTypes)
Look up a constructor of a class and set it to accessible.
|
static java.lang.reflect.Constructor<?> |
findConstructorExact(java.lang.Class<?> clazz,
java.lang.Object... parameterTypes)
Look up a constructor of a class and set it to accessible.
|
static java.lang.reflect.Constructor<?> |
findConstructorExact(java.lang.String className,
java.lang.ClassLoader classLoader,
java.lang.Object... parameterTypes)
Look up a constructor of a class and set it to accessible.
|
static java.lang.reflect.Constructor<?> |
findConstructorExactIfExists(java.lang.Class<?> clazz,
java.lang.Object... parameterTypes)
Look up and return a constructor if it exists.
|
static java.lang.reflect.Constructor<?> |
findConstructorExactIfExists(java.lang.String className,
java.lang.ClassLoader classLoader,
java.lang.Object... parameterTypes)
Look up and return a constructor if it exists.
|
static java.lang.reflect.Field |
findField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Look up a field in a class and set it to accessible.
|
static java.lang.reflect.Field |
findFieldIfExists(java.lang.Class<?> clazz,
java.lang.String fieldName)
Look up and return a field if it exists.
|
static java.lang.reflect.Field |
findFirstFieldByExactType(java.lang.Class<?> clazz,
java.lang.Class<?> type)
Returns the first field of the given type in a class.
|
static java.lang.reflect.Method |
findMethodBestMatch(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Look up a method in a class and set it to accessible.
|
static java.lang.reflect.Method |
findMethodBestMatch(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Object[] args)
Look up a method in a class and set it to accessible.
|
static java.lang.reflect.Method |
findMethodBestMatch(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Object... args)
Look up a method in a class and set it to accessible.
|
static java.lang.reflect.Method |
findMethodExact(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Look up a method in a class and set it to accessible.
|
static java.lang.reflect.Method |
findMethodExact(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Object... parameterTypes)
Look up a method in a class and set it to accessible.
|
static java.lang.reflect.Method |
findMethodExact(java.lang.String className,
java.lang.ClassLoader classLoader,
java.lang.String methodName,
java.lang.Object... parameterTypes)
Look up a method in a class and set it to accessible.
|
static java.lang.reflect.Method |
findMethodExactIfExists(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Object... parameterTypes)
Look up and return a method if it exists.
|
static java.lang.reflect.Method |
findMethodExactIfExists(java.lang.String className,
java.lang.ClassLoader classLoader,
java.lang.String methodName,
java.lang.Object... parameterTypes)
Look up and return a method if it exists.
|
static java.lang.reflect.Method[] |
findMethodsByExactParameters(java.lang.Class<?> clazz,
java.lang.Class<?> returnType,
java.lang.Class<?>... parameterTypes)
Returns an array of all methods declared/overridden in a class with the specified parameter types.
|
static java.lang.Object |
getAdditionalInstanceField(java.lang.Object obj,
java.lang.String key)
Returns a value which was stored with
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object) . |
static java.lang.Object |
getAdditionalStaticField(java.lang.Class<?> clazz,
java.lang.String key)
Like
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object) , but the value is returned for clazz . |
static java.lang.Object |
getAdditionalStaticField(java.lang.Object obj,
java.lang.String key)
Like
getAdditionalInstanceField(java.lang.Object, java.lang.String) , but the value is returned for the class of obj . |
static boolean |
getBooleanField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
boolean field in the given object instance. |
static byte |
getByteField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
byte field in the given object instance. |
static char |
getCharField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
char field in the given object instance. |
static java.lang.Class<?>[] |
getClassesAsArray(java.lang.Class<?>... clazzes)
Returns an array of the given classes.
|
static double |
getDoubleField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
double field in the given object instance. |
static int |
getFirstParameterIndexByType(java.lang.reflect.Member method,
java.lang.Class<?> type)
Returns the index of the first parameter declared with the given type.
|
static float |
getFloatField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
float field in the given object instance. |
static int |
getIntField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of an
int field in the given object instance. |
static long |
getLongField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
long field in the given object instance. |
static java.lang.String |
getMD5Sum(java.lang.String file)
Returns the lowercase hex string representation of a file's MD5 hash sum.
|
static int |
getMethodDepth(java.lang.String method)
Returns the current depth counter for the given method.
|
static java.lang.Object |
getObjectField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of an object field in the given object instance.
|
static int |
getParameterIndexByType(java.lang.reflect.Member method,
java.lang.Class<?> type)
Returns the index of the parameter declared with the given type, ensuring that there is exactly one such parameter.
|
static java.lang.Class<?>[] |
getParameterTypes(java.lang.Object... args)
Returns an array with the classes of the given objects.
|
static short |
getShortField(java.lang.Object obj,
java.lang.String fieldName)
Returns the value of a
short field in the given object instance. |
static boolean |
getStaticBooleanField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Returns the value of a static
boolean field in the given class. |
static byte |
getStaticByteField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
byte field in the given class. |
static char |
getStaticCharField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
char field in the given class. |
static double |
getStaticDoubleField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
double field in the given class. |
static float |
getStaticFloatField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
float field in the given class. |
static int |
getStaticIntField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
int field in the given class. |
static long |
getStaticLongField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
long field in the given class. |
static java.lang.Object |
getStaticObjectField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Returns the value of a static object field in the given class.
|
static short |
getStaticShortField(java.lang.Class<?> clazz,
java.lang.String fieldName)
Sets the value of a static
short field in the given class. |
static java.lang.Object |
getSurroundingThis(java.lang.Object obj)
For inner classes, returns the surrounding instance, i.e.
|
static int |
incrementMethodDepth(java.lang.String method)
Increments the depth counter for the given method.
|
static java.lang.Object |
newInstance(java.lang.Class<?> clazz,
java.lang.Class<?>[] parameterTypes,
java.lang.Object... args)
Creates a new instance of the given class.
|
static java.lang.Object |
newInstance(java.lang.Class<?> clazz,
java.lang.Object... args)
Creates a new instance of the given class.
|
static java.lang.Object |
removeAdditionalInstanceField(java.lang.Object obj,
java.lang.String key)
Removes and returns a value which was stored with
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object) . |
static java.lang.Object |
removeAdditionalStaticField(java.lang.Class<?> clazz,
java.lang.String key)
Like
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object) , but the value is removed and returned for clazz . |
static java.lang.Object |
removeAdditionalStaticField(java.lang.Object obj,
java.lang.String key)
Like
removeAdditionalInstanceField(java.lang.Object, java.lang.String) , but the value is removed and returned for the class of obj . |
static java.lang.Object |
setAdditionalInstanceField(java.lang.Object obj,
java.lang.String key,
java.lang.Object value)
Attaches any value to an object instance.
|
static java.lang.Object |
setAdditionalStaticField(java.lang.Class<?> clazz,
java.lang.String key,
java.lang.Object value)
Like
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object) , but the value is stored for clazz . |
static java.lang.Object |
setAdditionalStaticField(java.lang.Object obj,
java.lang.String key,
java.lang.Object value)
Like
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object) , but the value is stored for the class of obj . |
static void |
setBooleanField(java.lang.Object obj,
java.lang.String fieldName,
boolean value)
Sets the value of a
boolean field in the given object instance. |
static void |
setByteField(java.lang.Object obj,
java.lang.String fieldName,
byte value)
Sets the value of a
byte field in the given object instance. |
static void |
setCharField(java.lang.Object obj,
java.lang.String fieldName,
char value)
Sets the value of a
char field in the given object instance. |
static void |
setDoubleField(java.lang.Object obj,
java.lang.String fieldName,
double value)
Sets the value of a
double field in the given object instance. |
static void |
setFloatField(java.lang.Object obj,
java.lang.String fieldName,
float value)
Sets the value of a
float field in the given object instance. |
static void |
setIntField(java.lang.Object obj,
java.lang.String fieldName,
int value)
Sets the value of an
int field in the given object instance. |
static void |
setLongField(java.lang.Object obj,
java.lang.String fieldName,
long value)
Sets the value of a
long field in the given object instance. |
static void |
setObjectField(java.lang.Object obj,
java.lang.String fieldName,
java.lang.Object value)
Sets the value of an object field in the given object instance.
|
static void |
setShortField(java.lang.Object obj,
java.lang.String fieldName,
short value)
Sets the value of a
short field in the given object instance. |
static void |
setStaticBooleanField(java.lang.Class<?> clazz,
java.lang.String fieldName,
boolean value)
Sets the value of a static
boolean field in the given class. |
static void |
setStaticByteField(java.lang.Class<?> clazz,
java.lang.String fieldName,
byte value)
Sets the value of a static
byte field in the given class. |
static void |
setStaticCharField(java.lang.Class<?> clazz,
java.lang.String fieldName,
char value)
Sets the value of a static
char field in the given class. |
static void |
setStaticDoubleField(java.lang.Class<?> clazz,
java.lang.String fieldName,
double value)
Sets the value of a static
double field in the given class. |
static void |
setStaticFloatField(java.lang.Class<?> clazz,
java.lang.String fieldName,
float value)
Sets the value of a static
float field in the given class. |
static void |
setStaticIntField(java.lang.Class<?> clazz,
java.lang.String fieldName,
int value)
Sets the value of a static
int field in the given class. |
static void |
setStaticLongField(java.lang.Class<?> clazz,
java.lang.String fieldName,
long value)
Sets the value of a static
long field in the given class. |
static void |
setStaticObjectField(java.lang.Class<?> clazz,
java.lang.String fieldName,
java.lang.Object value)
Sets the value of a static object field in the given class.
|
static void |
setStaticShortField(java.lang.Class<?> clazz,
java.lang.String fieldName,
short value)
Sets the value of a static
short field in the given class. |
public static java.lang.Class<?> findClass(java.lang.String className, java.lang.ClassLoader classLoader)
There are various allowed syntaxes for the class name, but it's recommended to use one of these:
java.lang.String
java.lang.String[]
(array)
android.app.ActivityThread.ResourcesKey
android.app.ActivityThread$ResourcesKey
className
- The class name in one of the formats mentioned above.classLoader
- The class loader, or null
for the boot class loader.XposedHelpers.ClassNotFoundError
- In case the class was not found.public static java.lang.Class<?> findClassIfExists(java.lang.String className, java.lang.ClassLoader classLoader)
findClass(java.lang.String, java.lang.ClassLoader)
, but doesn't throw an exception if the class doesn't exist.className
- The class name.classLoader
- The class loader, or null
for the boot class loader.null
if it doesn't exist.public static java.lang.reflect.Field findField(java.lang.Class<?> clazz, java.lang.String fieldName)
clazz
- The class which either declares or inherits the field.fieldName
- The field name.java.lang.NoSuchFieldError
- In case the field was not found.public static java.lang.reflect.Field findFieldIfExists(java.lang.Class<?> clazz, java.lang.String fieldName)
findField(java.lang.Class<?>, java.lang.String)
, but doesn't throw an exception if the field doesn't exist.clazz
- The class which either declares or inherits the field.fieldName
- The field name.null
if it doesn't exist.public static java.lang.reflect.Field findFirstFieldByExactType(java.lang.Class<?> clazz, java.lang.Class<?> type)
clazz
- The class which either declares or inherits the field.type
- The type of the field.java.lang.NoSuchFieldError
- In case no matching field was not found.public static XC_MethodHook.Unhook findAndHookMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object... parameterTypesAndCallback)
findAndHookMethod(String, ClassLoader, String, Object...)
for details.public static XC_MethodHook.Unhook findAndHookMethod(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.String methodName, java.lang.Object... parameterTypesAndCallback)
This combines calls to findMethodExact(Class, String, Object...)
and
XposedBridge.hookMethod(java.lang.reflect.Member, de.robv.android.xposed.XC_MethodHook)
.
The method must be declared or overridden in the given class, inherited
methods are not considered! That's because each method implementation exists only once in
the memory, and when classes inherit it, they just get another reference to the implementation.
Hooking a method therefore applies to all classes inheriting the same implementation. You
have to expect that the hook applies to subclasses (unless they override the method), but you
shouldn't have to worry about hooks applying to superclasses, hence this "limitation".
There could be undesired or even dangerous hooks otherwise, e.g. if you hook
SomeClass.equals()
and that class doesn't override the equals()
on some ROMs,
making you hook Object.equals()
instead.
There are two ways to specify the parameter types. If you already have a reference to the
Class
, use that. For Android framework classes, you can often use something like
String.class
. If you don't have the class reference, you can simply use the
full class name as a string, e.g. java.lang.String
or com.example.MyClass
.
It will be passed to findClass(java.lang.String, java.lang.ClassLoader)
with the same class loader that is used for the target
method, see its documentation for the allowed notations.
Primitive types, such as int
, can be specified using int.class
(recommended)
or Integer.TYPE
. Note that Integer.class
doesn't refer to int
but to
Integer
, which is a normal class (boxed primitive). Therefore it must not be used when
the method expects an int
parameter - it has to be used for Integer
parameters
though, so check the method signature in detail.
As last argument to this method (after the list of target method parameters), you need
to specify the callback that should be executed when the method is invoked. It's usually
an anonymous subclass of XC_MethodHook
or XC_MethodReplacement
.
Example
// In order to hook this method ... package com.example; public class SomeClass { public int doSomething(String s, int i, MyClass m) { ... } } // ... you can use this call: findAndHookMethod("com.example.SomeClass", lpparam.classLoader, String.class, int.class, "com.example.MyClass", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { String oldText = (String) param.args[0]; Log.d("MyModule", oldText); param.args[0] = "test"; param.args[1] = 42; // auto-boxing is working here setBooleanField(param.args[2], "great", true); // This would not work (as MyClass can't be resolved at compile time): // MyClass myClass = (MyClass) param.args[2]; // myClass.great = true; } });
className
- The name of the class which implements the method.classLoader
- The class loader for resolving the target and parameter classes.methodName
- The target method name.parameterTypesAndCallback
- The parameter types of the target method, plus the callback.java.lang.NoSuchMethodError
- In case the method was not found.XposedHelpers.ClassNotFoundError
- In case the target class or one of the parameter types couldn't be resolved.public static java.lang.reflect.Method findMethodExact(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object... parameterTypes)
findMethodExact(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Method findMethodExactIfExists(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object... parameterTypes)
findMethodExactIfExists(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Method findMethodExact(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.String methodName, java.lang.Object... parameterTypes)
See findAndHookMethod(String, ClassLoader, String, Object...)
for details about
the method and parameter type resolution.
className
- The name of the class which implements the method.classLoader
- The class loader for resolving the target and parameter classes.methodName
- The target method name.parameterTypes
- The parameter types of the target method.java.lang.NoSuchMethodError
- In case the method was not found.XposedHelpers.ClassNotFoundError
- In case the target class or one of the parameter types couldn't be resolved.public static java.lang.reflect.Method findMethodExactIfExists(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.String methodName, java.lang.Object... parameterTypes)
findMethodExact(String, ClassLoader, String, Object...)
, but doesn't throw an
exception if the method doesn't exist.className
- The name of the class which implements the method.classLoader
- The class loader for resolving the target and parameter classes.methodName
- The target method name.parameterTypes
- The parameter types of the target method.null
if it doesn't exist.public static java.lang.reflect.Method findMethodExact(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
findMethodExact(String, ClassLoader, String, Object...)
for details.
This variant requires that you already have reference to all the parameter types.
public static java.lang.reflect.Method[] findMethodsByExactParameters(java.lang.Class<?> clazz, java.lang.Class<?> returnType, java.lang.Class<?>... parameterTypes)
The return type is optional, it will not be compared if it is null
.
Use void.class
if you want to search for methods returning nothing.
clazz
- The class to look in.returnType
- The return type, or null
(see above).parameterTypes
- The parameter types.public static java.lang.reflect.Method findMethodBestMatch(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
This does'nt only look for exact matches, but for the best match. All considered candidates must be compatible with the given parameter types, i.e. the parameters must be assignable to the method's formal parameters. Inherited methods are considered here.
clazz
- The class which declares, inherits or overrides the method.methodName
- The method name.parameterTypes
- The types of the method's parameters.java.lang.NoSuchMethodError
- In case no suitable method was found.public static java.lang.reflect.Method findMethodBestMatch(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object... args)
See findMethodBestMatch(Class, String, Class...)
for details. This variant
determines the parameter types from the classes of the given objects.
public static java.lang.reflect.Method findMethodBestMatch(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args)
See findMethodBestMatch(Class, String, Class...)
for details. This variant
determines the parameter types from the classes of the given objects. For any item that is
null
, the type is taken from parameterTypes
instead.
public static java.lang.Class<?>[] getParameterTypes(java.lang.Object... args)
public static java.lang.Class<?>[] getClassesAsArray(java.lang.Class<?>... clazzes)
public static java.lang.reflect.Constructor<?> findConstructorExact(java.lang.Class<?> clazz, java.lang.Object... parameterTypes)
findMethodExact(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Constructor<?> findConstructorExactIfExists(java.lang.Class<?> clazz, java.lang.Object... parameterTypes)
findMethodExactIfExists(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Constructor<?> findConstructorExact(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.Object... parameterTypes)
findMethodExact(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Constructor<?> findConstructorExactIfExists(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.Object... parameterTypes)
findMethodExactIfExists(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Constructor<?> findConstructorExact(java.lang.Class<?> clazz, java.lang.Class<?>... parameterTypes)
findMethodExact(String, ClassLoader, String, Object...)
for details.public static XC_MethodHook.Unhook findAndHookConstructor(java.lang.Class<?> clazz, java.lang.Object... parameterTypesAndCallback)
findAndHookMethod(String, ClassLoader, String, Object...)
for details.public static XC_MethodHook.Unhook findAndHookConstructor(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.Object... parameterTypesAndCallback)
findAndHookMethod(String, ClassLoader, String, Object...)
for details.public static java.lang.reflect.Constructor<?> findConstructorBestMatch(java.lang.Class<?> clazz, java.lang.Class<?>... parameterTypes)
See findMethodBestMatch(Class, String, Class...)
for details.
public static java.lang.reflect.Constructor<?> findConstructorBestMatch(java.lang.Class<?> clazz, java.lang.Object... args)
See findMethodBestMatch(Class, String, Class...)
for details. This variant
determines the parameter types from the classes of the given objects.
public static java.lang.reflect.Constructor<?> findConstructorBestMatch(java.lang.Class<?> clazz, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args)
See findMethodBestMatch(Class, String, Class...)
for details. This variant
determines the parameter types from the classes of the given objects. For any item that is
null
, the type is taken from parameterTypes
instead.
public static int getFirstParameterIndexByType(java.lang.reflect.Member method, java.lang.Class<?> type)
java.lang.NoSuchFieldError
- if there is no parameter with that type.public static int getParameterIndexByType(java.lang.reflect.Member method, java.lang.Class<?> type)
java.lang.NoSuchFieldError
- if there is no or more than one parameter with that type.public static void setObjectField(java.lang.Object obj, java.lang.String fieldName, java.lang.Object value)
findField(java.lang.Class<?>, java.lang.String)
.public static void setBooleanField(java.lang.Object obj, java.lang.String fieldName, boolean value)
boolean
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setByteField(java.lang.Object obj, java.lang.String fieldName, byte value)
byte
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setCharField(java.lang.Object obj, java.lang.String fieldName, char value)
char
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setDoubleField(java.lang.Object obj, java.lang.String fieldName, double value)
double
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setFloatField(java.lang.Object obj, java.lang.String fieldName, float value)
float
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setIntField(java.lang.Object obj, java.lang.String fieldName, int value)
int
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setLongField(java.lang.Object obj, java.lang.String fieldName, long value)
long
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setShortField(java.lang.Object obj, java.lang.String fieldName, short value)
short
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static java.lang.Object getObjectField(java.lang.Object obj, java.lang.String fieldName)
findField(java.lang.Class<?>, java.lang.String)
.public static java.lang.Object getSurroundingThis(java.lang.Object obj)
this
reference of the surrounding class.public static boolean getBooleanField(java.lang.Object obj, java.lang.String fieldName)
boolean
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static byte getByteField(java.lang.Object obj, java.lang.String fieldName)
byte
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static char getCharField(java.lang.Object obj, java.lang.String fieldName)
char
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static double getDoubleField(java.lang.Object obj, java.lang.String fieldName)
double
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static float getFloatField(java.lang.Object obj, java.lang.String fieldName)
float
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static int getIntField(java.lang.Object obj, java.lang.String fieldName)
int
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static long getLongField(java.lang.Object obj, java.lang.String fieldName)
long
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static short getShortField(java.lang.Object obj, java.lang.String fieldName)
short
field in the given object instance. A class reference is not sufficient! See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticObjectField(java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Object value)
findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticBooleanField(java.lang.Class<?> clazz, java.lang.String fieldName, boolean value)
boolean
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticByteField(java.lang.Class<?> clazz, java.lang.String fieldName, byte value)
byte
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticCharField(java.lang.Class<?> clazz, java.lang.String fieldName, char value)
char
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticDoubleField(java.lang.Class<?> clazz, java.lang.String fieldName, double value)
double
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticFloatField(java.lang.Class<?> clazz, java.lang.String fieldName, float value)
float
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticIntField(java.lang.Class<?> clazz, java.lang.String fieldName, int value)
int
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticLongField(java.lang.Class<?> clazz, java.lang.String fieldName, long value)
long
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static void setStaticShortField(java.lang.Class<?> clazz, java.lang.String fieldName, short value)
short
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static java.lang.Object getStaticObjectField(java.lang.Class<?> clazz, java.lang.String fieldName)
findField(java.lang.Class<?>, java.lang.String)
.public static boolean getStaticBooleanField(java.lang.Class<?> clazz, java.lang.String fieldName)
boolean
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static byte getStaticByteField(java.lang.Class<?> clazz, java.lang.String fieldName)
byte
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static char getStaticCharField(java.lang.Class<?> clazz, java.lang.String fieldName)
char
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static double getStaticDoubleField(java.lang.Class<?> clazz, java.lang.String fieldName)
double
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static float getStaticFloatField(java.lang.Class<?> clazz, java.lang.String fieldName)
float
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static int getStaticIntField(java.lang.Class<?> clazz, java.lang.String fieldName)
int
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static long getStaticLongField(java.lang.Class<?> clazz, java.lang.String fieldName)
long
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static short getStaticShortField(java.lang.Class<?> clazz, java.lang.String fieldName)
short
field in the given class. See also findField(java.lang.Class<?>, java.lang.String)
.public static java.lang.Object callMethod(java.lang.Object obj, java.lang.String methodName, java.lang.Object... args)
findMethodBestMatch(Class, String, Object...)
.obj
- The object instance. A class reference is not sufficient!methodName
- The method name.args
- The arguments for the method call.java.lang.NoSuchMethodError
- In case no suitable method was found.XposedHelpers.InvocationTargetError
- In case an exception was thrown by the invoked method.public static java.lang.Object callMethod(java.lang.Object obj, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object... args)
callMethod(Object, String, Object...)
.
This variant allows you to specify parameter types, which can help in case there are multiple
methods with the same name, especially if you call it with null
parameters.
public static java.lang.Object callStaticMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object... args)
findMethodBestMatch(Class, String, Object...)
.clazz
- The class reference.methodName
- The method name.args
- The arguments for the method call.java.lang.NoSuchMethodError
- In case no suitable method was found.XposedHelpers.InvocationTargetError
- In case an exception was thrown by the invoked method.public static java.lang.Object callStaticMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object... args)
callStaticMethod(Class, String, Object...)
.
This variant allows you to specify parameter types, which can help in case there are multiple
methods with the same name, especially if you call it with null
parameters.
public static java.lang.Object newInstance(java.lang.Class<?> clazz, java.lang.Object... args)
findConstructorBestMatch(Class, Object...)
.clazz
- The class reference.args
- The arguments for the constructor call.java.lang.NoSuchMethodError
- In case no suitable constructor was found.XposedHelpers.InvocationTargetError
- In case an exception was thrown by the invoked method.java.lang.InstantiationError
- In case the class cannot be instantiated.public static java.lang.Object newInstance(java.lang.Class<?> clazz, java.lang.Class<?>[] parameterTypes, java.lang.Object... args)
newInstance(Class, Object...)
.
This variant allows you to specify parameter types, which can help in case there are multiple
constructors with the same name, especially if you call it with null
parameters.
public static java.lang.Object setAdditionalInstanceField(java.lang.Object obj, java.lang.String key, java.lang.Object value)
getAdditionalInstanceField(java.lang.Object, java.lang.String)
.obj
- The object instance for which the value should be stored.key
- The key in the value map for this object instance.value
- The value to store.null
if there was none.public static java.lang.Object getAdditionalInstanceField(java.lang.Object obj, java.lang.String key)
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object)
.obj
- The object instance for which the value has been stored.key
- The key in the value map for this object instance.null
if there is none.public static java.lang.Object removeAdditionalInstanceField(java.lang.Object obj, java.lang.String key)
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object)
.obj
- The object instance for which the value has been stored.key
- The key in the value map for this object instance.null
if there was none.public static java.lang.Object setAdditionalStaticField(java.lang.Object obj, java.lang.String key, java.lang.Object value)
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object)
, but the value is stored for the class of obj
.public static java.lang.Object getAdditionalStaticField(java.lang.Object obj, java.lang.String key)
getAdditionalInstanceField(java.lang.Object, java.lang.String)
, but the value is returned for the class of obj
.public static java.lang.Object removeAdditionalStaticField(java.lang.Object obj, java.lang.String key)
removeAdditionalInstanceField(java.lang.Object, java.lang.String)
, but the value is removed and returned for the class of obj
.public static java.lang.Object setAdditionalStaticField(java.lang.Class<?> clazz, java.lang.String key, java.lang.Object value)
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object)
, but the value is stored for clazz
.public static java.lang.Object getAdditionalStaticField(java.lang.Class<?> clazz, java.lang.String key)
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object)
, but the value is returned for clazz
.public static java.lang.Object removeAdditionalStaticField(java.lang.Class<?> clazz, java.lang.String key)
setAdditionalInstanceField(java.lang.Object, java.lang.String, java.lang.Object)
, but the value is removed and returned for clazz
.public static byte[] assetAsByteArray(android.res.Resources res, java.lang.String path) throws java.io.IOException
byte
array.res
- The resources from which the asset should be loaded.path
- The path to the assetjava.io.IOException
public static java.lang.String getMD5Sum(java.lang.String file) throws java.io.IOException
java.io.IOException
public static int incrementMethodDepth(java.lang.String method)
The intention of the method depth counter is to keep track of the call depth for recursive
methods, e.g. to override parameters only for the outer call. The Xposed framework uses this
to load drawable replacements only once per call, even when multiple
Resources.getDrawable()
variants call each other.
method
- The method name. Should be prefixed with a unique, module-specific string.public static int decrementMethodDepth(java.lang.String method)
incrementMethodDepth(java.lang.String)
for details.method
- The method name. Should be prefixed with a unique, module-specific string.public static int getMethodDepth(java.lang.String method)
incrementMethodDepth(java.lang.String)
for details.method
- The method name. Should be prefixed with a unique, module-specific string.