Hook Utilities (Reflection)
A set of utility functions for performing Java reflection, allowing you to find classes and access or modify private fields and methods.
The hook_utils.py
module provides essential tools for interacting with the underlying Java code of the application via reflection. This is particularly useful for advanced Xposed hooking when you need to access non-public members of a class.
Use with Caution
Reflection is a powerful but fragile technique. It can break if the underlying application code changes. Always include error handling (e.g., try-except
blocks) when using these functions and check for None
return values.
find_class(class_name: str)
Safely finds and returns a Java class object by its fully qualified name.
class_name
: The full name of the class, including the package (e.g.,"org.telegram.ui.ActionBar.ActionBar"
).- Returns: A Java
Class
object if found, otherwiseNone
.
Example
get_private_field(obj: JavaObject, field_name: str)
Accesses and retrieves the value of a private (or public) instance field from a given object. It searches the entire class hierarchy.
obj
: The Java object instance from which to get the field.field_name
: The name of the field to access.- Returns: The value of the field if found, otherwise
None
.
Example
Assuming chatActivity
is an instance of org.telegram.ui.ChatActivity
.
set_private_field(obj: JavaObject, field_name: str, new_value: Any)
Modifies the value of a private (or public) instance field on a given object.
obj
: The Java object instance to modify.field_name
: The name of the field to modify.new_value
: The new value to assign to the field.- Returns:
True
if the field was set successfully,False
otherwise.
Example
get_static_private_field(clazz: JavaClass, field_name: str)
Accesses and retrieves the value of a static
private (or public) field from a given class.
clazz
: The JavaClass
object.field_name
: The name of the static field.- Returns: The value of the field if found, otherwise
None
.
Example
set_static_private_field(clazz: JavaClass, field_name: str, new_value: Any)
Modifies the value of a static
private (or public) field on a given class.
clazz
: The JavaClass
object.field_name
: The name of the static field to modify.new_value
: The new value to assign.- Returns:
True
if successful,False
otherwise.