### Basic Hook Installation Example Source: https://github.com/libxposed/api/blob/master/_autodocs/COMPLETION_REPORT.txt Demonstrates the fundamental process of installing a hook using the Xposed API. This is a starting point for intercepting method calls. ```java package io.github.libxposed.api.examples; import io.github.libxposed.api.XposedHook; import io.github.libxposed.api.XposedInterface; public class BasicHookExample implements XposedHook { @Override public void hook(XposedInterface xposed) { // Example: Hooking a method in a target app xposed.hookMethod( "com.example.targetapp.ClassName", // Target class name "methodName", // Target method name (params) -> { // Code to execute before the original method xposed.log("Method called!"); return null; // Return null to proceed with original method } ); } } ``` -------------------------------- ### Configuration Setup Example Source: https://github.com/libxposed/api/blob/master/_autodocs/COMPLETION_REPORT.txt Demonstrates how to set up and retrieve configuration options for an Xposed module. This allows modules to be customized by users or other modules. ```java package io.github.libxposed.api.examples; import io.github.libxposed.api.XposedHook; import io.github.libxposed.api.XposedInterface; public class ConfigurationExample implements XposedHook { @Override public void hook(XposedInterface xposed) { // Example: Setting a configuration value xposed.setConfiguration("my_module.feature_enabled", true); xposed.setConfiguration("my_module.timeout_ms", 5000); // Example: Retrieving a configuration value boolean featureEnabled = xposed.getConfiguration("my_module.feature_enabled", false); int timeout = xposed.getConfiguration("my_module.timeout_ms", 3000); if (featureEnabled) { xposed.log("Feature is enabled with timeout: " + timeout + "ms"); // ... enable feature logic ... } } } ``` -------------------------------- ### SystemServerStartingParam Example Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Provides an example of using SystemServerStartingParam to get the system server's classloader and hook system services like ActivityManagerService. ```java @NonNull ClassLoader getClassLoader(); ``` ```java @Override public void onSystemServerStarting(SystemServerStartingParam param) { ClassLoader loader = param.getClassLoader(); try { Class amsClass = loader.loadClass("com.android.server.am.ActivityManagerService"); // Hook system services } catch (ClassNotFoundException e) { log(Log.ERROR, TAG, "AMS not found", e); } } ``` -------------------------------- ### Example module.prop Configuration Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md A complete example of a module.prop file, including metadata, scope, exception handling, and hot reload settings. ```properties # Module metadata minApiVersion=102 targetApiVersion=102 # Module scope configuration staticScope=true # Exception handling exceptionMode=protective # Hot reload support (API 102+) autoHotReload=true ``` -------------------------------- ### Detach Example: After All Setup Complete Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Example showing the use of detach() after all module setup is complete, to stop receiving further lifecycle callbacks. ```java @Override public void onPackageReady(PackageReadyParam param) { // After all setup complete, can stop listening detach(); } ``` -------------------------------- ### Hot Reload Configuration Example Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Example demonstrating `module.prop` settings and XposedModule implementation for hot reloading. Includes `onHotReloading` to save state and `onHotReloaded` to replace hooks. ```properties minApiVersion=102 targetApiVersion=102 autoHotReload=true exceptionMode=protective ``` ```java public class MyModule extends XposedModule { private static final String TAG = "MyModule"; private HookHandle hookHandle; @Override public void onModuleLoaded(ModuleLoadedParam param) { // Initial setup only } @Override public void onPackageLoaded(PackageLoadedParam param) { if ("com.example.target".equals(param.getPackageName())) { hookTarget(param); } } private void hookTarget(PackageLoadedParam param) { try { Class targetClass = param.getDefaultClassLoader() .loadClass("com.example.target.MyClass"); Method targetMethod = targetClass.getDeclaredMethod("doSomething"); hookHandle = hook(targetMethod) .intercept(chain -> { log(Log.INFO, TAG, "Method called"); return chain.proceed(); }); } catch (Exception e) { log(Log.ERROR, TAG, "Hook failed", e); } } @Override public boolean onHotReloading(HotReloadingParam param) { // Prepare for reload — save state Bundle state = new Bundle(); state.putString("lastState", "active"); param.setSavedInstanceState(state); // Stop operations cleanupResources(); return true; // Allow reload } @Override public void onHotReloaded(HotReloadedParam param) { // Restore state Bundle state = (Bundle) param.getSavedInstanceState(); if (state != null) { String lastState = state.getString("lastState"); } // Replace old hooks with new implementation for (HookHandle oldHandle : param.getOldHookHandles()) { oldHandle.replaceHook(chain -> { log(Log.INFO, TAG, "Method called (after reload)"); return chain.proceed(); }); } } private void cleanupResources() { // Stop threads, unregister callbacks, etc. } } ``` -------------------------------- ### PackageLoadedParam Example Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Shows how to use PackageLoadedParam to get the package name, application info, and default classloader. It includes an example of loading a class from the target package. ```java @NonNull String getPackageName(); ``` ```java @NonNull ApplicationInfo getApplicationInfo(); ``` ```java boolean isFirstPackage(); ``` ```java @RequiresApi(Build.VERSION_CODES.Q) @NonNull ClassLoader getDefaultClassLoader(); ``` ```java @Override public void onPackageLoaded(PackageLoadedParam param) { String packageName = param.getPackageName(); if ("com.example.target".equals(packageName)) { ClassLoader loader = param.getDefaultClassLoader(); try { Class targetClass = loader.loadClass("com.example.target.MyClass"); // Hook at this point } catch (ClassNotFoundException e) { log(Log.WARN, TAG, "Class not found", e); } } } ``` -------------------------------- ### PackageReadyParam Example Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Illustrates using PackageReadyParam to obtain the package's classloader and AppComponentFactory. The example demonstrates loading an Activity class. ```java @NonNull ClassLoader getClassLoader(); ``` ```java @RequiresApi(Build.VERSION_CODES.P) @NonNull AppComponentFactory getAppComponentFactory(); ``` ```java @Override public void onPackageReady(PackageReadyParam param) { String packageName = param.getPackageName(); ClassLoader loader = param.getClassLoader(); // May differ from default try { Class activityClass = loader.loadClass("com.example.target.MainActivity"); // Hook activities now } catch (ClassNotFoundException e) { log(Log.WARN, TAG, "Activity not found", e); } } ``` -------------------------------- ### HookBuilder Fluent Usage Example Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md Demonstrates the fluent builder pattern for installing a hook using HookBuilder. This example sets priority and exception mode before intercepting the hooker. ```java HookHandle handle = hook(method) .setPriority(PRIORITY_DEFAULT) .setExceptionMode(ExceptionMode.PROTECTIVE) .intercept(hooker); ``` -------------------------------- ### Detach Example: Target App Initialization Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Example demonstrating how to use detach() when the module has finished its initialization for a specific target application. ```java @Override public void onPackageLoaded(PackageLoadedParam param) { if ("com.example.target".equals(param.getPackageName())) { // This is our target app, continue setup initializeHooks(); } else { // Not our target, stop receiving callbacks detach(); } } ``` -------------------------------- ### Scope Configuration Example Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Defines package names for which the module should be active in scope.list. ```text com.example.target.app1 com.example.target.app2 system android ``` -------------------------------- ### Handling HookFailedError during Hook Installation Source: https://github.com/libxposed/api/blob/master/_autodocs/errors.md Example of catching HookFailedError when attempting to hook a framework internal method. This indicates a failure in the hook installation process. ```java try { // Attempting to hook framework internal method hook(somethingInternalMethod) .intercept(hooker); // May throw } catch (HookFailedError e) { log(Log.ERROR, TAG, "Cannot hook: " + e.getMessage()); } ``` -------------------------------- ### Install Basic Hook Source: https://github.com/libxposed/api/blob/master/_autodocs/INDEX.md Installs a basic hook on a target method within a specific package. Includes pre- and post-processing logic. Ensure necessary imports and exception handling are in place. ```java @Override public void onPackageLoaded(PackageLoadedParam param) { if ("com.example.target".equals(param.getPackageName())) { try { Class targetClass = param.getDefaultClassLoader() .loadClass("com.example.target.MyClass"); Method targetMethod = targetClass.getDeclaredMethod("doSomething"); HookHandle handle = hook(targetMethod) .setPriority(PRIORITY_DEFAULT) .setExceptionMode(ExceptionMode.PROTECTIVE) .intercept(chain -> { // Pre-processing Object result = chain.proceed(); // Post-processing return result; }); } catch (Exception e) { log(Log.ERROR, "MyModule", "Hook failed", e); } } } ``` -------------------------------- ### SystemServerStartingParam Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md Provides information about the system server process when it is starting. ```APIDOC ## SystemServerStartingParam Information about system server. Located in `XposedModuleInterface.SystemServerStartingParam`. ### Methods: | Name | Parameters | Return Type | Description | |------|-----------|------------|-------------| | getClassLoader | — | ClassLoader | System server classloader | **Used By:** - Parameter to `XposedModuleInterface.onSystemServerStarting(SystemServerStartingParam)` ``` -------------------------------- ### Example: Initializing Module State on Load Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Shows how to initialize module-global state or determine app-specific hooks based on the process name when the module is loaded. ```java @Override public void onModuleLoaded(ModuleLoadedParam param) { String processName = param.getProcessName(); if ("com.example.target:secure".equals(processName)) { initializeHooks(); } } ``` -------------------------------- ### Java Entry Registration Example Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModule.md Specifies the fully-qualified class name of the Xposed module's entry point in the java_init.list file. ```plaintext com.example.mymodule.MyXposedModule ``` -------------------------------- ### Example: Handling Hot Reloading Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Demonstrates saving state and cleaning up resources before a hot reload. Returns true to allow the reload. ```java @Override public boolean onHotReloading(HotReloadingParam param) { Bundle extras = param.getExtras(); // Save state (only classloader-neutral values) Bundle savedState = new Bundle(); savedState.putString("config_key", "config_value"); savedState.putLong("timestamp", System.currentTimeMillis()); param.setSavedInstanceState(savedState); // Stop threads, unregister callbacks, release resources cleanup(); return true; // Allow reload } ``` -------------------------------- ### onSystemServerStarting Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Called when the system server is ready to start critical services. This method replaces the first callback phases of onPackageLoaded() and onPackageReady() specifically within the system server context. ```APIDOC ## onSystemServerStarting(SystemServerStartingParam param) ### Description Called when system server ready to start critical services. Replaces first callback phase of `onPackageLoaded()` and `onPackageReady()` in system server. ### Method Signature ```java default void onSystemServerStarting(@NonNull SystemServerStartingParam param) { } ``` ### Parameters #### Path Parameters - **param** (SystemServerStartingParam) - Required - Information about system server ### Throws `RuntimeException` – All exceptions caught and logged by framework. ### Use Cases - Hook system services (ActivityManager, PackageManager, etc.) - Patch system server behavior ### Example ```java @Override public void onSystemServerStarting(SystemServerStartingParam param) { ClassLoader loader = param.getClassLoader(); try { Class amsClass = loader.loadClass("com.android.server.am.ActivityManagerService"); Method startMethod = amsClass.getDeclaredMethod("start"); hook(startMethod) .intercept(chain -> { log(Log.INFO, TAG, "AMS.start called"); return chain.proceed(); }); } catch (Exception e) { log(Log.ERROR, TAG, "Failed to hook AMS", e); } } ``` ``` -------------------------------- ### ModuleLoadedParam Example Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Demonstrates how to use ModuleLoadedParam to check if the module is loaded into the system server or to identify the current process name. ```java boolean isSystemServer(); ``` ```java @NonNull String getProcessName(); ``` ```java @Override public void onModuleLoaded(ModuleLoadedParam param) { if (param.isSystemServer()) { // Handle system server } else { String processName = param.getProcessName(); if ("com.example.target".equals(processName)) { // Handle target app } } } ``` -------------------------------- ### Example: Handling Hot Reloaded Event Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Demonstrates restoring configuration from saved state and replacing old hooks with new implementations after a hot reload. ```java @Override public void onHotReloaded(HotReloadedParam param) { Bundle savedState = (Bundle) param.getSavedInstanceState(); if (savedState != null) { String config = savedState.getString("config_key"); // Restore configuration } // Replace old hooks with new implementations for (HookHandle oldHandle : param.getOldHookHandles()) { oldHandle.replaceHook(newHooker); } // Resume threads, re-register callbacks resume(); } ``` -------------------------------- ### Get Framework Version Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves the version string of the framework implementation. ```java @NonNull String getFrameworkVersion(); ``` -------------------------------- ### Logging Hook Installation Failures Source: https://github.com/libxposed/api/blob/master/_autodocs/errors.md Use this method to handle and log `HookFailedError` exceptions, which occur when a hook fails to install. This typically means a module feature cannot be used, and the error should be logged with the exception object. ```java void handleHookError(HookFailedError e) { log(Log.ERROR, "MyModule", "Hook installation failed: " + e.getMessage(), e); // Cannot proceed with this module feature } ``` -------------------------------- ### Get Framework Name Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves the name of the framework implementation. ```java @NonNull String getFrameworkName(); ``` -------------------------------- ### Basic Gradle Setup for Xposed API Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md This Gradle configuration demonstrates how to include the Xposed API as a `compileOnly` dependency in your Android project. This ensures the API is available at compile time without being bundled into the final APK. ```gradle plugins { id 'com.android.application' } android { compileSdk 37 defaultConfig { applicationId "com.example.mymodule" minSdk 26 targetSdk 37 } } dependencies { compileOnly("io.github.libxposed:api:102.0.0") } ``` -------------------------------- ### HookBuilder Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md A builder interface for configuring hooks before they are installed. It allows setting priority, exception mode, and an optional ID, and finally installing the hook. ```APIDOC ## Interface HookBuilder ### Description Builder for configuring hooks before installation. ### Methods #### setPriority - **Description**: Set hook priority - **Parameters**: - **priority** (int) - Description: The priority level for the hook - **Return Type**: HookBuilder #### setExceptionMode - **Description**: Set exception handling mode for the hook - **Parameters**: - **mode** (ExceptionMode) - Description: The exception mode to apply - **Return Type**: HookBuilder #### setId - **Description**: Set hook ID (API 102+) - **Parameters**: - **id** (String) - Description: The unique identifier for the hook - **Return Type**: HookBuilder #### intercept - **Description**: Install the configured hook. - **Parameters**: - **hooker** (Hooker) - Description: The hook implementation - **Return Type**: HookHandle - **Throws**: IllegalArgumentException, HookFailedError ``` -------------------------------- ### onModuleLoaded Callback Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Callback invoked once when a module generation loads into a target process. Used for initial setup and configuration. ```APIDOC ## Lifecycle Callbacks ### onModuleLoaded(ModuleLoadedParam param) Called once when module generation loads into target process. This callback replayed on initial load but not on hot reload. ```java default void onModuleLoaded(@NonNull ModuleLoadedParam param) { } ``` | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | param | ModuleLoadedParam | Yes | Information about the process | **Throws:** `RuntimeException` – All exceptions caught and logged by framework. #### Use Cases - Verify this module is loaded in correct process - Initialize module-global state (only on initial load) - Determine app-specific hooks or configuration #### Example ```java @Override public void onModuleLoaded(ModuleLoadedParam param) { String processName = param.getProcessName(); if ("com.example.target:secure".equals(processName)) { initializeHooks(); } } ``` ``` -------------------------------- ### Get Framework Version Code Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves the version code of the framework implementation. ```java long getFrameworkVersionCode(); ``` -------------------------------- ### Module Filtering in Callbacks Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Example of how a module should filter package names within callbacks to ensure it only acts on target packages. ```java @Override public void onPackageLoaded(PackageLoadedParam param) { // Module must filter — may receive callbacks for unscoped packages if ("com.example.target".equals(param.getPackageName())) { // This is our target package hookPackage(param); } else { // Not our target, ignore or detach detach(); } } ``` -------------------------------- ### SystemServerStartingParam Interface Definition Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md Provides information specifically for when the system server is starting. It includes a method to retrieve the system server's classloader. ```java interface SystemServerStartingParam { @NonNull ClassLoader getClassLoader(); } ``` -------------------------------- ### Hooking System Server Initialization Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Called when the system server is ready to start critical services. Use this to hook system services like ActivityManagerService. Exceptions during hooking are caught and logged. ```java @Override public void onSystemServerStarting(SystemServerStartingParam param) { ClassLoader loader = param.getClassLoader(); try { Class amsClass = loader.loadClass("com.android.server.am.ActivityManagerService"); Method startMethod = amsClass.getDeclaredMethod("start"); hook(startMethod) .intercept(chain -> { log(Log.INFO, TAG, "AMS.start called"); return chain.proceed(); }); } catch (Exception e) { log(Log.ERROR, TAG, "Failed to hook AMS", e); } } ``` -------------------------------- ### Get Module Application Info Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Retrieves the ApplicationInfo object for the current module. This can be used to access metadata about the module itself. ```java @NonNull @Override public final ApplicationInfo getModuleApplicationInfo() ``` -------------------------------- ### Hooker Implementation Pattern Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md A common pattern for implementing the Hooker interface using a lambda expression. This example shows a basic implementation that proceeds with the chain and returns the result. ```java Hooker hooker = chain -> { Object result = chain.proceed(); return result; }; ``` -------------------------------- ### Get Framework Properties Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves framework property flags. Note that properties with the prefix `PROP_RT_` may change between launches. ```java long getFrameworkProperties(); ``` -------------------------------- ### Custom onHotReloaded for Hook Management Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md An example of a custom onHotReloaded implementation that restores state, selectively replaces or unhooks old hooks, and resumes operations. This is useful for managing module updates atomically. ```java @Override public void onHotReloaded(HotReloadedParam param) { // Restore state Bundle savedState = (Bundle) param.getSavedInstanceState(); if (savedState != null) { restoreConfig(savedState.getString("config")); } // Replace old hooks for (HookHandle oldHandle : param.getOldHookHandles()) { if (shouldKeepHook(oldHandle)) { oldHandle.replaceHook(newHooker); } else { oldHandle.unhook(); } } // Resume operations resumeWorkerThreads(); reregisterCallbacks(); } ``` -------------------------------- ### Accessing Framework Methods in XposedModule Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModule.md Demonstrates direct access to framework methods like logging and hooking from an XposedModule instance. ```java public void someMethod() { // this is an instance of XposedModule // Call framework methods directly log(Log.INFO, TAG, "Log message"); HookHandle handle = hook(targetMethod) .setPriority(PRIORITY_DEFAULT) .intercept(hooker); } ``` -------------------------------- ### Typical XposedModule Implementation Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModule.md A common implementation pattern for an Xposed module, demonstrating how to override lifecycle callbacks like onModuleLoaded and onPackageLoaded to register hooks and perform actions based on the process or package name. ```java public class MyXposedModule extends XposedModule { private static final String TAG = "MyModule"; @Override public void onModuleLoaded(ModuleLoadedParam param) { // Verify process if (param.isSystemServer()) { hookSystemServices(); } else if ("com.example.target".equals(param.getProcessName())) { hookTargetApp(); } } @Override public void onPackageLoaded(PackageLoadedParam param) { if ("com.example.target".equals(param.getPackageName())) { // Hook when package loads try { Class targetClass = param.getDefaultClassLoader() .loadClass("com.example.target.MyClass"); hook(targetClass.getDeclaredMethod("targetMethod")) .setPriority(PRIORITY_DEFAULT) .setExceptionMode(ExceptionMode.PROTECTIVE) .intercept(chain -> { log(Log.INFO, TAG, "targetMethod called"); return chain.proceed(); }); } catch (Exception e) { log(Log.ERROR, TAG, "Failed to hook", e); } } } @Override public void onPackageReady(PackageReadyParam param) { // Called after AppComponentFactory, classloader finalized } @Override public boolean onHotReloading(HotReloadingParam param) { // Return true to allow hot reload, false to reject // Must clean up resources before returning true return true; } @Override public void onHotReloaded(HotReloadedParam param) { // Re-install hooks in new code List oldHandles = param.getOldHookHandles(); // Replace old hooks with new implementations for (HookHandle oldHandle : oldHandles) { oldHandle.replaceHook(newHooker); } } } ``` -------------------------------- ### Native Entry Point Registration Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Lists native function names for module entry points in native_init.list. ```c Java_com_example_mymodule_NativeEntry_init ``` -------------------------------- ### Get Saved Instance State from HotReloadedParam Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Retrieves data previously set in HotReloadingParam.setSavedInstanceState(). ```java Object getSavedInstanceState(); ``` -------------------------------- ### HookHandle Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md Represents a handle for an installed hook, allowing for inspection and manipulation such as unhooking or replacing the hook. ```APIDOC ## Interface HookHandle ### Description Handle for installed hook, allowing inspection and manipulation. ### Methods #### getExecutable - **Description**: The method or constructor being hooked. - **Return Type**: Executable #### unhook - **Description**: Cancel the installed hook. This operation is idempotent. - **Return Type**: void #### getId - **Description**: Get the hook ID or null if not set. - **Return Type**: String #### replaceHook - **Description**: Replace the current hook atomically with a new one. - **Parameters**: - **hooker** (Hooker) - Description: The new hook implementation - **Return Type**: HookHandle - **Throws**: IllegalArgumentException, IllegalStateException, HookFailedError ``` -------------------------------- ### Xposed Module File Structure Source: https://github.com/libxposed/api/blob/master/_autodocs/INDEX.md Illustrates the typical directory layout for an Xposed module project. ```plaintext src/main/ ├── java/ │ └── com/example/mymodule/ │ └── MyXposedModule.java ├── resources/ │ └── META-INF/xposed/ │ ├── module.prop │ ├── java_init.list │ └── scope.list └── res/ └── values/ └── strings.xml ``` -------------------------------- ### Get Xposed API Version Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves the runtime Xposed API version. Framework implementations should not override this. ```java default int getApiVersion(); ``` -------------------------------- ### Get Constructor Invoker Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Returns a constructor invoker that bypasses access checks. The default invoker type is `Invoker.Type.Chain.FULL`. ```java @NonNull CtorInvoker getInvoker(@NonNull Constructor constructor); ``` -------------------------------- ### Hot Reload Implementation Source: https://github.com/libxposed/api/blob/master/_autodocs/COMPLETION_REPORT.txt Illustrates how to implement hot reloading for modules, allowing changes to be applied without restarting the application or device. Requires specific callbacks. ```java package io.github.libxposed.api.examples; import io.github.libxposed.api.XposedHook; import io.github.libxposed.api.XposedInterface; public class HotReloadExample implements XposedHook { @Override public void hook(XposedInterface xposed) { xposed.registerCallback(new HotReloadCallback() { @Override public void onHotReloading() { xposed.log("Module is hot reloading..."); // Perform cleanup or state saving before reload } @Override public void onHotReloaded() { xposed.log("Module has been hot reloaded."); // Reinitialize or restore state after reload } }); } } ``` -------------------------------- ### Get Method Invoker Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Returns a method invoker that bypasses access checks. The default invoker type is `Invoker.Type.Chain.FULL`. ```java @NonNull Invoker getInvoker(@NonNull Method method); ``` -------------------------------- ### Get Hook ID Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieve the unique ID assigned to the hook. Returns null if the hook has not been assigned an ID. ```java @SinceApi(API_102) @Nullable String getId(); ``` -------------------------------- ### XposedInterfaceWrapper Implementation Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Demonstrates the basic structure of the XposedInterfaceWrapper class, showing how it acts as a transparent wrapper for the XposedInterface and delegates calls to the underlying framework. ```java public class XposedInterfaceWrapper implements XposedInterface { private XposedInterface mBase; private Runnable mDetachImpl; // Framework attachment (internal only) @InternalApi public final void attachFramework(@NonNull XposedInterface base, @NonNull Runnable detachImpl) { if (mBase != null) { throw new IllegalStateException("Framework already attached"); } mBase = base; mDetachImpl = detachImpl; } // Public API methods delegate to mBase @Override public final HookBuilder hook(@NonNull Executable origin) { ensureAttached(); return mBase.hook(origin); } // Module control methods @SinceApi(API_102) public final void detach() { ensureAttached(); mDetachImpl.run(); } } ``` -------------------------------- ### Framework Information Source: https://github.com/libxposed/api/blob/master/_autodocs/COMPLETION_REPORT.txt Methods for retrieving information about the Xposed framework itself. ```APIDOC ## Framework Information ### Description These methods allow modules to query details about the Xposed framework, including its name, version, and properties. ### Methods - **getFrameworkName()**: Returns the name of the Xposed framework. - **getFrameworkVersion()**: Returns the version string of the Xposed framework. - **getFrameworkVersionCode()**: Returns the version code of the Xposed framework. - **getFrameworkProperties()**: Returns flags indicating framework properties like system, remote, or API protection. ``` -------------------------------- ### Interact with Remote Files Source: https://github.com/libxposed/api/blob/master/_autodocs/INDEX.md Shows how to list remote files and open a specific file for reading. Includes error handling for file not found and unsupported operations. ```java try { String[] files = listRemoteFiles(); ParcelFileDescriptor fd = openRemoteFile("config.txt"); // Read from fd } catch (FileNotFoundException e) { // File not found } catch (UnsupportedOperationException e) { // Remote files not available } ``` -------------------------------- ### Access Remote Preferences Source: https://github.com/libxposed/api/blob/master/_autodocs/INDEX.md Demonstrates how to retrieve remote preferences. Includes error handling for unsupported operations. ```java try { SharedPreferences prefs = getRemotePreferences("group_name"); String value = prefs.getString("key", "default"); } catch (UnsupportedOperationException e) { // Remote preferences not available use_fallback = true; } ``` -------------------------------- ### Java Entry Point Registration Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Specifies fully-qualified Java class names for module entry points in java_init.list. ```java com.example.mymodule.MyXposedModule com.example.mymodule.AnotherModule ``` -------------------------------- ### Typical Xposed Module Usage Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Demonstrates how an Xposed module, extending XposedModule (which inherits from XposedInterfaceWrapper), can load classes, hook methods, and log events using inherited framework APIs. ```java public class MyModule extends XposedModule { @Override public void onPackageLoaded(PackageLoadedParam param) { ClassLoader loader = param.getDefaultClassLoader(); try { Class targetClass = loader.loadClass("com.example.target.MyClass"); Method targetMethod = targetClass.getDeclaredMethod("myMethod"); // Use framework API inherited from XposedInterfaceWrapper HookHandle handle = hook(targetMethod) .setPriority(PRIORITY_DEFAULT) .intercept(chain -> { log(Log.INFO, "MyModule", "Hook called"); return chain.proceed(); }); } catch (Exception e) { log(Log.ERROR, "MyModule", "Hook failed", e); } } @Override public void onHotReloading(HotReloadingParam param) { // Stop operations detach(); // Stop receiving callbacks if appropriate return true; // Allow reload } } ``` -------------------------------- ### Handling XposedFrameworkError Source: https://github.com/libxposed/api/blob/master/_autodocs/errors.md Example of catching XposedFrameworkError. This error indicates a fatal framework bug, and modules should log the error and not attempt recovery. ```java try { HookHandle handle = hook(targetMethod).intercept(hooker); } catch (XposedFrameworkError e) { // Framework is broken, cannot proceed // Report this immediately log(Log.ERROR, "MyModule", "Framework error (report to maintainers): " + e.getMessage()); // Don't try to recover — module cannot function } ``` -------------------------------- ### API Reference Overview Source: https://github.com/libxposed/api/blob/master/_autodocs/COMPLETION_REPORT.txt This section provides an overview of the generated API reference documentation for libxposed. It lists the core public classes and interfaces, along with the number of methods and types documented. The documentation adheres to strict content rules, ensuring accuracy and completeness. ```APIDOC ## API Reference Overview This documentation covers the libxposed API v102.0.0, generated from source code analysis. The reference includes detailed information on core components and their usage. ### Core Components Documented: * **Classes (4):** * `XposedInterface` (interface) * `XposedModule` (abstract class) * `XposedModuleInterface` (interface) * `XposedInterfaceWrapper` (class) * **Interfaces (11):** * `Invoker` (generic) * `Invoker.Type` (sealed) * `CtorInvoker` (generic) * `Chain` (functional) * `Hooker` (functional) * `HookBuilder` (builder) * `HookHandle` (handle) * `ModuleLoadedParam` (callback param) * `PackageLoadedParam` (callback param) * `PackageReadyParam` (callback param) * `SystemServerStartingParam` (callback param) * `HotReloadingParam` (callback param, API 102) * `HotReloadedParam` (callback param, API 102) * **Methods (23+):** * `XposedInterface`: 15 methods * `XposedModuleInterface`: 6 methods * `XposedInterfaceWrapper`: 2 methods ### Documentation Features: * **Format:** Pure markdown (GitHub-flavored), no HTML or styling. * **Structure:** Method signatures with full parameter types, parameter tables, return type specifications, and exception documentation. * **Content:** Precise technical reference only, no invented or speculative content. Behavior derived strictly from source code. ``` -------------------------------- ### Framework Capability Flag: PROP_CAP_SYSTEM Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Indicates that the framework has the capability to hook system_server and other system processes. ```java long PROP_CAP_SYSTEM = 1L; ``` -------------------------------- ### Get Remote Preferences Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves read-only remote preferences stored in the framework for a given group. Throws `UnsupportedOperationException` if the framework is embedded. ```java @NonNull SharedPreferences getRemotePreferences(@NonNull String group); ``` -------------------------------- ### Get Remote Preferences Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Accesses remote SharedPreferences stored within the Xposed framework. Note that these are read-only within hooked applications. ```java @NonNull @Override public final SharedPreferences getRemotePreferences(@NonNull String name) ``` -------------------------------- ### Minimum API Version Configuration Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModule.md Sets the minimum Xposed API version required for the module to function correctly. ```properties minApiVersion=101 ``` -------------------------------- ### onPackageReady Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Called after AppComponentFactory instantiates the classloader and is ready to create the Application. This method is intended for hooking into the application's initialization phase. ```APIDOC ## onPackageReady(PackageReadyParam param) ### Description Called after `AppComponentFactory` instantiates classloader and is ready to create `Application`. ### Method Signature ```java default void onPackageReady(@NonNull PackageReadyParam param) { } ``` ### Parameters #### Path Parameters - **param** (PackageReadyParam) - Required - Information about the package ### Throws `RuntimeException` – All exceptions caught and logged by framework. ### Note Only called once per package name per process. ### Use Cases - Hook when app classloader fully initialized - Hook Activity/Service constructors - Patch Application ### Example ```java @Override public void onPackageReady(PackageReadyParam param) { if ("com.example.target".equals(param.getPackageName())) { ClassLoader loader = param.getClassLoader(); hookApplicationAndActivities(loader); } } ``` ``` -------------------------------- ### Handling HookFailedError during Hook Replacement Source: https://github.com/libxposed/api/blob/master/_autodocs/errors.md Example of catching HookFailedError when attempting to replace an existing hook. This indicates a failure in the hook replacement process. ```java HookHandle oldHandle = param.getOldHookHandles().get(0); try { HookHandle newHandle = oldHandle.replaceHook(newHooker); } catch (HookFailedError e) { log(Log.ERROR, TAG, "Hook replacement failed: " + e.getMessage()); } ``` -------------------------------- ### HookBuilder Interface Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md A builder interface for configuring hooks before installation. It allows setting priority, exception mode, and an optional ID, before intercepting a hooker. ```java interface HookBuilder { HookBuilder setPriority(int priority); HookBuilder setExceptionMode(@NonNull ExceptionMode mode); @SinceApi(API_102) HookBuilder setId(@Nullable String id); @NonNull HookHandle intercept(@NonNull Hooker hooker); } ``` -------------------------------- ### Package Ready Callback Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md This method is called after the AppComponentFactory has instantiated the classloader and is ready to create the Application. It's suitable for hooking Application and Activity constructors. ```java default void onPackageReady(@NonNull PackageReadyParam param) { } ``` ```java @Override public void onPackageReady(PackageReadyParam param) { if ("com.example.target".equals(param.getPackageName())) { ClassLoader loader = param.getClassLoader(); hookApplicationAndActivities(loader); } } ``` -------------------------------- ### getModuleApplicationInfo Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Retrieves the `ApplicationInfo` of the module. ```APIDOC ## getModuleApplicationInfo() ### Description Returns `ApplicationInfo` of the module. ### Method N/A (Instance Method) ### Endpoint N/A ### Returns - **ApplicationInfo**: The `ApplicationInfo` of the module. ``` -------------------------------- ### Get Extras from Hot ReloadingParam Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Retrieves data passed from the module app when triggering hot reload via service or app update. ```java Bundle getExtras(); ``` -------------------------------- ### getExecutable() Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Returns the method or constructor that is currently being hooked. ```APIDOC ## getExecutable() ### Description Returns the method or constructor being hooked. ### Method ```java @NonNull Executable getExecutable(); ``` ``` -------------------------------- ### HookHandle Interface Source: https://github.com/libxposed/api/blob/master/_autodocs/types.md Represents a handle for an installed hook, allowing for inspection and manipulation. It provides access to the hooked executable and methods to unhook or replace the hook. ```java interface HookHandle { @NonNull Executable getExecutable(); void unhook(); @SinceApi(API_102) @Nullable String getId(); @SinceApi(API_102) @NonNull HookHandle replaceHook(@NonNull Hooker hooker); } ``` -------------------------------- ### log(int priority, String tag, String msg, Throwable tr) Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Writes a message with an exception to the Xposed log. ```APIDOC ## log(int priority, String tag, String msg, Throwable tr) ### Description Writes message with exception to Xposed log. ### Method N/A (Instance Method) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **priority** (int) - Required - Description: Log priority (see `android.util.Log`) - **tag** (String) - Optional - Default: null - Description: Log tag - **msg** (String) - Required - Description: Log message - **tr** (Throwable) - Optional - Default: null - Description: Exception to log ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Returns void ``` -------------------------------- ### Get Old Hook Handles from HotReloadedParam Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Returns a list of hook handles created by the previous module generation. New code can manage these hooks. ```java List getOldHookHandles(); ``` -------------------------------- ### Module Application Info Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Retrieves the `ApplicationInfo` object for the currently running module. ```APIDOC ## getModuleApplicationInfo() ### Description Returns `ApplicationInfo` of the module. ### Method Signature `@NonNull @Override public final ApplicationInfo getModuleApplicationInfo()` ### Returns The `ApplicationInfo` of the module. ``` -------------------------------- ### HookFailedError Class Definition Source: https://github.com/libxposed/api/blob/master/_autodocs/errors.md Defines the HookFailedError class, which extends XposedFrameworkError. This error is thrown when hook installation or replacement fails due to a framework internal error. ```java public class HookFailedError extends XposedFrameworkError { public HookFailedError(String message); public HookFailedError(String message, Throwable cause); public HookFailedError(Throwable cause); } ``` -------------------------------- ### XposedModule Source: https://github.com/libxposed/api/blob/master/_autodocs/INDEX.md Abstract base class for module entry points. Modules extend this class to define their entry point and access framework functionalities. ```APIDOC ## XposedModule ### Description Abstract base class for module entry points. Modules extend this class to define entry point. ### Hierarchy - Extends `XposedInterfaceWrapper` (framework API access) - Implements `XposedModuleInterface` (lifecycle callbacks) ### Entry Registration - List in `META-INF/xposed/java_init.list` - One entry class per module (required for hot reload) ### Key Features - Framework automatically calls `attachFramework()` on instantiation - Access all `XposedInterface` methods directly - Override lifecycle callbacks as needed ``` -------------------------------- ### Get Constructor Invoker Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Retrieves an invoker for a given constructor, bypassing standard access checks. This allows for the instantiation of objects through constructors that might otherwise be inaccessible. ```java @NonNull @Override public final CtorInvoker getInvoker(@NonNull Constructor constructor) ``` -------------------------------- ### Get Method Invoker Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Retrieves an invoker for a given method, bypassing standard access checks. This is useful for invoking private or protected methods from external contexts. ```java @NonNull @Override public final Invoker getInvoker(@NonNull Method method) ``` -------------------------------- ### Enable Minification and ProGuard in Gradle Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Configure your Android project's `build.gradle` file to enable code minification and apply ProGuard rules for release builds. This is essential for optimizing your application and protecting your code. ```gradle android { buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } ``` -------------------------------- ### List Remote Files Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterfaceWrapper.md Lists all files present in the module's shared data directory within the Xposed framework. This allows modules to query available resources. ```java @NonNull @Override public final String[] listRemoteFiles() ``` -------------------------------- ### Xposed Module Scope Configuration List Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModule.md Defines the package names for which the module's scope is configured. Framework injects the module into regular processes of these packages. ```text com.example.app1 com.example.app2 system ``` -------------------------------- ### List Remote Files Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Lists all files within the module's shared data directory. Throws `UnsupportedOperationException` if the framework is embedded. ```java @NonNull String[] listRemoteFiles(); ``` -------------------------------- ### onPackageLoaded Callback Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Callback invoked when a package with `hasCode` loads, before `AppComponentFactory` instantiation. ```APIDOC ### onPackageLoaded(PackageLoadedParam param) Called when `hasCode` package loads. Default classloader ready, before `AppComponentFactory` instantiation. ```java @RequiresApi(Build.VERSION_CODES.Q) default void onPackageLoaded(@NonNull PackageLoadedParam param) { } ``` | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | param | PackageLoadedParam | Yes | Information about the package | **Requires:** API 29+ (`Build.VERSION_CODES.Q`) **Throws:** `RuntimeException` – All exceptions caught and logged by framework. **Note:** Only called once per package name per process. Process may load multiple packages (shared user ID, context package). #### Use Cases - Load classes before AppComponentFactory - Hook early-stage methods - Check if package is target; call `detach()` if not ``` -------------------------------- ### XposedModuleInterface Source: https://github.com/libxposed/api/blob/master/_autodocs/INDEX.md Defines lifecycle callback methods for module entry points, allowing modules to respond to various events during the application lifecycle. ```APIDOC ## XposedModuleInterface ### Description Defines lifecycle callback methods for module entry points. ### Lifecycle Callbacks - `onModuleLoaded(ModuleLoadedParam)` – Module loaded into process - `onPackageLoaded(PackageLoadedParam)` – Package default classloader ready - `onPackageReady(PackageReadyParam)` – App classloader created - `onSystemServerStarting(SystemServerStartingParam)` – System server starting - `onHotReloading(HotReloadingParam)` – Before hot reload (API 102+) - `onHotReloaded(HotReloadedParam)` – After hot reload (API 102+) ### Callback Parameters - Contain process/package information at load time - Information frozen (not updated after load) - Modules should filter by process and package name ``` -------------------------------- ### log(int priority, String tag, String msg) Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Writes a message to the Xposed log with a specified priority and optional tag. ```APIDOC ## log(int priority, String tag, String msg) ### Description Writes message to Xposed log. ### Method N/A (Instance Method) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **priority** (int) - Required - Description: Log priority (see `android.util.Log`) - **tag** (String) - Optional - Default: null - Description: Log tag - **msg** (String) - Required - Description: Log message ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Returns void ``` -------------------------------- ### Hooking on Package Load Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedModuleInterface.md Implement this method to hook into the application's classloader as soon as the package is loaded. This is useful for early initialization tasks. ```java @Override public void onPackageLoaded(PackageLoadedParam param) { if ("com.example.target".equals(param.getPackageName())) { ClassLoader loader = param.getDefaultClassLoader(); hookEarlyClasses(loader); } } ``` -------------------------------- ### Required Properties for module.prop Source: https://github.com/libxposed/api/blob/master/_autodocs/configuration.md Defines the minimum and target Xposed API versions required for the module. ```properties minApiVersion=101 targetApiVersion=102 ``` -------------------------------- ### HookBuilder.intercept(Hooker hooker) Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Configures the hooker and builds the hook. This method should be called after setting any desired configurations like priority or exception mode. ```APIDOC ## HookBuilder.intercept(Hooker hooker) ### Description Sets hooker and builds the hook. ### Method ```java @NonNull HookHandle intercept(@NonNull Hooker hooker); ``` ### Parameters #### Request Body - **hooker** (Hooker) - Required - The hooker implementation ### Throws - `IllegalArgumentException` if origin is framework internal or if hooker invalid - `HookFailedError` if hook fails due to framework internal error ``` -------------------------------- ### Intercepting Method Calls with XposedInterface Source: https://github.com/libxposed/api/blob/master/_autodocs/api-reference/XposedInterface.md Demonstrates how to hook a target method, set its priority and exception handling mode, and intercept its execution to modify arguments and process the result. ```java HookHandle handle = getInvoker().hook(targetMethod) .setPriority(XposedInterface.PRIORITY_DEFAULT) .setExceptionMode(ExceptionMode.PROTECTIVE) .intercept(chain -> { // Pre-processing Object receiver = chain.getThisObject(); Object[] args = chain.getArgs().toArray(); // Modify if needed args[0] = modifyArg(args[0]); // Invoke with new arguments Object result = chain.proceed(args); // Post-processing return result; }); ```