From d7897b67d9be068799a2a59f861dc0e3ede0bc78 Mon Sep 17 00:00:00 2001
From: tehcneko <7764726+tehcneko@users.noreply.github.com>
Date: Sat, 24 Apr 2021 14:59:35 +0800
Subject: [PATCH] [core] Remove useless codes (#505)
* [core] Replace tabs with spaces
* [core] Remove useless codes
---
.../android/xposed/IXposedHookCmdInit.java | 36 +-
.../IXposedHookInitPackageResources.java | 52 +-
.../xposed/IXposedHookLoadPackage.java | 55 +-
.../android/xposed/IXposedHookZygoteInit.java | 50 +-
.../de/robv/android/xposed/IXposedMod.java | 7 +-
.../de/robv/android/xposed/SELinuxHelper.java | 75 +-
.../de/robv/android/xposed/XC_MethodHook.java | 280 +-
.../android/xposed/XC_MethodReplacement.java | 147 +-
.../android/xposed/XSharedPreferences.java | 19 +-
.../de/robv/android/xposed/XposedBridge.java | 653 ++--
.../de/robv/android/xposed/XposedHelpers.java | 3287 +++++++++--------
.../de/robv/android/xposed/XposedInit.java | 73 +-
.../android/xposed/callbacks/IXUnhook.java | 16 +-
.../callbacks/XC_InitPackageResources.java | 85 +-
.../xposed/callbacks/XC_LayoutInflated.java | 156 +-
.../xposed/callbacks/XC_LoadPackage.java | 99 +-
.../android/xposed/callbacks/XCallback.java | 255 +-
.../android/xposed/services/BaseService.java | 307 +-
.../xposed/services/DirectAccessService.java | 184 +-
.../android/xposed/services/FileResult.java | 104 +-
.../main/java/org/lsposed/lspd/core/Main.java | 8 +-
.../lspd/hooker/HandleBindAppHooker.java | 2 +-
.../hooker/StartBootstrapServicesHooker.java | 4 +-
23 files changed, 3080 insertions(+), 2874 deletions(-)
diff --git a/core/src/main/java/de/robv/android/xposed/IXposedHookCmdInit.java b/core/src/main/java/de/robv/android/xposed/IXposedHookCmdInit.java
index e7c8b1cc..655453b8 100644
--- a/core/src/main/java/de/robv/android/xposed/IXposedHookCmdInit.java
+++ b/core/src/main/java/de/robv/android/xposed/IXposedHookCmdInit.java
@@ -28,21 +28,29 @@ package de.robv.android.xposed;
* implemented anymore.
*/
public interface IXposedHookCmdInit extends IXposedMod {
- /**
- * Called very early during startup of a command-line tool.
- * @param startupParam Details about the module itself and the started process.
- * @throws Throwable Everything is caught, but it will prevent further initialization of the module.
- */
- void initCmdApp(StartupParam startupParam) throws Throwable;
+ /**
+ * Called very early during startup of a command-line tool.
+ *
+ * @param startupParam Details about the module itself and the started process.
+ * @throws Throwable Everything is caught, but it will prevent further initialization of the module.
+ */
+ void initCmdApp(StartupParam startupParam) throws Throwable;
- /** Data holder for {@link #initCmdApp}. */
- final class StartupParam {
- /*package*/ StartupParam() {}
+ /**
+ * Data holder for {@link #initCmdApp}.
+ */
+ final class StartupParam {
+ /*package*/ StartupParam() {
+ }
- /** The path to the module's APK. */
- public String modulePath;
+ /**
+ * The path to the module's APK.
+ */
+ public String modulePath;
- /** The class name of the tools that the hook was invoked for. */
- public String startClassName;
- }
+ /**
+ * The class name of the tools that the hook was invoked for.
+ */
+ public String startClassName;
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/IXposedHookInitPackageResources.java b/core/src/main/java/de/robv/android/xposed/IXposedHookInitPackageResources.java
index 73d739df..9b00ccea 100644
--- a/core/src/main/java/de/robv/android/xposed/IXposedHookInitPackageResources.java
+++ b/core/src/main/java/de/robv/android/xposed/IXposedHookInitPackageResources.java
@@ -33,33 +33,35 @@ import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResou
* registering it as a callback automatically.
*/
public interface IXposedHookInitPackageResources extends IXposedMod {
- /**
- * This method is called when resources for an app are being initialized.
- * Modules can call special methods of the {@link XResources} class in order to replace resources.
- *
- * @param resparam Information about the resources.
- * @throws Throwable Everything the callback throws is caught and logged.
- */
- void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable;
+ /**
+ * This method is called when resources for an app are being initialized.
+ * Modules can call special methods of the {@link XResources} class in order to replace resources.
+ *
+ * @param resparam Information about the resources.
+ * @throws Throwable Everything the callback throws is caught and logged.
+ */
+ void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable;
- /** @hide */
- final class Wrapper extends XC_InitPackageResources {
- private final IXposedHookInitPackageResources instance;
- private final String apkPath;
+ /**
+ * @hide
+ */
+ final class Wrapper extends XC_InitPackageResources {
+ private final IXposedHookInitPackageResources instance;
+ private final String apkPath;
- public Wrapper(IXposedHookInitPackageResources instance, String apkPath) {
- this.instance = instance;
- this.apkPath = apkPath;
- }
+ public Wrapper(IXposedHookInitPackageResources instance, String apkPath) {
+ this.instance = instance;
+ this.apkPath = apkPath;
+ }
- @Override
- public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable {
- instance.handleInitPackageResources(resparam);
- }
+ @Override
+ public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable {
+ instance.handleInitPackageResources(resparam);
+ }
- @Override
- public String getApkPath() {
- return apkPath;
- }
- }
+ @Override
+ public String getApkPath() {
+ return apkPath;
+ }
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/IXposedHookLoadPackage.java b/core/src/main/java/de/robv/android/xposed/IXposedHookLoadPackage.java
index 08d443eb..7be79f5f 100644
--- a/core/src/main/java/de/robv/android/xposed/IXposedHookLoadPackage.java
+++ b/core/src/main/java/de/robv/android/xposed/IXposedHookLoadPackage.java
@@ -33,33 +33,36 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
* registering it as a callback automatically.
*/
public interface IXposedHookLoadPackage extends IXposedMod {
- /**
- * This method is called when an app is loaded. It's called very early, even before
- * {@link Application#onCreate} is called.
- * Modules can set up their app-specific hooks here.
- *
- * @param lpparam Information about the app.
- * @throws Throwable Everything the callback throws is caught and logged.
- */
- void handleLoadPackage(LoadPackageParam lpparam) throws Throwable;
+ /**
+ * This method is called when an app is loaded. It's called very early, even before
+ * {@link Application#onCreate} is called.
+ * Modules can set up their app-specific hooks here.
+ *
+ * @param lpparam Information about the app.
+ * @throws Throwable Everything the callback throws is caught and logged.
+ */
+ void handleLoadPackage(LoadPackageParam lpparam) throws Throwable;
- /** @hide */
- final class Wrapper extends XC_LoadPackage {
- private final IXposedHookLoadPackage instance;
- private final String apkPath;
+ /**
+ * @hide
+ */
+ final class Wrapper extends XC_LoadPackage {
+ private final IXposedHookLoadPackage instance;
+ private final String apkPath;
- public Wrapper(IXposedHookLoadPackage instance, String apkPath) {
- this.instance = instance;
- this.apkPath = apkPath;
- }
- @Override
- public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
- instance.handleLoadPackage(lpparam);
- }
+ public Wrapper(IXposedHookLoadPackage instance, String apkPath) {
+ this.instance = instance;
+ this.apkPath = apkPath;
+ }
- @Override
- public String getApkPath() {
- return apkPath;
- }
- }
+ @Override
+ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
+ instance.handleLoadPackage(lpparam);
+ }
+
+ @Override
+ public String getApkPath() {
+ return apkPath;
+ }
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/IXposedHookZygoteInit.java b/core/src/main/java/de/robv/android/xposed/IXposedHookZygoteInit.java
index 23277004..5e6d5c3a 100644
--- a/core/src/main/java/de/robv/android/xposed/IXposedHookZygoteInit.java
+++ b/core/src/main/java/de/robv/android/xposed/IXposedHookZygoteInit.java
@@ -35,16 +35,20 @@ import de.robv.android.xposed.callbacks.XCallback;
*
If you want to hook one/multiple specific apps, use {@link IXposedHookLoadPackage} instead.
*/
public interface IXposedHookZygoteInit extends IXposedMod {
- /**
- * Called very early during startup of Zygote.
- * @param startupParam Details about the module itself and the started process.
- * @throws Throwable everything is caught, but will prevent further initialization of the module.
- */
- void initZygote(StartupParam startupParam) throws Throwable;
+ /**
+ * Called very early during startup of Zygote.
+ *
+ * @param startupParam Details about the module itself and the started process.
+ * @throws Throwable everything is caught, but will prevent further initialization of the module.
+ */
+ void initZygote(StartupParam startupParam) throws Throwable;
- /** Data holder for {@link #initZygote}. */
- final class StartupParam extends XCallback.Param {
- /*package*/ StartupParam() {}
+ /**
+ * Data holder for {@link #initZygote}.
+ */
+ final class StartupParam extends XCallback.Param {
+ /*package*/ StartupParam() {
+ }
/**
* @param callbacks
@@ -54,15 +58,17 @@ public interface IXposedHookZygoteInit extends IXposedMod {
super(callbacks);
}
- /** The path to the module's APK. */
- public String modulePath;
+ /**
+ * The path to the module's APK.
+ */
+ public String modulePath;
- /**
- * Always {@code true} on 32-bit ROMs. On 64-bit, it's only {@code true} for the primary
- * process that starts the system_server.
- */
- public boolean startsSystemServer;
- }
+ /**
+ * Always {@code true} on 32-bit ROMs. On 64-bit, it's only {@code true} for the primary
+ * process that starts the system_server.
+ */
+ public boolean startsSystemServer;
+ }
/**
* @hide
@@ -83,9 +89,9 @@ public interface IXposedHookZygoteInit extends IXposedMod {
instance.initZygote(this.startupParam);
}
- @Override
- public String getApkPath() {
- return startupParam.modulePath;
- }
- }
+ @Override
+ public String getApkPath() {
+ return startupParam.modulePath;
+ }
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/IXposedMod.java b/core/src/main/java/de/robv/android/xposed/IXposedMod.java
index dd0fcb02..319fa560 100644
--- a/core/src/main/java/de/robv/android/xposed/IXposedMod.java
+++ b/core/src/main/java/de/robv/android/xposed/IXposedMod.java
@@ -20,5 +20,8 @@
package de.robv.android.xposed;
-/** Marker interface for Xposed modules. Cannot be implemented directly. */
-/* package */ interface IXposedMod {}
+/**
+ * Marker interface for Xposed modules. Cannot be implemented directly.
+ */
+/* package */ interface IXposedMod {
+}
diff --git a/core/src/main/java/de/robv/android/xposed/SELinuxHelper.java b/core/src/main/java/de/robv/android/xposed/SELinuxHelper.java
index 0156c0f3..a5c8fe8c 100644
--- a/core/src/main/java/de/robv/android/xposed/SELinuxHelper.java
+++ b/core/src/main/java/de/robv/android/xposed/SELinuxHelper.java
@@ -27,49 +27,50 @@ import de.robv.android.xposed.services.DirectAccessService;
* A helper to work with (or without) SELinux, abstracting much of its big complexity.
*/
public final class SELinuxHelper {
- private SELinuxHelper() {}
+ private SELinuxHelper() {
+ }
- /**
- * Determines whether SELinux is disabled or enabled.
- *
- * @return A boolean indicating whether SELinux is enabled.
- */
- public static boolean isSELinuxEnabled() {
- // lsp: always enabled
- return true;
- }
+ /**
+ * Determines whether SELinux is disabled or enabled.
+ *
+ * @return A boolean indicating whether SELinux is enabled.
+ */
+ public static boolean isSELinuxEnabled() {
+ // lsp: always enabled
+ return true;
+ }
- /**
- * Determines whether SELinux is permissive or enforcing.
- *
- * @return A boolean indicating whether SELinux is enforcing.
- */
- public static boolean isSELinuxEnforced() {
- // lsp: always enforcing
- return true;
- }
+ /**
+ * Determines whether SELinux is permissive or enforcing.
+ *
+ * @return A boolean indicating whether SELinux is enforcing.
+ */
+ public static boolean isSELinuxEnforced() {
+ // lsp: always enforcing
+ return true;
+ }
- /**
- * Gets the security context of the current process.
- *
- * @return A String representing the security context of the current process.
- */
- public static String getContext() {
- return null;
- }
+ /**
+ * Gets the security context of the current process.
+ *
+ * @return A String representing the security context of the current process.
+ */
+ public static String getContext() {
+ return null;
+ }
- /**
- * Retrieve the service to be used when accessing files in {@code /data/data/*}.
- *
- *
IMPORTANT: If you call this from the Zygote process,
- * don't re-use the result in different process!
- *
- * @return An instance of the service.
- */
- public static BaseService getAppDataFileService() {
+ /**
+ * Retrieve the service to be used when accessing files in {@code /data/data/*}.
+ *
+ *
IMPORTANT: If you call this from the Zygote process,
+ * don't re-use the result in different process!
+ *
+ * @return An instance of the service.
+ */
+ public static BaseService getAppDataFileService() {
return sServiceAppDataFile;
}
- private static final BaseService sServiceAppDataFile = new DirectAccessService(); // ed: initialized directly
+ private static final BaseService sServiceAppDataFile = new DirectAccessService(); // ed: initialized directly
}
diff --git a/core/src/main/java/de/robv/android/xposed/XC_MethodHook.java b/core/src/main/java/de/robv/android/xposed/XC_MethodHook.java
index 9fa3193c..e593064b 100644
--- a/core/src/main/java/de/robv/android/xposed/XC_MethodHook.java
+++ b/core/src/main/java/de/robv/android/xposed/XC_MethodHook.java
@@ -32,157 +32,175 @@ import de.robv.android.xposed.callbacks.XCallback;
* {@link #beforeHookedMethod} and/or {@link #afterHookedMethod}.
*/
public abstract class XC_MethodHook extends XCallback {
- /**
- * Creates a new callback with default priority.
- */
- @SuppressWarnings("deprecation")
- public XC_MethodHook() {
- super();
- }
+ /**
+ * Creates a new callback with default priority.
+ */
+ @SuppressWarnings("deprecation")
+ public XC_MethodHook() {
+ super();
+ }
- /**
- * Creates a new callback with a specific priority.
- *
- *
Note that {@link #afterHookedMethod} will be called in reversed order, i.e.
- * the callback with the highest priority will be called last. This way, the callback has the
- * final control over the return value. {@link #beforeHookedMethod} is called as usual, i.e.
- * highest priority first.
- *
- * @param priority See {@link XCallback#priority}.
- */
- public XC_MethodHook(int priority) {
- super(priority);
- }
+ /**
+ * Creates a new callback with a specific priority.
+ *
+ *
Note that {@link #afterHookedMethod} will be called in reversed order, i.e.
+ * the callback with the highest priority will be called last. This way, the callback has the
+ * final control over the return value. {@link #beforeHookedMethod} is called as usual, i.e.
+ * highest priority first.
+ *
+ * @param priority See {@link XCallback#priority}.
+ */
+ public XC_MethodHook(int priority) {
+ super(priority);
+ }
- /**
- * Called before the invocation of the method.
- *
- *
You can use {@link MethodHookParam#setResult} and {@link MethodHookParam#setThrowable}
- * to prevent the original method from being called.
- *
- *
Note that implementations shouldn't call {@code super(param)}, it's not necessary.
- *
- * @param param Information about the method call.
- * @throws Throwable Everything the callback throws is caught and logged.
- */
- protected void beforeHookedMethod(MethodHookParam param) throws Throwable {}
+ /**
+ * Called before the invocation of the method.
+ *
+ *
You can use {@link MethodHookParam#setResult} and {@link MethodHookParam#setThrowable}
+ * to prevent the original method from being called.
+ *
+ *
Note that implementations shouldn't call {@code super(param)}, it's not necessary.
+ *
+ * @param param Information about the method call.
+ * @throws Throwable Everything the callback throws is caught and logged.
+ */
+ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ }
- public void callBeforeHookedMethod(MethodHookParam param) throws Throwable {
- beforeHookedMethod(param);
- }
+ public void callBeforeHookedMethod(MethodHookParam param) throws Throwable {
+ beforeHookedMethod(param);
+ }
- /**
- * Called after the invocation of the method.
- *
- *
You can use {@link MethodHookParam#setResult} and {@link MethodHookParam#setThrowable}
- * to modify the return value of the original method.
- *
- *
Note that implementations shouldn't call {@code super(param)}, it's not necessary.
- *
- * @param param Information about the method call.
- * @throws Throwable Everything the callback throws is caught and logged.
- */
- protected void afterHookedMethod(MethodHookParam param) throws Throwable {}
+ /**
+ * Called after the invocation of the method.
+ *
+ *
You can use {@link MethodHookParam#setResult} and {@link MethodHookParam#setThrowable}
+ * to modify the return value of the original method.
+ *
+ *
Note that implementations shouldn't call {@code super(param)}, it's not necessary.
+ *
+ * @param param Information about the method call.
+ * @throws Throwable Everything the callback throws is caught and logged.
+ */
+ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
+ }
- public void callAfterHookedMethod(MethodHookParam param) throws Throwable {
- afterHookedMethod(param);
- }
+ public void callAfterHookedMethod(MethodHookParam param) throws Throwable {
+ afterHookedMethod(param);
+ }
- /**
- * Wraps information about the method call and allows to influence it.
- */
- public static final class MethodHookParam extends XCallback.Param {
- /** @hide */
- @SuppressWarnings("deprecation")
- public MethodHookParam() {
- super();
- }
+ /**
+ * Wraps information about the method call and allows to influence it.
+ */
+ public static final class MethodHookParam extends XCallback.Param {
+ /**
+ * @hide
+ */
+ @SuppressWarnings("deprecation")
+ public MethodHookParam() {
+ super();
+ }
- /** The hooked method/constructor. */
- public Member method;
+ /**
+ * The hooked method/constructor.
+ */
+ public Member method;
- /** The {@code this} reference for an instance method, or {@code null} for static methods. */
- public Object thisObject;
+ /**
+ * The {@code this} reference for an instance method, or {@code null} for static methods.
+ */
+ public Object thisObject;
- /** Arguments to the method call. */
- public Object[] args;
+ /**
+ * Arguments to the method call.
+ */
+ public Object[] args;
- private Object result = null;
- private Throwable throwable = null;
- public boolean returnEarly = false;
+ private Object result = null;
+ private Throwable throwable = null;
+ public boolean returnEarly = false;
- /** Returns the result of the method call. */
- public Object getResult() {
- return result;
- }
+ /**
+ * Returns the result of the method call.
+ */
+ public Object getResult() {
+ return result;
+ }
- /**
- * Modify the result of the method call.
- *
- *
If called from {@link #beforeHookedMethod}, it prevents the call to the original method.
- */
- public void setResult(Object result) {
- this.result = result;
- this.throwable = null;
- this.returnEarly = true;
- }
+ /**
+ * Modify the result of the method call.
+ *
+ *
If called from {@link #beforeHookedMethod}, it prevents the call to the original method.
+ */
+ public void setResult(Object result) {
+ this.result = result;
+ this.throwable = null;
+ this.returnEarly = true;
+ }
- /** Returns the {@link Throwable} thrown by the method, or {@code null}. */
- public Throwable getThrowable() {
- return throwable;
- }
+ /**
+ * Returns the {@link Throwable} thrown by the method, or {@code null}.
+ */
+ public Throwable getThrowable() {
+ return throwable;
+ }
- /** Returns true if an exception was thrown by the method. */
- public boolean hasThrowable() {
- return throwable != null;
- }
+ /**
+ * Returns true if an exception was thrown by the method.
+ */
+ public boolean hasThrowable() {
+ return throwable != null;
+ }
- /**
- * Modify the exception thrown of the method call.
- *
- *
If called from {@link #beforeHookedMethod}, it prevents the call to the original method.
- */
- public void setThrowable(Throwable throwable) {
- this.throwable = throwable;
- this.result = null;
- this.returnEarly = true;
- }
+ /**
+ * Modify the exception thrown of the method call.
+ *
+ *
If called from {@link #beforeHookedMethod}, it prevents the call to the original method.
+ */
+ public void setThrowable(Throwable throwable) {
+ this.throwable = throwable;
+ this.result = null;
+ this.returnEarly = true;
+ }
- /** Returns the result of the method call, or throws the Throwable caused by it. */
- public Object getResultOrThrowable() throws Throwable {
- if (throwable != null)
- throw throwable;
- return result;
- }
- }
+ /**
+ * Returns the result of the method call, or throws the Throwable caused by it.
+ */
+ public Object getResultOrThrowable() throws Throwable {
+ if (throwable != null)
+ throw throwable;
+ return result;
+ }
+ }
- /**
- * An object with which the method/constructor can be unhooked.
- */
- public class Unhook implements IXUnhook {
- private final Member hookMethod;
+ /**
+ * An object with which the method/constructor can be unhooked.
+ */
+ public class Unhook implements IXUnhook {
+ private final Member hookMethod;
- /*package*/ Unhook(Member hookMethod) {
- this.hookMethod = hookMethod;
- }
+ /*package*/ Unhook(Member hookMethod) {
+ this.hookMethod = hookMethod;
+ }
- /**
- * Returns the method/constructor that has been hooked.
- */
- public Member getHookedMethod() {
- return hookMethod;
- }
+ /**
+ * Returns the method/constructor that has been hooked.
+ */
+ public Member getHookedMethod() {
+ return hookMethod;
+ }
- @Override
- public XC_MethodHook getCallback() {
- return XC_MethodHook.this;
- }
+ @Override
+ public XC_MethodHook getCallback() {
+ return XC_MethodHook.this;
+ }
- @SuppressWarnings("deprecation")
- @Override
- public void unhook() {
- XposedBridge.unhookMethod(hookMethod, XC_MethodHook.this);
- }
+ @SuppressWarnings("deprecation")
+ @Override
+ public void unhook() {
+ XposedBridge.unhookMethod(hookMethod, XC_MethodHook.this);
+ }
- }
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/XC_MethodReplacement.java b/core/src/main/java/de/robv/android/xposed/XC_MethodReplacement.java
index f9169b60..3bb3b237 100644
--- a/core/src/main/java/de/robv/android/xposed/XC_MethodReplacement.java
+++ b/core/src/main/java/de/robv/android/xposed/XC_MethodReplacement.java
@@ -26,83 +26,88 @@ import de.robv.android.xposed.callbacks.XCallback;
* A special case of {@link XC_MethodHook} which completely replaces the original method.
*/
public abstract class XC_MethodReplacement extends XC_MethodHook {
- /**
- * Creates a new callback with default priority.
- */
- public XC_MethodReplacement() {
- super();
- }
+ /**
+ * Creates a new callback with default priority.
+ */
+ public XC_MethodReplacement() {
+ super();
+ }
- /**
- * Creates a new callback with a specific priority.
- *
- * @param priority See {@link XCallback#priority}.
- */
- public XC_MethodReplacement(int priority) {
- super(priority);
- }
+ /**
+ * Creates a new callback with a specific priority.
+ *
+ * @param priority See {@link XCallback#priority}.
+ */
+ public XC_MethodReplacement(int priority) {
+ super(priority);
+ }
- /** @hide */
- @Override
- protected final void beforeHookedMethod(MethodHookParam param) throws Throwable {
- try {
- Object result = replaceHookedMethod(param);
- param.setResult(result);
- } catch (Throwable t) {
- XposedBridge.log(t);
- param.setThrowable(t);
- }
- }
+ /**
+ * @hide
+ */
+ @Override
+ protected final void beforeHookedMethod(MethodHookParam param) throws Throwable {
+ try {
+ Object result = replaceHookedMethod(param);
+ param.setResult(result);
+ } catch (Throwable t) {
+ XposedBridge.log(t);
+ param.setThrowable(t);
+ }
+ }
- /** @hide */
- @Override
- @SuppressWarnings("EmptyMethod")
- protected final void afterHookedMethod(MethodHookParam param) throws Throwable {}
+ /**
+ * @hide
+ */
+ @Override
+ @SuppressWarnings("EmptyMethod")
+ protected final void afterHookedMethod(MethodHookParam param) throws Throwable {
+ }
- /**
- * Shortcut for replacing a method completely. Whatever is returned/thrown here is taken
- * instead of the result of the original method (which will not be called).
- *
- *
Note that implementations shouldn't call {@code super(param)}, it's not necessary.
- *
- * @param param Information about the method call.
- * @throws Throwable Anything that is thrown by the callback will be passed on to the original caller.
- */
- @SuppressWarnings("UnusedParameters")
- protected abstract Object replaceHookedMethod(MethodHookParam param) throws Throwable;
+ /**
+ * Shortcut for replacing a method completely. Whatever is returned/thrown here is taken
+ * instead of the result of the original method (which will not be called).
+ *
+ *
Note that implementations shouldn't call {@code super(param)}, it's not necessary.
+ *
+ * @param param Information about the method call.
+ * @throws Throwable Anything that is thrown by the callback will be passed on to the original caller.
+ */
+ @SuppressWarnings("UnusedParameters")
+ protected abstract Object replaceHookedMethod(MethodHookParam param) throws Throwable;
- /**
- * Predefined callback that skips the method without replacements.
- */
- public static final XC_MethodReplacement DO_NOTHING = new XC_MethodReplacement(PRIORITY_HIGHEST*2) {
- @Override
- protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
- return null;
- }
- };
+ /**
+ * Predefined callback that skips the method without replacements.
+ */
+ public static final XC_MethodReplacement DO_NOTHING = new XC_MethodReplacement(PRIORITY_HIGHEST * 2) {
+ @Override
+ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
+ return null;
+ }
+ };
- /**
- * Creates a callback which always returns a specific value.
- *
- * @param result The value that should be returned to callers of the hooked method.
- */
- public static XC_MethodReplacement returnConstant(final Object result) {
- return returnConstant(PRIORITY_DEFAULT, result);
- }
+ /**
+ * Creates a callback which always returns a specific value.
+ *
+ * @param result The value that should be returned to callers of the hooked method.
+ */
+ public static XC_MethodReplacement returnConstant(final Object result) {
+ return returnConstant(PRIORITY_DEFAULT, result);
+ }
- /**
- * Like {@link #returnConstant(Object)}, but allows to specify a priority for the callback.
- *
- * @param priority See {@link XCallback#priority}.
- * @param result The value that should be returned to callers of the hooked method.
- */
- public static XC_MethodReplacement returnConstant(int priority, final Object result) {
- return new XC_MethodReplacement(priority) {
- @Override
- protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
- return result;
- }
- };
- }
+ /**
+ * Like {@link #returnConstant(Object)}, but allows to specify a priority for the callback.
+ *
+ * @param priority See {@link XCallback#priority}.
+ * @param result The value that should be returned to callers of the hooked method.
+ */
+ public static XC_MethodReplacement returnConstant(int priority, final Object result) {
+ return new XC_MethodReplacement(priority) {
+ @Override
+ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
+ return result;
+ }
+ };
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java b/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java
index d2501d8b..1d73b9dc 100644
--- a/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java
+++ b/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java
@@ -28,6 +28,7 @@ import android.preference.PreferenceManager;
import android.util.Log;
import com.android.internal.util.XmlUtils;
+
import org.lsposed.lspd.BuildConfig;
import org.lsposed.lspd.util.MetaDataReader;
@@ -99,7 +100,8 @@ public final class XSharedPreferences implements SharedPreferences {
Path dir = (Path) key.watchable();
Path path = dir.resolve((Path) event.context());
String pathStr = path.toString();
- if (BuildConfig.DEBUG) Log.v(TAG, "File " + path.toString() + " event: " + kind.name());
+ if (BuildConfig.DEBUG)
+ Log.v(TAG, "File " + path.toString() + " event: " + kind.name());
// We react to both real and backup files due to rare race conditions
if (pathStr.endsWith(".bak")) {
if (kind != StandardWatchEventKinds.ENTRY_DELETE) {
@@ -114,7 +116,8 @@ public final class XSharedPreferences implements SharedPreferences {
try {
l.onSharedPreferenceChanged(data.mPrefs, null);
} catch (Throwable t) {
- if (BuildConfig.DEBUG) Log.e(TAG, "Fail in preference change listener", t);
+ if (BuildConfig.DEBUG)
+ Log.e(TAG, "Fail in preference change listener", t);
}
}
}
@@ -183,7 +186,7 @@ public final class XSharedPreferences implements SharedPreferences {
}
}
if (newModule) {
- mFile = new File(serviceClient.getPrefsPath( packageName ), prefFileName + ".xml");
+ mFile = new File(serviceClient.getPrefsPath(packageName), prefFileName + ".xml");
} else {
mFile = new File(Environment.getDataDirectory(), "data/" + packageName + "/shared_prefs/" + prefFileName + ".xml");
}
@@ -209,7 +212,8 @@ public final class XSharedPreferences implements SharedPreferences {
if (sWatcherDaemon == null || !sWatcherDaemon.isAlive()) {
initWatcherDaemon();
}
- if (BuildConfig.DEBUG) Log.d(TAG, "tryRegisterWatcher: registered file watcher for " + path);
+ if (BuildConfig.DEBUG)
+ Log.d(TAG, "tryRegisterWatcher: registered file watcher for " + path);
} catch (AccessDeniedException accDeniedEx) {
if (BuildConfig.DEBUG) Log.e(TAG, "tryRegisterWatcher: access denied to " + path);
} catch (Exception e) {
@@ -232,7 +236,8 @@ public final class XSharedPreferences implements SharedPreferences {
if (!atLeastOneValid) {
try {
sWatcher.close();
- } catch (Exception ignore) { }
+ } catch (Exception ignore) {
+ }
}
}
}
@@ -522,7 +527,7 @@ public final class XSharedPreferences implements SharedPreferences {
if (listener == null)
throw new IllegalArgumentException("listener cannot be null");
- synchronized(this) {
+ synchronized (this) {
if (mListeners.put(listener, sContent) == null) {
tryRegisterWatcher();
}
@@ -537,7 +542,7 @@ public final class XSharedPreferences implements SharedPreferences {
*/
@Override
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
- synchronized(this) {
+ synchronized (this) {
if (mListeners.remove(listener) != null && mListeners.isEmpty()) {
tryUnregisterWatcher();
}
diff --git a/core/src/main/java/de/robv/android/xposed/XposedBridge.java b/core/src/main/java/de/robv/android/xposed/XposedBridge.java
index 9842e31c..ac58958f 100644
--- a/core/src/main/java/de/robv/android/xposed/XposedBridge.java
+++ b/core/src/main/java/de/robv/android/xposed/XposedBridge.java
@@ -20,11 +20,16 @@
package de.robv.android.xposed;
+import static de.robv.android.xposed.XposedHelpers.setObjectField;
+
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.Log;
import org.lsposed.lspd.BuildConfig;
+import org.lsposed.lspd.nativebridge.ModuleLogger;
+import org.lsposed.lspd.nativebridge.ResourcesHook;
+import org.lsposed.lspd.yahfa.hooker.YahfaHooker;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Executable;
@@ -43,12 +48,6 @@ import java.util.Set;
import de.robv.android.xposed.callbacks.XC_InitPackageResources;
import de.robv.android.xposed.callbacks.XC_InitZygote;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
-import org.lsposed.lspd.nativebridge.ModuleLogger;
-import org.lsposed.lspd.nativebridge.ResourcesHook;
-import org.lsposed.lspd.yahfa.dexmaker.DynamicBridge;
-import org.lsposed.lspd.yahfa.hooker.YahfaHooker;
-
-import static de.robv.android.xposed.XposedHelpers.setObjectField;
/**
* This class contains most of Xposed's central logic, such as initialization and callbacks used by
@@ -56,377 +55,373 @@ import static de.robv.android.xposed.XposedHelpers.setObjectField;
*/
@SuppressWarnings("JniMissingFunction")
public final class XposedBridge {
- /**
- * The system class loader which can be used to locate Android framework classes.
- * Application classes cannot be retrieved from it.
- *
- * @see ClassLoader#getSystemClassLoader
- */
- public static final ClassLoader BOOTCLASSLOADER = XposedBridge.class.getClassLoader();
+ /**
+ * The system class loader which can be used to locate Android framework classes.
+ * Application classes cannot be retrieved from it.
+ *
+ * @see ClassLoader#getSystemClassLoader
+ */
+ public static final ClassLoader BOOTCLASSLOADER = XposedBridge.class.getClassLoader();
- /** @hide */
- public static final String TAG = "LSPosed-Bridge";
+ /**
+ * @hide
+ */
+ public static final String TAG = "LSPosed-Bridge";
- /** @deprecated Use {@link #getXposedVersion()} instead. */
- @Deprecated
- public static int XPOSED_BRIDGE_VERSION;
+ /**
+ * @deprecated Use {@link #getXposedVersion()} instead.
+ */
+ @Deprecated
+ public static int XPOSED_BRIDGE_VERSION;
- /*package*/ static boolean isZygote = true; // ed: RuntimeInit.main() tool process not supported yet
+ private static final Object[] EMPTY_ARRAY = new Object[0];
- // This field is set "magically" on MIUI.
- /*package*/ static long BOOT_START_TIME;
+ // built-in handlers
+ private static final Map> sHookedMethodCallbacks = new NoValuesHashMap<>();
+ public static final CopyOnWriteSortedSet sLoadedPackageCallbacks = new CopyOnWriteSortedSet<>();
+ /*package*/ static final CopyOnWriteSortedSet sInitPackageResourcesCallbacks = new CopyOnWriteSortedSet<>();
+ /*package*/ static final CopyOnWriteSortedSet sInitZygoteCallbacks = new CopyOnWriteSortedSet<>();
- private static final Object[] EMPTY_ARRAY = new Object[0];
+ private XposedBridge() {
+ }
- // built-in handlers
- private static final Map> sHookedMethodCallbacks = new NoValuesHashMap<>();
- public static final CopyOnWriteSortedSet sLoadedPackageCallbacks = new CopyOnWriteSortedSet<>();
- /*package*/ static final CopyOnWriteSortedSet sInitPackageResourcesCallbacks = new CopyOnWriteSortedSet<>();
- /*package*/ static final CopyOnWriteSortedSet sInitZygoteCallbacks = new CopyOnWriteSortedSet<>();
+ public static volatile ClassLoader dummyClassLoader = null;
- private XposedBridge() {}
-
- public static volatile ClassLoader dummyClassLoader = null;
-
- public static void initXResources() {
+ public static void initXResources() {
if (dummyClassLoader != null) {
- return;
- }
- try {
- Resources res = Resources.getSystem();
- Class> resClass = res.getClass();
- Class> taClass = TypedArray.class;
- try {
- TypedArray ta = res.obtainTypedArray(res.getIdentifier(
- "preloaded_drawables", "array", "android"));
- taClass = ta.getClass();
- ta.recycle();
- } catch (Resources.NotFoundException nfe) {
- XposedBridge.log(nfe);
- }
- ResourcesHook.removeFinalFlagNative(resClass);
- ResourcesHook.removeFinalFlagNative(taClass);
- ClassLoader myCL = XposedBridge.class.getClassLoader();
- dummyClassLoader = ResourcesHook.buildDummyClassLoader(myCL.getParent(), resClass, taClass);
- dummyClassLoader.loadClass("xposed.dummy.XResourcesSuperClass");
- dummyClassLoader.loadClass("xposed.dummy.XTypedArraySuperClass");
- setObjectField(myCL, "parent", dummyClassLoader);
- } catch (Throwable throwable) {
- XposedBridge.log(throwable);
- XposedInit.disableResources = true;
- }
- }
+ return;
+ }
+ try {
+ Resources res = Resources.getSystem();
+ Class> resClass = res.getClass();
+ Class> taClass = TypedArray.class;
+ try {
+ TypedArray ta = res.obtainTypedArray(res.getIdentifier(
+ "preloaded_drawables", "array", "android"));
+ taClass = ta.getClass();
+ ta.recycle();
+ } catch (Resources.NotFoundException nfe) {
+ XposedBridge.log(nfe);
+ }
+ ResourcesHook.removeFinalFlagNative(resClass);
+ ResourcesHook.removeFinalFlagNative(taClass);
+ ClassLoader myCL = XposedBridge.class.getClassLoader();
+ dummyClassLoader = ResourcesHook.buildDummyClassLoader(myCL.getParent(), resClass, taClass);
+ dummyClassLoader.loadClass("xposed.dummy.XResourcesSuperClass");
+ dummyClassLoader.loadClass("xposed.dummy.XTypedArraySuperClass");
+ setObjectField(myCL, "parent", dummyClassLoader);
+ } catch (Throwable throwable) {
+ XposedBridge.log(throwable);
+ XposedInit.disableResources = true;
+ }
+ }
- /**
- * Returns the currently installed version of the Xposed framework.
- */
- public static int getXposedVersion() {
- return BuildConfig.API_CODE;
- }
+ /**
+ * Returns the currently installed version of the Xposed framework.
+ */
+ public static int getXposedVersion() {
+ return BuildConfig.API_CODE;
+ }
- /**
- * Writes a message to the Xposed modules log.
- *
- *
DON'T FLOOD THE LOG!!! This is only meant for error logging.
- * If you want to write information/debug messages, use logcat.
- *
- * @param text The log message.
- */
- public synchronized static void log(String text) {
- Log.i(TAG, text);
- ModuleLogger.log(text, false);
- }
+ /**
+ * Writes a message to the Xposed modules log.
+ *
+ *
DON'T FLOOD THE LOG!!! This is only meant for error logging.
+ * If you want to write information/debug messages, use logcat.
+ *
+ * @param text The log message.
+ */
+ public synchronized static void log(String text) {
+ Log.i(TAG, text);
+ ModuleLogger.log(text, false);
+ }
- /**
- * Logs a stack trace to the Xposed modules log.
- *
- *
DON'T FLOOD THE LOG!!! This is only meant for error logging.
- * If you want to write information/debug messages, use logcat.
- *
- * @param t The Throwable object for the stack trace.
- */
- public synchronized static void log(Throwable t) {
- String logStr = Log.getStackTraceString(t);
- Log.e(TAG, logStr);
- ModuleLogger.log(logStr, true);
- }
+ /**
+ * Logs a stack trace to the Xposed modules log.
+ *
+ *
DON'T FLOOD THE LOG!!! This is only meant for error logging.
+ * If you want to write information/debug messages, use logcat.
+ *
+ * @param t The Throwable object for the stack trace.
+ */
+ public synchronized static void log(Throwable t) {
+ String logStr = Log.getStackTraceString(t);
+ Log.e(TAG, logStr);
+ ModuleLogger.log(logStr, true);
+ }
- /**
- * Hook any method (or constructor) with the specified callback. See below for some wrappers
- * that make it easier to find a method/constructor in one step.
- *
- * @param hookMethod The method to be hooked.
- * @param callback The callback to be executed when the hooked method is called.
- * @return An object that can be used to remove the hook.
- *
- * @see XposedHelpers#findAndHookMethod(String, ClassLoader, String, Object...)
- * @see XposedHelpers#findAndHookMethod(Class, String, Object...)
- * @see #hookAllMethods
- * @see XposedHelpers#findAndHookConstructor(String, ClassLoader, Object...)
- * @see XposedHelpers#findAndHookConstructor(Class, Object...)
- * @see #hookAllConstructors
- */
- public static XC_MethodHook.Unhook hookMethod(Member hookMethod, XC_MethodHook callback) {
- if (!(hookMethod instanceof Executable)) {
- throw new IllegalArgumentException("Only methods and constructors can be hooked: " + hookMethod.toString());
- }
- // No check interface because there may be default methods
+ /**
+ * Hook any method (or constructor) with the specified callback. See below for some wrappers
+ * that make it easier to find a method/constructor in one step.
+ *
+ * @param hookMethod The method to be hooked.
+ * @param callback The callback to be executed when the hooked method is called.
+ * @return An object that can be used to remove the hook.
+ * @see XposedHelpers#findAndHookMethod(String, ClassLoader, String, Object...)
+ * @see XposedHelpers#findAndHookMethod(Class, String, Object...)
+ * @see #hookAllMethods
+ * @see XposedHelpers#findAndHookConstructor(String, ClassLoader, Object...)
+ * @see XposedHelpers#findAndHookConstructor(Class, Object...)
+ * @see #hookAllConstructors
+ */
+ public static XC_MethodHook.Unhook hookMethod(Member hookMethod, XC_MethodHook callback) {
+ if (!(hookMethod instanceof Executable)) {
+ throw new IllegalArgumentException("Only methods and constructors can be hooked: " + hookMethod.toString());
+ }
+ // No check interface because there may be default methods
/*else if (hookMethod.getDeclaringClass().isInterface()) {
throw new IllegalArgumentException("Cannot hook interfaces: " + hookMethod.toString());
}*/
- else if (Modifier.isAbstract(hookMethod.getModifiers())) {
- throw new IllegalArgumentException("Cannot hook abstract methods: " + hookMethod.toString());
- }
+ else if (Modifier.isAbstract(hookMethod.getModifiers())) {
+ throw new IllegalArgumentException("Cannot hook abstract methods: " + hookMethod.toString());
+ }
- Executable targetMethod = (Executable) hookMethod;
+ Executable targetMethod = (Executable) hookMethod;
- if (callback == null) {
- throw new IllegalArgumentException("callback should not be null!");
- }
+ if (callback == null) {
+ throw new IllegalArgumentException("callback should not be null!");
+ }
- boolean newMethod = false;
- CopyOnWriteSortedSet callbacks;
- synchronized (sHookedMethodCallbacks) {
- callbacks = sHookedMethodCallbacks.get(targetMethod);
- if (callbacks == null) {
- callbacks = new CopyOnWriteSortedSet<>();
- sHookedMethodCallbacks.put(targetMethod, callbacks);
- newMethod = true;
- }
- }
- callbacks.add(callback);
+ boolean newMethod = false;
+ CopyOnWriteSortedSet callbacks;
+ synchronized (sHookedMethodCallbacks) {
+ callbacks = sHookedMethodCallbacks.get(targetMethod);
+ if (callbacks == null) {
+ callbacks = new CopyOnWriteSortedSet<>();
+ sHookedMethodCallbacks.put(targetMethod, callbacks);
+ newMethod = true;
+ }
+ }
+ callbacks.add(callback);
- if (newMethod) {
- AdditionalHookInfo additionalInfo = new AdditionalHookInfo(callbacks);
+ if (newMethod) {
+ AdditionalHookInfo additionalInfo = new AdditionalHookInfo(callbacks);
if (!YahfaHooker.shouldDelayHook(targetMethod)) {
- YahfaHooker.hookMethod(targetMethod, additionalInfo);
- } else {
- PendingHooks.recordPendingMethod((Method)hookMethod, additionalInfo);
- }
+ YahfaHooker.hookMethod(targetMethod, additionalInfo);
+ } else {
+ PendingHooks.recordPendingMethod((Method) hookMethod, additionalInfo);
+ }
}
return callback.new Unhook(hookMethod);
- }
+ }
- /**
- * Removes the callback for a hooked method/constructor.
- *
- * @deprecated Use {@link XC_MethodHook.Unhook#unhook} instead. An instance of the {@code Unhook}
- * class is returned when you hook the method.
- *
- * @param hookMethod The method for which the callback should be removed.
- * @param callback The reference to the callback as specified in {@link #hookMethod}.
- */
- @Deprecated
- public static void unhookMethod(Member hookMethod, XC_MethodHook callback) {
- CopyOnWriteSortedSet callbacks;
- synchronized (sHookedMethodCallbacks) {
- callbacks = sHookedMethodCallbacks.get(hookMethod);
- if (callbacks == null)
- return;
- }
- callbacks.remove(callback);
- }
+ /**
+ * Removes the callback for a hooked method/constructor.
+ *
+ * @param hookMethod The method for which the callback should be removed.
+ * @param callback The reference to the callback as specified in {@link #hookMethod}.
+ * @deprecated Use {@link XC_MethodHook.Unhook#unhook} instead. An instance of the {@code Unhook}
+ * class is returned when you hook the method.
+ */
+ @Deprecated
+ public static void unhookMethod(Member hookMethod, XC_MethodHook callback) {
+ CopyOnWriteSortedSet callbacks;
+ synchronized (sHookedMethodCallbacks) {
+ callbacks = sHookedMethodCallbacks.get(hookMethod);
+ if (callbacks == null)
+ return;
+ }
+ callbacks.remove(callback);
+ }
- /**
- * Hooks all methods with a certain name that were declared in the specified class. Inherited
- * methods and constructors are not considered. For constructors, use
- * {@link #hookAllConstructors} instead.
- *
- * @param hookClass The class to check for declared methods.
- * @param methodName The name of the method(s) to hook.
- * @param callback The callback to be executed when the hooked methods are called.
- * @return A set containing one object for each found method which can be used to unhook it.
- */
- @SuppressWarnings("UnusedReturnValue")
- public static Set hookAllMethods(Class> hookClass, String methodName, XC_MethodHook callback) {
- Set unhooks = new HashSet<>();
- for (Member method : hookClass.getDeclaredMethods())
- if (method.getName().equals(methodName))
- unhooks.add(hookMethod(method, callback));
- return unhooks;
- }
+ /**
+ * Hooks all methods with a certain name that were declared in the specified class. Inherited
+ * methods and constructors are not considered. For constructors, use
+ * {@link #hookAllConstructors} instead.
+ *
+ * @param hookClass The class to check for declared methods.
+ * @param methodName The name of the method(s) to hook.
+ * @param callback The callback to be executed when the hooked methods are called.
+ * @return A set containing one object for each found method which can be used to unhook it.
+ */
+ @SuppressWarnings("UnusedReturnValue")
+ public static Set hookAllMethods(Class> hookClass, String methodName, XC_MethodHook callback) {
+ Set unhooks = new HashSet<>();
+ for (Member method : hookClass.getDeclaredMethods())
+ if (method.getName().equals(methodName))
+ unhooks.add(hookMethod(method, callback));
+ return unhooks;
+ }
- /**
- * Hook all constructors of the specified class.
- *
- * @param hookClass The class to check for constructors.
- * @param callback The callback to be executed when the hooked constructors are called.
- * @return A set containing one object for each found constructor which can be used to unhook it.
- */
- @SuppressWarnings("UnusedReturnValue")
- public static Set hookAllConstructors(Class> hookClass, XC_MethodHook callback) {
- Set unhooks = new HashSet<>();
- for (Member constructor : hookClass.getDeclaredConstructors())
- unhooks.add(hookMethod(constructor, callback));
- return unhooks;
- }
+ /**
+ * Hook all constructors of the specified class.
+ *
+ * @param hookClass The class to check for constructors.
+ * @param callback The callback to be executed when the hooked constructors are called.
+ * @return A set containing one object for each found constructor which can be used to unhook it.
+ */
+ @SuppressWarnings("UnusedReturnValue")
+ public static Set hookAllConstructors(Class> hookClass, XC_MethodHook callback) {
+ Set unhooks = new HashSet<>();
+ for (Member constructor : hookClass.getDeclaredConstructors())
+ unhooks.add(hookMethod(constructor, callback));
+ return unhooks;
+ }
- /**
- * Adds a callback to be executed when an app ("Android package") is loaded.
- *
- *
You probably don't need to call this. Simply implement {@link IXposedHookLoadPackage}
- * in your module class and Xposed will take care of registering it as a callback.
- *
- * @param callback The callback to be executed.
- * @hide
- */
- public static void hookLoadPackage(XC_LoadPackage callback) {
- synchronized (sLoadedPackageCallbacks) {
- sLoadedPackageCallbacks.add(callback);
- }
- }
+ /**
+ * Adds a callback to be executed when an app ("Android package") is loaded.
+ *
+ *
You probably don't need to call this. Simply implement {@link IXposedHookLoadPackage}
+ * in your module class and Xposed will take care of registering it as a callback.
+ *
+ * @param callback The callback to be executed.
+ * @hide
+ */
+ public static void hookLoadPackage(XC_LoadPackage callback) {
+ synchronized (sLoadedPackageCallbacks) {
+ sLoadedPackageCallbacks.add(callback);
+ }
+ }
- public static void clearLoadedPackages() {
- synchronized (sLoadedPackageCallbacks) {
- sLoadedPackageCallbacks.clear();
- }
- }
+ public static void clearLoadedPackages() {
+ synchronized (sLoadedPackageCallbacks) {
+ sLoadedPackageCallbacks.clear();
+ }
+ }
- /**
- * Adds a callback to be executed when the resources for an app are initialized.
- *
- *
You probably don't need to call this. Simply implement {@link IXposedHookInitPackageResources}
- * in your module class and Xposed will take care of registering it as a callback.
- *
- * @param callback The callback to be executed.
- * @hide
- */
- public static void hookInitPackageResources(XC_InitPackageResources callback) {
- synchronized (sInitPackageResourcesCallbacks) {
- sInitPackageResourcesCallbacks.add(callback);
- }
- }
+ /**
+ * Adds a callback to be executed when the resources for an app are initialized.
+ *
+ *
You probably don't need to call this. Simply implement {@link IXposedHookInitPackageResources}
+ * in your module class and Xposed will take care of registering it as a callback.
+ *
+ * @param callback The callback to be executed.
+ * @hide
+ */
+ public static void hookInitPackageResources(XC_InitPackageResources callback) {
+ synchronized (sInitPackageResourcesCallbacks) {
+ sInitPackageResourcesCallbacks.add(callback);
+ }
+ }
- public static void hookInitZygote(XC_InitZygote callback) {
- synchronized (sInitZygoteCallbacks) {
- sInitZygoteCallbacks.add(callback);
- }
- }
+ public static void hookInitZygote(XC_InitZygote callback) {
+ synchronized (sInitZygoteCallbacks) {
+ sInitZygoteCallbacks.add(callback);
+ }
+ }
- /**
- * Basically the same as {@link Method#invoke}, but calls the original method
- * as it was before the interception by Xposed. Also, access permissions are not checked.
- *
- *
There are very few cases where this method is needed. A common mistake is
- * to replace a method and then invoke the original one based on dynamic conditions. This
- * creates overhead and skips further hooks by other modules. Instead, just hook (don't replace)
- * the method and call {@code param.setResult(null)} in {@link XC_MethodHook#beforeHookedMethod}
- * if the original method should be skipped.
- *
- * @param method The method to be called.
- * @param thisObject For non-static calls, the "this" pointer, otherwise {@code null}.
- * @param args Arguments for the method call as Object[] array.
- * @return The result returned from the invoked method.
- * @throws NullPointerException
- * if {@code receiver == null} for a non-static method
- * @throws IllegalAccessException
- * if this method is not accessible (see {@link AccessibleObject})
- * @throws IllegalArgumentException
- * if the number of arguments doesn't match the number of parameters, the receiver
- * is incompatible with the declaring class, or an argument could not be unboxed
- * or converted by a widening conversion to the corresponding parameter type
- * @throws InvocationTargetException
- * if an exception was thrown by the invoked method
- */
- public static Object invokeOriginalMethod(Member method, Object thisObject, Object[] args)
- throws Throwable {
- if (args == null) {
- args = EMPTY_ARRAY;
- }
+ /**
+ * Basically the same as {@link Method#invoke}, but calls the original method
+ * as it was before the interception by Xposed. Also, access permissions are not checked.
+ *
+ *
There are very few cases where this method is needed. A common mistake is
+ * to replace a method and then invoke the original one based on dynamic conditions. This
+ * creates overhead and skips further hooks by other modules. Instead, just hook (don't replace)
+ * the method and call {@code param.setResult(null)} in {@link XC_MethodHook#beforeHookedMethod}
+ * if the original method should be skipped.
+ *
+ * @param method The method to be called.
+ * @param thisObject For non-static calls, the "this" pointer, otherwise {@code null}.
+ * @param args Arguments for the method call as Object[] array.
+ * @return The result returned from the invoked method.
+ * @throws NullPointerException if {@code receiver == null} for a non-static method
+ * @throws IllegalAccessException if this method is not accessible (see {@link AccessibleObject})
+ * @throws IllegalArgumentException if the number of arguments doesn't match the number of parameters, the receiver
+ * is incompatible with the declaring class, or an argument could not be unboxed
+ * or converted by a widening conversion to the corresponding parameter type
+ * @throws InvocationTargetException if an exception was thrown by the invoked method
+ */
+ public static Object invokeOriginalMethod(Member method, Object thisObject, Object[] args)
+ throws Throwable {
+ if (args == null) {
+ args = EMPTY_ARRAY;
+ }
- if (!(method instanceof Executable)) {
- throw new IllegalArgumentException("method must be of type Method or Constructor");
- }
+ if (!(method instanceof Executable)) {
+ throw new IllegalArgumentException("method must be of type Method or Constructor");
+ }
- return YahfaHooker.invokeOriginalMethod((Executable) method, thisObject, args);
- }
+ return YahfaHooker.invokeOriginalMethod((Executable) method, thisObject, args);
+ }
- private static class NoValuesHashMap extends HashMap {
- @Override
- public Collection values() {
- return Collections.EMPTY_LIST;
- }
+ private static class NoValuesHashMap extends HashMap {
+ @Override
+ public Collection values() {
+ return Collections.EMPTY_LIST;
+ }
- @Override
- public void clear() {
+ @Override
+ public void clear() {
- }
+ }
- @Override
- public Set keySet() {
- return Collections.EMPTY_SET;
- }
+ @Override
+ public Set keySet() {
+ return Collections.EMPTY_SET;
+ }
- @Override
- public Set> entrySet() {
- return Collections.EMPTY_SET;
- }
+ @Override
+ public Set> entrySet() {
+ return Collections.EMPTY_SET;
+ }
- @Override
- public int size() {
- return 0;
- }
+ @Override
+ public int size() {
+ return 0;
+ }
- @Override
- public boolean isEmpty() {
- return true;
- }
- }
+ @Override
+ public boolean isEmpty() {
+ return true;
+ }
+ }
- /** @hide */
- public static final class CopyOnWriteSortedSet {
- private transient volatile Object[] elements = EMPTY_ARRAY;
+ /**
+ * @hide
+ */
+ public static final class CopyOnWriteSortedSet {
+ private transient volatile Object[] elements = EMPTY_ARRAY;
- @SuppressWarnings("UnusedReturnValue")
- public synchronized boolean add(E e) {
- int index = indexOf(e);
- if (index >= 0)
- return false;
+ @SuppressWarnings("UnusedReturnValue")
+ public synchronized boolean add(E e) {
+ int index = indexOf(e);
+ if (index >= 0)
+ return false;
- Object[] newElements = new Object[elements.length + 1];
- System.arraycopy(elements, 0, newElements, 0, elements.length);
- newElements[elements.length] = e;
- Arrays.sort(newElements);
- elements = newElements;
- return true;
- }
+ Object[] newElements = new Object[elements.length + 1];
+ System.arraycopy(elements, 0, newElements, 0, elements.length);
+ newElements[elements.length] = e;
+ Arrays.sort(newElements);
+ elements = newElements;
+ return true;
+ }
- @SuppressWarnings("UnusedReturnValue")
- public synchronized boolean remove(E e) {
- int index = indexOf(e);
- if (index == -1)
- return false;
+ @SuppressWarnings("UnusedReturnValue")
+ public synchronized boolean remove(E e) {
+ int index = indexOf(e);
+ if (index == -1)
+ return false;
- Object[] newElements = new Object[elements.length - 1];
- System.arraycopy(elements, 0, newElements, 0, index);
- System.arraycopy(elements, index + 1, newElements, index, elements.length - index - 1);
- elements = newElements;
- return true;
- }
+ Object[] newElements = new Object[elements.length - 1];
+ System.arraycopy(elements, 0, newElements, 0, index);
+ System.arraycopy(elements, index + 1, newElements, index, elements.length - index - 1);
+ elements = newElements;
+ return true;
+ }
- private int indexOf(Object o) {
- for (int i = 0; i < elements.length; i++) {
- if (o.equals(elements[i]))
- return i;
- }
- return -1;
- }
+ private int indexOf(Object o) {
+ for (int i = 0; i < elements.length; i++) {
+ if (o.equals(elements[i]))
+ return i;
+ }
+ return -1;
+ }
- public Object[] getSnapshot() {
- return elements;
- }
+ public Object[] getSnapshot() {
+ return elements;
+ }
- public synchronized void clear() {
- elements = EMPTY_ARRAY;
- }
- }
+ public synchronized void clear() {
+ elements = EMPTY_ARRAY;
+ }
+ }
- public static class AdditionalHookInfo {
- public final CopyOnWriteSortedSet callbacks;
+ public static class AdditionalHookInfo {
+ public final CopyOnWriteSortedSet callbacks;
- private AdditionalHookInfo(CopyOnWriteSortedSet callbacks) {
- this.callbacks = callbacks;
- }
- }
+ private AdditionalHookInfo(CopyOnWriteSortedSet callbacks) {
+ this.callbacks = callbacks;
+ }
+ }
}
diff --git a/core/src/main/java/de/robv/android/xposed/XposedHelpers.java b/core/src/main/java/de/robv/android/xposed/XposedHelpers.java
index 8950ba0d..4e3dee26 100644
--- a/core/src/main/java/de/robv/android/xposed/XposedHelpers.java
+++ b/core/src/main/java/de/robv/android/xposed/XposedHelpers.java
@@ -50,1596 +50,1703 @@ import org.apache.commons.lang3.reflect.MemberUtilsX;
* Helpers that simplify hooking and calling methods/constructors, getting and settings fields, ...
*/
public final class XposedHelpers {
- private XposedHelpers() {}
-
- private static final HashMap fieldCache = new HashMap<>();
- private static final HashMap methodCache = new HashMap<>();
- private static final HashMap> constructorCache = new HashMap<>();
- private static final WeakHashMap