public final class

XposedHelpers

extends Object
java.lang.Object
   ↳ de.robv.android.xposed.XposedHelpers

Class Overview

Helpers that simplify hooking and calling methods/constructors, getting and settings fields, ...

Summary

Nested Classes
class XposedHelpers.ClassNotFoundError Thrown when a class loader is unable to find a class. 
class XposedHelpers.InvocationTargetError This class provides a wrapper for an exception thrown by a method invocation. 
Public Methods
static byte[] assetAsByteArray(Resources res, String path)
Loads an asset from a resource object and returns the content as byte array.
static Object callMethod(Object obj, String methodName, Class[]<?> parameterTypes, Object... args)
Calls an instance or static method of the given object.
static Object callMethod(Object obj, String methodName, Object... args)
Calls an instance or static method of the given object.
static Object callStaticMethod(Class<?> clazz, String methodName, Class[]<?> parameterTypes, Object... args)
Calls a static method of the given class.
static Object callStaticMethod(Class<?> clazz, String methodName, Object... args)
Calls a static method of the given class.
static int decrementMethodDepth(String method)
Decrements the depth counter for the given method.
static XC_MethodHook.Unhook findAndHookConstructor(Class<?> clazz, Object... parameterTypesAndCallback)
Look up a constructor and hook it.
static XC_MethodHook.Unhook findAndHookConstructor(String className, ClassLoader classLoader, Object... parameterTypesAndCallback)
Look up a constructor and hook it.
static XC_MethodHook.Unhook findAndHookMethod(Class<?> clazz, String methodName, Object... parameterTypesAndCallback)
Look up a method and hook it.
static XC_MethodHook.Unhook findAndHookMethod(String className, ClassLoader classLoader, String methodName, Object... parameterTypesAndCallback)
Look up a method and hook it.
static Class<?> findClass(String className, ClassLoader classLoader)
Look up a class with the specified class loader.
static Class<?> findClassIfExists(String className, ClassLoader classLoader)
Look up and return a class if it exists.
static Constructor<?> findConstructorBestMatch(Class<?> clazz, Class[]<?> parameterTypes, Object[] args)
Look up a constructor in a class and set it to accessible.
static Constructor<?> findConstructorBestMatch(Class<?> clazz, Object... args)
Look up a constructor in a class and set it to accessible.
static Constructor<?> findConstructorBestMatch(Class<?> clazz, Class...<?> parameterTypes)
Look up a constructor in a class and set it to accessible.
static Constructor<?> findConstructorExact(String className, ClassLoader classLoader, Object... parameterTypes)
Look up a constructor of a class and set it to accessible.
static Constructor<?> findConstructorExact(Class<?> clazz, Class...<?> parameterTypes)
Look up a constructor of a class and set it to accessible.
static Constructor<?> findConstructorExact(Class<?> clazz, Object... parameterTypes)
Look up a constructor of a class and set it to accessible.
static Constructor<?> findConstructorExactIfExists(Class<?> clazz, Object... parameterTypes)
Look up and return a constructor if it exists.
static Constructor<?> findConstructorExactIfExists(String className, ClassLoader classLoader, Object... parameterTypes)
Look up and return a constructor if it exists.
static Field findField(Class<?> clazz, String fieldName)
Look up a field in a class and set it to accessible.
static Field findFieldIfExists(Class<?> clazz, String fieldName)
Look up and return a field if it exists.
static Field findFirstFieldByExactType(Class<?> clazz, Class<?> type)
Returns the first field of the given type in a class.
static Method findMethodBestMatch(Class<?> clazz, String methodName, Class[]<?> parameterTypes, Object[] args)
Look up a method in a class and set it to accessible.
static Method findMethodBestMatch(Class<?> clazz, String methodName, Object... args)
Look up a method in a class and set it to accessible.
static Method findMethodBestMatch(Class<?> clazz, String methodName, Class...<?> parameterTypes)
Look up a method in a class and set it to accessible.
static Method findMethodExact(Class<?> clazz, String methodName, Class...<?> parameterTypes)
Look up a method in a class and set it to accessible.
static Method findMethodExact(Class<?> clazz, String methodName, Object... parameterTypes)
Look up a method in a class and set it to accessible.
static Method findMethodExact(String className, ClassLoader classLoader, String methodName, Object... parameterTypes)
Look up a method in a class and set it to accessible.
static Method findMethodExactIfExists(Class<?> clazz, String methodName, Object... parameterTypes)
Look up and return a method if it exists.
static Method findMethodExactIfExists(String className, ClassLoader classLoader, String methodName, Object... parameterTypes)
Look up and return a method if it exists.
static Method[] findMethodsByExactParameters(Class<?> clazz, Class<?> returnType, Class...<?> parameterTypes)
Returns an array of all methods declared/overridden in a class with the specified parameter types.
static Object getAdditionalInstanceField(Object obj, String key)
Returns a value which was stored with setAdditionalInstanceField(Object, String, Object).
static Object getAdditionalStaticField(Class<?> clazz, String key)
Like setAdditionalInstanceField(Object, String, Object), but the value is returned for clazz.
static Object getAdditionalStaticField(Object obj, String key)
Like getAdditionalInstanceField(Object, String), but the value is returned for the class of obj.
static boolean getBooleanField(Object obj, String fieldName)
Returns the value of a boolean field in the given object instance.
static byte getByteField(Object obj, String fieldName)
Returns the value of a byte field in the given object instance.
static char getCharField(Object obj, String fieldName)
Returns the value of a char field in the given object instance.
static Class[]<?> getClassesAsArray(Class...<?> clazzes)
Returns an array of the given classes.
static double getDoubleField(Object obj, String fieldName)
Returns the value of a double field in the given object instance.
static float getFloatField(Object obj, String fieldName)
Returns the value of a float field in the given object instance.
static int getIntField(Object obj, String fieldName)
Returns the value of an int field in the given object instance.
static long getLongField(Object obj, String fieldName)
Returns the value of a long field in the given object instance.
static String getMD5Sum(String file)
Returns the lowercase hex string representation of a file's MD5 hash sum.
static int getMethodDepth(String method)
Returns the current depth counter for the given method.
static Object getObjectField(Object obj, String fieldName)
Returns the value of an object field in the given object instance.
static Class[]<?> getParameterTypes(Object... args)
Returns an array with the classes of the given objects.
static short getShortField(Object obj, String fieldName)
Returns the value of a short field in the given object instance.
static boolean getStaticBooleanField(Class<?> clazz, String fieldName)
Returns the value of a static boolean field in the given class.
static byte getStaticByteField(Class<?> clazz, String fieldName)
Sets the value of a static byte field in the given class.
static char getStaticCharField(Class<?> clazz, String fieldName)
Sets the value of a static char field in the given class.
static double getStaticDoubleField(Class<?> clazz, String fieldName)
Sets the value of a static double field in the given class.
static float getStaticFloatField(Class<?> clazz, String fieldName)
Sets the value of a static float field in the given class.
static int getStaticIntField(Class<?> clazz, String fieldName)
Sets the value of a static int field in the given class.
static long getStaticLongField(Class<?> clazz, String fieldName)
Sets the value of a static long field in the given class.
static Object getStaticObjectField(Class<?> clazz, String fieldName)
Returns the value of a static object field in the given class.
static short getStaticShortField(Class<?> clazz, String fieldName)
Sets the value of a static short field in the given class.
static Object getSurroundingThis(Object obj)
For inner classes, returns the surrounding instance, i.e.
static int incrementMethodDepth(String method)
Increments the depth counter for the given method.
static Object newInstance(Class<?> clazz, Object... args)
Creates a new instance of the given class.
static Object newInstance(Class<?> clazz, Class[]<?> parameterTypes, Object... args)
Creates a new instance of the given class.
static Object removeAdditionalInstanceField(Object obj, String key)
Removes and returns a value which was stored with setAdditionalInstanceField(Object, String, Object).
static Object removeAdditionalStaticField(Class<?> clazz, String key)
Like setAdditionalInstanceField(Object, String, Object), but the value is removed and returned for clazz.
static Object removeAdditionalStaticField(Object obj, String key)
Like removeAdditionalInstanceField(Object, String), but the value is removed and returned for the class of obj.
static Object setAdditionalInstanceField(Object obj, String key, Object value)
Attaches any value to an object instance.
static Object setAdditionalStaticField(Object obj, String key, Object value)
Like setAdditionalInstanceField(Object, String, Object), but the value is stored for the class of obj.
static Object setAdditionalStaticField(Class<?> clazz, String key, Object value)
Like setAdditionalInstanceField(Object, String, Object), but the value is stored for clazz.
static void setBooleanField(Object obj, String fieldName, boolean value)
Sets the value of a boolean field in the given object instance.
static void setByteField(Object obj, String fieldName, byte value)
Sets the value of a byte field in the given object instance.
static void setCharField(Object obj, String fieldName, char value)
Sets the value of a char field in the given object instance.
static void setDoubleField(Object obj, String fieldName, double value)
Sets the value of a double field in the given object instance.
static void setFloatField(Object obj, String fieldName, float value)
Sets the value of a float field in the given object instance.
static void setIntField(Object obj, String fieldName, int value)
Sets the value of an int field in the given object instance.
static void setLongField(Object obj, String fieldName, long value)
Sets the value of a long field in the given object instance.
static void setObjectField(Object obj, String fieldName, Object value)
Sets the value of an object field in the given object instance.
static void setShortField(Object obj, String fieldName, short value)
Sets the value of a short field in the given object instance.
static void setStaticBooleanField(Class<?> clazz, String fieldName, boolean value)
Sets the value of a static boolean field in the given class.
static void setStaticByteField(Class<?> clazz, String fieldName, byte value)
Sets the value of a static byte field in the given class.
static void setStaticCharField(Class<?> clazz, String fieldName, char value)
Sets the value of a static char field in the given class.
static void setStaticDoubleField(Class<?> clazz, String fieldName, double value)
Sets the value of a static double field in the given class.
static void setStaticFloatField(Class<?> clazz, String fieldName, float value)
Sets the value of a static float field in the given class.
static void setStaticIntField(Class<?> clazz, String fieldName, int value)
Sets the value of a static int field in the given class.
static void setStaticLongField(Class<?> clazz, String fieldName, long value)
Sets the value of a static long field in the given class.
static void setStaticObjectField(Class<?> clazz, String fieldName, Object value)
Sets the value of a static object field in the given class.
static void setStaticShortField(Class<?> clazz, String fieldName, short value)
Sets the value of a static short field in the given class.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static byte[] assetAsByteArray (Resources res, String path)

Loads an asset from a resource object and returns the content as byte array.

Parameters
res The resources from which the asset should be loaded.
path The path to the asset, as in AssetManager.open(String).
Returns
  • The content of the asset.
Throws
IOException

public static Object callMethod (Object obj, String methodName, Class[]<?> parameterTypes, Object... args)

Calls an instance or static method of the given object. See 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 Object callMethod (Object obj, String methodName, Object... args)

Calls an instance or static method of the given object. The method is resolved using findMethodBestMatch(Class, String, Object...).

Parameters
obj The object instance. A class reference is not sufficient!
methodName The method name.
args The arguments for the method call.
Throws
NoSuchMethodError In case no suitable method was found.
XposedHelpers.InvocationTargetError In case an exception was thrown by the invoked method.

public static Object callStaticMethod (Class<?> clazz, String methodName, Class[]<?> parameterTypes, Object... args)

Calls a static method of the given class. See 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 Object callStaticMethod (Class<?> clazz, String methodName, Object... args)

Calls a static method of the given class. The method is resolved using findMethodBestMatch(Class, String, Object...).

Parameters
clazz The class reference.
methodName The method name.
args The arguments for the method call.
Throws
NoSuchMethodError In case no suitable method was found.
XposedHelpers.InvocationTargetError In case an exception was thrown by the invoked method.

public static int decrementMethodDepth (String method)

Added in API level 63

Decrements the depth counter for the given method. See incrementMethodDepth(String) for details.

Parameters
method The method name. Should be prefixed with a unique, module-specific string.
Returns
  • The updated depth.

public static XC_MethodHook.Unhook findAndHookConstructor (Class<?> clazz, Object... parameterTypesAndCallback)

Added in API level 51

Look up a constructor and hook it. See findAndHookMethod(String, ClassLoader, String, Object...) for details.

public static XC_MethodHook.Unhook findAndHookConstructor (String className, ClassLoader classLoader, Object... parameterTypesAndCallback)

Added in API level 51

Look up a constructor and hook it. See findAndHookMethod(String, ClassLoader, String, Object...) for details.

public static XC_MethodHook.Unhook findAndHookMethod (Class<?> clazz, String methodName, Object... parameterTypesAndCallback)

Look up a method and hook it. See findAndHookMethod(String, ClassLoader, String, Object...) for details.

public static XC_MethodHook.Unhook findAndHookMethod (String className, ClassLoader classLoader, String methodName, Object... parameterTypesAndCallback)

Look up a method and hook it. The last argument must be the callback for the hook.

This combines calls to findMethodExact(Class, String, Object...) and XposedBridge.hookMethod(Member, 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(String, 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;
   }
 });
 

Parameters
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.
Returns
  • An object which can be used to remove the callback again.
Throws
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 Class<?> findClass (String className, ClassLoader classLoader)

Look up a class with the specified class loader.

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

Parameters
className The class name in one of the formats mentioned above.
classLoader The class loader, or null for the boot class loader.
Returns
  • A reference to the class.
Throws
XposedHelpers.ClassNotFoundError In case the class was not found.

public static Class<?> findClassIfExists (String className, ClassLoader classLoader)

Added in API level 82

Look up and return a class if it exists. Like findClass(String, ClassLoader), but doesn't throw an exception if the class doesn't exist.

Parameters
className The class name.
classLoader The class loader, or null for the boot class loader.
Returns
  • A reference to the class, or null if it doesn't exist.

public static Constructor<?> findConstructorBestMatch (Class<?> clazz, Class[]<?> parameterTypes, Object[] args)

Look up a constructor in a class and set it to accessible.

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 Constructor<?> findConstructorBestMatch (Class<?> clazz, Object... args)

Look up a constructor in a class and set it to accessible.

See findMethodBestMatch(Class, String, Class...) for details. This variant determines the parameter types from the classes of the given objects.

public static Constructor<?> findConstructorBestMatch (Class<?> clazz, Class...<?> parameterTypes)

Look up a constructor in a class and set it to accessible.

See findMethodBestMatch(Class, String, Class...) for details.

public static Constructor<?> findConstructorExact (String className, ClassLoader classLoader, Object... parameterTypes)

Added in API level 51

Look up a constructor of a class and set it to accessible. See findMethodExact(String, ClassLoader, String, Object...) for details.

public static Constructor<?> findConstructorExact (Class<?> clazz, Class...<?> parameterTypes)

Look up a constructor of a class and set it to accessible. See findMethodExact(String, ClassLoader, String, Object...) for details.

public static Constructor<?> findConstructorExact (Class<?> clazz, Object... parameterTypes)

Added in API level 51

Look up a constructor of a class and set it to accessible. See findMethodExact(String, ClassLoader, String, Object...) for details.

public static Constructor<?> findConstructorExactIfExists (Class<?> clazz, Object... parameterTypes)

Added in API level 82

Look up and return a constructor if it exists. See findMethodExactIfExists(String, ClassLoader, String, Object...) for details.

public static Constructor<?> findConstructorExactIfExists (String className, ClassLoader classLoader, Object... parameterTypes)

Added in API level 82

Look up and return a constructor if it exists. See findMethodExactIfExists(String, ClassLoader, String, Object...) for details.

public static Field findField (Class<?> clazz, String fieldName)

Look up a field in a class and set it to accessible.

Parameters
clazz The class which either declares or inherits the field.
fieldName The field name.
Returns
  • A reference to the field.
Throws
NoSuchFieldError In case the field was not found.

public static Field findFieldIfExists (Class<?> clazz, String fieldName)

Added in API level 82

Look up and return a field if it exists. Like findField(Class, String), but doesn't throw an exception if the field doesn't exist.

Parameters
clazz The class which either declares or inherits the field.
fieldName The field name.
Returns
  • A reference to the field, or null if it doesn't exist.

public static Field findFirstFieldByExactType (Class<?> clazz, Class<?> type)

Added in API level 42

Returns the first field of the given type in a class. Might be useful for Proguard'ed classes to identify fields with unique types.

Parameters
clazz The class which either declares or inherits the field.
type The type of the field.
Returns
  • A reference to the first field of the given type.
Throws
NoSuchFieldError In case no matching field was not found.

public static Method findMethodBestMatch (Class<?> clazz, String methodName, Class[]<?> parameterTypes, Object[] args)

Look up a method in a class and set it to accessible.

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 Method findMethodBestMatch (Class<?> clazz, String methodName, Object... args)

Look up a method in a class and set it to accessible.

See findMethodBestMatch(Class, String, Class...) for details. This variant determines the parameter types from the classes of the given objects.

public static Method findMethodBestMatch (Class<?> clazz, String methodName, Class...<?> parameterTypes)

Look up a method in a class and set it to accessible.

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.

Parameters
clazz The class which declares, inherits or overrides the method.
methodName The method name.
parameterTypes The types of the method's parameters.
Returns
  • A reference to the best-matching method.
Throws
NoSuchMethodError In case no suitable method was found.

public static Method findMethodExact (Class<?> clazz, String methodName, Class...<?> parameterTypes)

Look up a method in a class and set it to accessible. See findMethodExact(String, ClassLoader, String, Object...) for details.

This variant requires that you already have reference to all the parameter types.

public static Method findMethodExact (Class<?> clazz, String methodName, Object... parameterTypes)

Look up a method in a class and set it to accessible. See findMethodExact(String, ClassLoader, String, Object...) for details.

public static Method findMethodExact (String className, ClassLoader classLoader, String methodName, Object... parameterTypes)

Look up a method in a class and set it to accessible. The method must be declared or overridden in the given class.

See findAndHookMethod(String, ClassLoader, String, Object...) for details about the method and parameter type resolution.

Parameters
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.
Returns
  • A reference to the method.
Throws
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 Method findMethodExactIfExists (Class<?> clazz, String methodName, Object... parameterTypes)

Added in API level 82

Look up and return a method if it exists. See findMethodExactIfExists(String, ClassLoader, String, Object...) for details.

public static Method findMethodExactIfExists (String className, ClassLoader classLoader, String methodName, Object... parameterTypes)

Added in API level 82

Look up and return a method if it exists. Like findMethodExact(String, ClassLoader, String, Object...), but doesn't throw an exception if the method doesn't exist.

Parameters
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.
Returns
  • A reference to the method, or null if it doesn't exist.

public static Method[] findMethodsByExactParameters (Class<?> clazz, Class<?> returnType, Class...<?> parameterTypes)

Added in API level 36

Returns an array of all methods declared/overridden in a class with the specified parameter types.

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.

Parameters
clazz The class to look in.
returnType The return type, or null (see above).
parameterTypes The parameter types.
Returns
  • An array with matching methods, all set to accessible already.

public static Object getAdditionalInstanceField (Object obj, String key)

Returns a value which was stored with setAdditionalInstanceField(Object, String, Object).

Parameters
obj The object instance for which the value has been stored.
key The key in the value map for this object instance.
Returns
  • The stored value for this instance/key combination, or null if there is none.

public static Object getAdditionalStaticField (Class<?> clazz, String key)

Like setAdditionalInstanceField(Object, String, Object), but the value is returned for clazz.

public static Object getAdditionalStaticField (Object obj, String key)

Like getAdditionalInstanceField(Object, String), but the value is returned for the class of obj.

public static boolean getBooleanField (Object obj, String fieldName)

Returns the value of a boolean field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static byte getByteField (Object obj, String fieldName)

Returns the value of a byte field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static char getCharField (Object obj, String fieldName)

Returns the value of a char field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static Class[]<?> getClassesAsArray (Class...<?> clazzes)

Returns an array of the given classes.

public static double getDoubleField (Object obj, String fieldName)

Returns the value of a double field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static float getFloatField (Object obj, String fieldName)

Returns the value of a float field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static int getIntField (Object obj, String fieldName)

Returns the value of an int field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static long getLongField (Object obj, String fieldName)

Returns the value of a long field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static String getMD5Sum (String file)

Returns the lowercase hex string representation of a file's MD5 hash sum.

Throws
IOException

public static int getMethodDepth (String method)

Added in API level 63

Returns the current depth counter for the given method. See incrementMethodDepth(String) for details.

Parameters
method The method name. Should be prefixed with a unique, module-specific string.
Returns
  • The updated depth.

public static Object getObjectField (Object obj, String fieldName)

Returns the value of an object field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static Class[]<?> getParameterTypes (Object... args)

Returns an array with the classes of the given objects.

public static short getShortField (Object obj, String fieldName)

Returns the value of a short field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static boolean getStaticBooleanField (Class<?> clazz, String fieldName)

Returns the value of a static boolean field in the given class. See also findField(Class, String).

public static byte getStaticByteField (Class<?> clazz, String fieldName)

Sets the value of a static byte field in the given class. See also findField(Class, String).

public static char getStaticCharField (Class<?> clazz, String fieldName)

Sets the value of a static char field in the given class. See also findField(Class, String).

public static double getStaticDoubleField (Class<?> clazz, String fieldName)

Sets the value of a static double field in the given class. See also findField(Class, String).

public static float getStaticFloatField (Class<?> clazz, String fieldName)

Sets the value of a static float field in the given class. See also findField(Class, String).

public static int getStaticIntField (Class<?> clazz, String fieldName)

Sets the value of a static int field in the given class. See also findField(Class, String).

public static long getStaticLongField (Class<?> clazz, String fieldName)

Sets the value of a static long field in the given class. See also findField(Class, String).

public static Object getStaticObjectField (Class<?> clazz, String fieldName)

Returns the value of a static object field in the given class. See also findField(Class, String).

public static short getStaticShortField (Class<?> clazz, String fieldName)

Sets the value of a static short field in the given class. See also findField(Class, String).

public static Object getSurroundingThis (Object obj)

For inner classes, returns the surrounding instance, i.e. the this reference of the surrounding class.

public static int incrementMethodDepth (String method)

Added in API level 63

Increments the depth counter for the given 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(int) variants call each other.

Parameters
method The method name. Should be prefixed with a unique, module-specific string.
Returns
  • The updated depth.

public static Object newInstance (Class<?> clazz, Object... args)

Creates a new instance of the given class. The constructor is resolved using findConstructorBestMatch(Class, Object...).

Parameters
clazz The class reference.
args The arguments for the constructor call.
Throws
NoSuchMethodError In case no suitable constructor was found.
XposedHelpers.InvocationTargetError In case an exception was thrown by the invoked method.
InstantiationError In case the class cannot be instantiated.

public static Object newInstance (Class<?> clazz, Class[]<?> parameterTypes, Object... args)

Creates a new instance of the given class. See 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 Object removeAdditionalInstanceField (Object obj, String key)

Removes and returns a value which was stored with setAdditionalInstanceField(Object, String, Object).

Parameters
obj The object instance for which the value has been stored.
key The key in the value map for this object instance.
Returns
  • The previously stored value for this instance/key combination, or null if there was none.

public static Object removeAdditionalStaticField (Class<?> clazz, String key)

Like setAdditionalInstanceField(Object, String, Object), but the value is removed and returned for clazz.

public static Object removeAdditionalStaticField (Object obj, String key)

Like removeAdditionalInstanceField(Object, String), but the value is removed and returned for the class of obj.

public static Object setAdditionalInstanceField (Object obj, String key, Object value)

Attaches any value to an object instance. This simulates adding an instance field. The value can be retrieved again with getAdditionalInstanceField(Object, String).

Parameters
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.
Returns
  • The previously stored value for this instance/key combination, or null if there was none.

public static Object setAdditionalStaticField (Object obj, String key, Object value)

Like setAdditionalInstanceField(Object, String, Object), but the value is stored for the class of obj.

public static Object setAdditionalStaticField (Class<?> clazz, String key, Object value)

Like setAdditionalInstanceField(Object, String, Object), but the value is stored for clazz.

public static void setBooleanField (Object obj, String fieldName, boolean value)

Sets the value of a boolean field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setByteField (Object obj, String fieldName, byte value)

Sets the value of a byte field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setCharField (Object obj, String fieldName, char value)

Sets the value of a char field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setDoubleField (Object obj, String fieldName, double value)

Sets the value of a double field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setFloatField (Object obj, String fieldName, float value)

Sets the value of a float field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setIntField (Object obj, String fieldName, int value)

Sets the value of an int field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setLongField (Object obj, String fieldName, long value)

Sets the value of a long field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setObjectField (Object obj, String fieldName, Object value)

Sets the value of an object field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setShortField (Object obj, String fieldName, short value)

Sets the value of a short field in the given object instance. A class reference is not sufficient! See also findField(Class, String).

public static void setStaticBooleanField (Class<?> clazz, String fieldName, boolean value)

Sets the value of a static boolean field in the given class. See also findField(Class, String).

public static void setStaticByteField (Class<?> clazz, String fieldName, byte value)

Sets the value of a static byte field in the given class. See also findField(Class, String).

public static void setStaticCharField (Class<?> clazz, String fieldName, char value)

Sets the value of a static char field in the given class. See also findField(Class, String).

public static void setStaticDoubleField (Class<?> clazz, String fieldName, double value)

Sets the value of a static double field in the given class. See also findField(Class, String).

public static void setStaticFloatField (Class<?> clazz, String fieldName, float value)

Sets the value of a static float field in the given class. See also findField(Class, String).

public static void setStaticIntField (Class<?> clazz, String fieldName, int value)

Sets the value of a static int field in the given class. See also findField(Class, String).

public static void setStaticLongField (Class<?> clazz, String fieldName, long value)

Sets the value of a static long field in the given class. See also findField(Class, String).

public static void setStaticObjectField (Class<?> clazz, String fieldName, Object value)

Sets the value of a static object field in the given class. See also findField(Class, String).

public static void setStaticShortField (Class<?> clazz, String fieldName, short value)

Sets the value of a static short field in the given class. See also findField(Class, String).