java.lang.Object | |
↳ | de.robv.android.xposed.XposedHelpers |
Helpers that simplify hooking and calling methods/constructors, getting and settings fields, ...
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
XposedHelpers.ClassNotFoundError | Thrown when a class loader is unable to find a class. | ||||||||||
XposedHelpers.InvocationTargetError | This class provides a wrapper for an exception thrown by a method invocation. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Loads an asset from a resource object and returns the content as
byte array.
| |||||||||||
Calls an instance or static method of the given object.
| |||||||||||
Calls an instance or static method of the given object.
| |||||||||||
Calls a static method of the given class.
| |||||||||||
Calls a static method of the given class.
| |||||||||||
Decrements the depth counter for the given method.
| |||||||||||
Look up a constructor and hook it.
| |||||||||||
Look up a constructor and hook it.
| |||||||||||
Look up a method and hook it.
| |||||||||||
Look up a method and hook it.
| |||||||||||
Look up a class with the specified class loader.
| |||||||||||
Look up and return a class if it exists.
| |||||||||||
Look up a constructor in a class and set it to accessible.
| |||||||||||
Look up a constructor in a class and set it to accessible.
| |||||||||||
Look up a constructor in a class and set it to accessible.
| |||||||||||
Look up a constructor of a class and set it to accessible.
| |||||||||||
Look up a constructor of a class and set it to accessible.
| |||||||||||
Look up a constructor of a class and set it to accessible.
| |||||||||||
Look up and return a constructor if it exists.
| |||||||||||
Look up and return a constructor if it exists.
| |||||||||||
Look up a field in a class and set it to accessible.
| |||||||||||
Look up and return a field if it exists.
| |||||||||||
Returns the first field of the given type in a class.
| |||||||||||
Look up a method in a class and set it to accessible.
| |||||||||||
Look up a method in a class and set it to accessible.
| |||||||||||
Look up a method in a class and set it to accessible.
| |||||||||||
Look up a method in a class and set it to accessible.
| |||||||||||
Look up a method in a class and set it to accessible.
| |||||||||||
Look up a method in a class and set it to accessible.
| |||||||||||
Look up and return a method if it exists.
| |||||||||||
Look up and return a method if it exists.
| |||||||||||
Returns an array of all methods declared/overridden in a class with the specified parameter types.
| |||||||||||
Returns a value which was stored with
setAdditionalInstanceField(Object, String, Object) .
| |||||||||||
Like
setAdditionalInstanceField(Object, String, Object) , but the value is returned for clazz .
| |||||||||||
Like
getAdditionalInstanceField(Object, String) , but the value is returned for the class of obj .
| |||||||||||
Returns the value of a
boolean field in the given object instance.
| |||||||||||
Returns the value of a
byte field in the given object instance.
| |||||||||||
Returns the value of a
char field in the given object instance.
| |||||||||||
Returns an array of the given classes.
| |||||||||||
Returns the value of a
double field in the given object instance.
| |||||||||||
Returns the value of a
float field in the given object instance.
| |||||||||||
Returns the value of an
int field in the given object instance.
| |||||||||||
Returns the value of a
long field in the given object instance.
| |||||||||||
Returns the lowercase hex string representation of a file's MD5 hash sum.
| |||||||||||
Returns the current depth counter for the given method.
| |||||||||||
Returns the value of an object field in the given object instance.
| |||||||||||
Returns an array with the classes of the given objects.
| |||||||||||
Returns the value of a
short field in the given object instance.
| |||||||||||
Returns the value of a static
boolean field in the given class.
| |||||||||||
Sets the value of a static
byte field in the given class.
| |||||||||||
Sets the value of a static
char field in the given class.
| |||||||||||
Sets the value of a static
double field in the given class.
| |||||||||||
Sets the value of a static
float field in the given class.
| |||||||||||
Sets the value of a static
int field in the given class.
| |||||||||||
Sets the value of a static
long field in the given class.
| |||||||||||
Returns the value of a static object field in the given class.
| |||||||||||
Sets the value of a static
short field in the given class.
| |||||||||||
For inner classes, returns the surrounding instance, i.e.
| |||||||||||
Increments the depth counter for the given method.
| |||||||||||
Creates a new instance of the given class.
| |||||||||||
Creates a new instance of the given class.
| |||||||||||
Removes and returns a value which was stored with
setAdditionalInstanceField(Object, String, Object) .
| |||||||||||
Like
setAdditionalInstanceField(Object, String, Object) , but the value is removed and returned for clazz .
| |||||||||||
Like
removeAdditionalInstanceField(Object, String) , but the value is removed and returned for the class of obj .
| |||||||||||
Attaches any value to an object instance.
| |||||||||||
Like
setAdditionalInstanceField(Object, String, Object) , but the value is stored for the class of obj .
| |||||||||||
Like
setAdditionalInstanceField(Object, String, Object) , but the value is stored for clazz .
| |||||||||||
Sets the value of a
boolean field in the given object instance.
| |||||||||||
Sets the value of a
byte field in the given object instance.
| |||||||||||
Sets the value of a
char field in the given object instance.
| |||||||||||
Sets the value of a
double field in the given object instance.
| |||||||||||
Sets the value of a
float field in the given object instance.
| |||||||||||
Sets the value of an
int field in the given object instance.
| |||||||||||
Sets the value of a
long field in the given object instance.
| |||||||||||
Sets the value of an object field in the given object instance.
| |||||||||||
Sets the value of a
short field in the given object instance.
| |||||||||||
Sets the value of a static
boolean field in the given class.
| |||||||||||
Sets the value of a static
byte field in the given class.
| |||||||||||
Sets the value of a static
char field in the given class.
| |||||||||||
Sets the value of a static
double field in the given class.
| |||||||||||
Sets the value of a static
float field in the given class.
| |||||||||||
Sets the value of a static
int field in the given class.
| |||||||||||
Sets the value of a static
long field in the given class.
| |||||||||||
Sets the value of a static object field in the given class.
| |||||||||||
Sets the value of a static
short field in the given class.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Loads an asset from a resource object and returns the content as byte
array.
res | The resources from which the asset should be loaded. |
---|---|
path | The path to the asset, as in AssetManager.open(String) . |
IOException |
---|
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.
Calls an instance or static method of the given object.
The method is resolved using 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. |
NoSuchMethodError | In case no suitable method was found. |
---|---|
XposedHelpers.InvocationTargetError | In case an exception was thrown by the invoked method. |
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.
Calls a static method of the given class.
The method is resolved using findMethodBestMatch(Class, String, Object...)
.
clazz | The class reference. |
---|---|
methodName | The method name. |
args | The arguments for the method call. |
NoSuchMethodError | In case no suitable method was found. |
---|---|
XposedHelpers.InvocationTargetError | In case an exception was thrown by the invoked method. |
Decrements the depth counter for the given method.
See incrementMethodDepth(String)
for details.
method | The method name. Should be prefixed with a unique, module-specific string. |
---|
Look up a constructor and hook it. See findAndHookMethod(String, ClassLoader, String, Object...)
for details.
Look up a constructor and hook it. See findAndHookMethod(String, ClassLoader, String, Object...)
for details.
Look up a method and hook it. See findAndHookMethod(String, ClassLoader, String, Object...)
for details.
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; } });
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. |
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. |
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
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. |
---|
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.
className | The class name. |
---|---|
classLoader | The class loader, or null for the boot class loader. |
null
if it doesn't exist.
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.
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.
Look up a constructor in a class and set it to accessible.
See findMethodBestMatch(Class, String, Class...)
for details.
Look up a constructor of a class and set it to accessible.
See findMethodExact(String, ClassLoader, String, Object...)
for details.
Look up a constructor of a class and set it to accessible.
See findMethodExact(String, ClassLoader, String, Object...)
for details.
Look up a constructor of a class and set it to accessible.
See findMethodExact(String, ClassLoader, String, Object...)
for details.
Look up and return a constructor if it exists.
See findMethodExactIfExists(String, ClassLoader, String, Object...)
for details.
Look up and return a constructor if it exists.
See findMethodExactIfExists(String, ClassLoader, String, Object...)
for details.
Look up a field in a class and set it to accessible.
clazz | The class which either declares or inherits the field. |
---|---|
fieldName | The field name. |
NoSuchFieldError | In case the field was not found. |
---|
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.
clazz | The class which either declares or inherits the field. |
---|---|
fieldName | The field name. |
null
if it doesn't exist.
Returns the first field of the given type in a class. Might be useful for Proguard'ed classes to identify fields with unique types.
clazz | The class which either declares or inherits the field. |
---|---|
type | The type of the field. |
NoSuchFieldError | In case no matching field was not found. |
---|
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.
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.
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.
clazz | The class which declares, inherits or overrides the method. |
---|---|
methodName | The method name. |
parameterTypes | The types of the method's parameters. |
NoSuchMethodError | In case no suitable method was found. |
---|
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.
Look up a method in a class and set it to accessible.
See findMethodExact(String, ClassLoader, String, Object...)
for details.
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.
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. |
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. |
Look up and return a method if it exists.
See findMethodExactIfExists(String, ClassLoader, String, Object...)
for details.
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.
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.
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.
clazz | The class to look in. |
---|---|
returnType | The return type, or null (see above). |
parameterTypes | The parameter types. |
Returns a value which was stored with setAdditionalInstanceField(Object, String, 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.
Like setAdditionalInstanceField(Object, String, Object)
, but the value is returned for clazz
.
Like getAdditionalInstanceField(Object, String)
, but the value is returned for the class of obj
.
Returns the value of a boolean
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the value of a byte
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the value of a char
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns an array of the given classes.
Returns the value of a double
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the value of a float
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the value of an int
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the value of a long
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the lowercase hex string representation of a file's MD5 hash sum.
IOException |
---|
Returns the current depth counter for the given method.
See incrementMethodDepth(String)
for details.
method | The method name. Should be prefixed with a unique, module-specific string. |
---|
Returns the value of an object field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns an array with the classes of the given objects.
Returns the value of a short
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Returns the value of a static boolean
field in the given class. See also findField(Class>, String)
.
Sets the value of a static byte
field in the given class. See also findField(Class>, String)
.
Sets the value of a static char
field in the given class. See also findField(Class>, String)
.
Sets the value of a static double
field in the given class. See also findField(Class>, String)
.
Sets the value of a static float
field in the given class. See also findField(Class>, String)
.
Sets the value of a static int
field in the given class. See also findField(Class>, String)
.
Sets the value of a static long
field in the given class. See also findField(Class>, String)
.
Returns the value of a static object field in the given class. See also findField(Class>, String)
.
Sets the value of a static short
field in the given class. See also findField(Class>, String)
.
For inner classes, returns the surrounding instance, i.e. the this
reference of the surrounding class.
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.
method | The method name. Should be prefixed with a unique, module-specific string. |
---|
Creates a new instance of the given class.
The constructor is resolved using findConstructorBestMatch(Class, Object...)
.
clazz | The class reference. |
---|---|
args | The arguments for the constructor call. |
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. |
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.
Removes and returns a value which was stored with setAdditionalInstanceField(Object, String, 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.
Like setAdditionalInstanceField(Object, String, Object)
, but the value is removed and returned for clazz
.
Like removeAdditionalInstanceField(Object, String)
, but the value is removed and returned for the class of obj
.
Attaches any value to an object instance. This simulates adding an instance field.
The value can be retrieved again with getAdditionalInstanceField(Object, 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.
Like setAdditionalInstanceField(Object, String, Object)
, but the value is stored for the class of obj
.
Like setAdditionalInstanceField(Object, String, Object)
, but the value is stored for clazz
.
Sets the value of a boolean
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a byte
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a char
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a double
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a float
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of an int
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a long
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of an object field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a short
field in the given object instance. A class reference is not sufficient! See also findField(Class>, String)
.
Sets the value of a static boolean
field in the given class. See also findField(Class>, String)
.
Sets the value of a static byte
field in the given class. See also findField(Class>, String)
.
Sets the value of a static char
field in the given class. See also findField(Class>, String)
.
Sets the value of a static double
field in the given class. See also findField(Class>, String)
.
Sets the value of a static float
field in the given class. See also findField(Class>, String)
.
Sets the value of a static int
field in the given class. See also findField(Class>, String)
.
Sets the value of a static long
field in the given class. See also findField(Class>, String)
.
Sets the value of a static object field in the given class. See also findField(Class>, String)
.
Sets the value of a static short
field in the given class. See also findField(Class>, String)
.