Xposed Method Hooking
Hook Java methods and constructors from Python plugins using MethodHook, MethodReplacement, BaseHook, and filters.
Introduction
Xposed-style method hooking lets your plugin intercept method calls inside the app, modify arguments, inspect or replace return values, or skip the original implementation entirely.
This is one of the most powerful parts of the plugin SDK, and also one of the easiest to misuse, so it is worth being explicit about the available styles.
Hook Handler Styles
You can provide hook logic in three ways.
1. MethodHook
Use MethodHook when you want before_hooked_method(...) and/or after_hooked_method(...).
2. MethodReplacement
Use MethodReplacement when you want to fully replace the original Java method.
3. Functional hooks or BaseHook
For simpler cases, you can skip creating a full class and pass before= and/or after= directly:
Internally the SDK wraps that style into BaseHook, which is a small helper subclass of MethodHook.
The param Object
All hook callbacks receive de.robv.android.xposed.XC_MethodHook.MethodHookParam.
The most useful fields and methods are:
param.thisObject: instance on which the method was called, orNonefor static methodsparam.args: method argument array; you can read and modify itparam.method: the hookedMethodorConstructorparam.getResult(): return value of the original method, available after executionparam.setResult(value): sets a result manually
If you call param.setResult(...) inside before_hooked_method(...), the original method is skipped.
Filters
Filters decide whether your hook callback should run at all.
You can use them in two styles:
@hook_filters(...)on class-based hook methodsbefore_filters=[...]andafter_filters=[...]for functional hooks
Available HookFilter helpers
HookFilter.RESULT_IS_NULLHookFilter.RESULT_IS_TRUEHookFilter.RESULT_IS_FALSEHookFilter.RESULT_NOT_NULLHookFilter.ResultIsInstanceOf(clazz)HookFilter.ResultEqual(value)HookFilter.ResultNotEqual(value)HookFilter.ArgumentIsNull(index)HookFilter.ArgumentNotNull(index)HookFilter.ArgumentIsFalse(index)HookFilter.ArgumentIsTrue(index)HookFilter.ArgumentIsInstanceOf(index, clazz)HookFilter.ArgumentEqual(index, value)HookFilter.ArgumentNotEqual(index, value)HookFilter.Condition(condition, object=None)HookFilter.Or(*filters)
Class-based filter example
MVEL condition filter example
The Hooking Process
1. Find the target method or constructor
You usually start with find_class(...), then call Java reflection directly on the returned Class.
Do not call `getClass()` on the `Class` object
find_class(...) already returns a Java Class. Call getDeclaredMethod(...)
or getDeclaredConstructor(...) on that object directly.
2. Implement the hook handler
3. Apply the hook
Hooks are removed automatically when your plugin unloads, but you can also unhook manually.
4. Hook all methods or all constructors
Or:
5. Manual unhooking
If you used hook_all_methods(...) or hook_all_constructors(...), iterate over the returned list and unhook each item.
Practical Examples
Example 1: modify arguments before the call
Example 2: change the return value after the call
Example 3: skip the original call in before_hooked_method
Example 4: fully replace a method
Return values in `MethodReplacement`
Your replace_hooked_method(...) becomes the whole implementation.
Return a value compatible with the original Java method:
Noneforvoid- Python
bool/int/floatfor primitive Java returns - compatible Java or Python object for reference returns