Convert Figma logo to code with AI

alibaba logodexposed

dexposed enable 'god' mode for single android application.

4,506
1,069
4,506
19

Top Related Projects

4,412

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.

11,610

Matrix is a plugin style, non-invasive APM system developed by WeChat.

Quick Overview

Dexposed is an open-source Android framework that provides a powerful and flexible runtime instrumentation solution. It allows developers to dynamically hook into and modify the behavior of Android applications without the need for recompilation or root access.

Pros

  • Runtime Instrumentation: Dexposed enables developers to instrument and modify the behavior of Android applications at runtime, without the need for recompilation or root access.
  • Flexible Hooking: The framework provides a flexible and extensible hooking mechanism, allowing developers to intercept and modify method calls, return values, and exceptions.
  • Compatibility: Dexposed is compatible with a wide range of Android versions, from 2.3 (Gingerbread) to the latest versions.
  • Open-Source: The project is open-source, allowing developers to contribute, extend, and customize the framework to suit their specific needs.

Cons

  • Complexity: Dexposed can be complex to set up and configure, especially for developers who are new to runtime instrumentation or Android development.
  • Performance Impact: Depending on the level of instrumentation and the number of hooks, Dexposed may have a performance impact on the target application.
  • Potential Stability Issues: As a runtime instrumentation framework, Dexposed may introduce stability issues or compatibility problems with certain Android applications or versions.
  • Limited Documentation: The project's documentation could be more comprehensive, making it challenging for new users to get started.

Code Examples

Here are a few code examples demonstrating the usage of Dexposed:

Hooking a Method

// Hook the "onCreate" method of an Activity
XposedBridge.hookMethod(
    findClass("com.example.MyActivity", null).getDeclaredMethod("onCreate", Bundle.class),
    new XC_MethodHook() {
        @Override
        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
            // Perform custom logic before the original method is called
            Log.d("MyActivity", "onCreate called");
        }

        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            // Perform custom logic after the original method is called
            Log.d("MyActivity", "onCreate completed");
        }
    }
);

Modifying Method Arguments

// Hook the "sendMessage" method of a class and modify the arguments
XposedBridge.hookMethod(
    findClass("com.example.MessageSender", null).getDeclaredMethod("sendMessage", String.class),
    new XC_MethodHook() {
        @Override
        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
            // Modify the message argument before the original method is called
            param.args[0] = "Modified message";
        }
    }
);

Modifying Method Return Values

// Hook the "getDeviceId" method of the TelephonyManager class and modify the return value
XposedBridge.hookMethod(
    findClass("android.telephony.TelephonyManager", null).getDeclaredMethod("getDeviceId"),
    new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            // Modify the return value of the original method
            param.setResult("Modified device ID");
        }
    }
);

Getting Started

To get started with Dexposed, follow these steps:

  1. Download the Dexposed framework from the GitHub repository.
  2. Integrate the Dexposed library into your Android project by adding the necessary dependencies and configurations.
  3. Create a new Xposed module by extending the XposedBridge class and implementing the initZygote and handleLoadPackage methods.
  4. Use the XposedBridge.hookMethod method to hook into the desired methods and modify their behavior as needed.
  5. Build and install your Xposed module on the target Android device.

Please refer to the project's documentation for more detailed instructions and best practices.

Competitor Comparisons

4,412

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.

Pros of Robust

  • Robust provides a runtime patch solution that can be applied to running apps without the need for recompilation or reinstallation.
  • Robust supports a wide range of Android versions, from 4.0 to the latest version.
  • Robust has a well-documented and active community, with regular updates and bug fixes.

Cons of Robust

  • Robust is a larger and more complex solution compared to Dexposed, which may make it more difficult to set up and maintain.
  • Robust may have a higher performance overhead compared to Dexposed, as it needs to manage the runtime patching process.
  • Robust is primarily focused on Android, while Dexposed can be used on both Android and Java applications.

Code Comparison

Dexposed:

public static void hookMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Object instance, Object... args) {
    try {
        Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
        DexposedBridge.hookMethod(method, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                // Your code here
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                // Your code here
            }
        });
        method.invoke(instance, args);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Robust:

public static void patchMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Object instance, Object... args) {
    try {
        Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
        Robust.patchMethod(method, new MethodPatch() {
            @Override
            public void patch(MethodInfo methodInfo, MethodProxy methodProxy, Object[] args) throws Throwable {
                // Your code here
            }
        });
        method.invoke(instance, args);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

The main difference between the two code snippets is the way they hook or patch the method. Dexposed uses the XC_MethodHook interface to define the before and after hooks, while Robust uses the MethodPatch interface to define the patching logic.

11,610

Matrix is a plugin style, non-invasive APM system developed by WeChat.

Pros of Matrix

  • Matrix provides a comprehensive set of tools for Android app performance monitoring and optimization, including ANR (Application Not Responding) detection, battery monitoring, and network traffic analysis.
  • Matrix offers a modular design, allowing developers to selectively integrate the features they need, reducing the overall impact on their app.
  • Matrix's performance monitoring capabilities are more extensive than those provided by Dexposed, covering a wider range of app performance metrics.

Cons of Matrix

  • Matrix has a larger codebase and a more complex setup process compared to Dexposed, which may be a barrier for some developers.
  • Matrix's integration with Android Studio is not as seamless as Dexposed, which provides a more streamlined development experience.
  • Matrix may have a higher performance impact on the app, depending on the specific features and configurations used.

Code Comparison

Dexposed:

public static void hook(String className, String methodName, Object... parameterTypes) {
    try {
        Class<?> clazz = Class.forName(className);
        Method method = clazz.getDeclaredMethod(methodName, (Class<?>[]) parameterTypes);
        method.setAccessible(true);
        DexposedBridge.hookMethod(method, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                // Your code here
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                // Your code here
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Matrix:

public static void installMatrix(Application application) {
    MatrixOptions options = new MatrixOptions();
    options.setAppID("your_app_id");
    options.setEnableAppenderLog(true);
    options.setEnableAppenderTraceLog(true);
    options.setEnableAppenderConsoleLog(true);
    options.setEnableAppenderFileLog(true);
    options.setEnableAppenderUploadLog(true);
    Matrix.init(options);
    Matrix.with(application)
          .getPluginByClass(ANRPlugin.class)
          .start();
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

What is it?

Download Software License Join the chat at https://gitter.im/alibaba/dexposed

Dexposed is a powerful yet non-invasive runtime AOP (Aspect-oriented Programming) framework for Android app development, based on the work of open-source Xposed framework project.

The AOP of Dexposed is implemented purely non-invasive, without any annotation processor, weaver or bytecode rewriter. The integration is as simple as loading a small JNI library in just one line of code at the initialization phase of your app.

Not only the code of your app, but also the code of Android framework that running in your app process can be hooked. This feature is extremely useful in Android development as we developers heavily rely on the fragmented old versions of Android platform (SDK).

Together with dynamic class loading, a small piece of compiled Java AOP code can be loaded into the running app, effectively altering the behavior of the target app without restart.

Typical use-cases

  • Classic AOP programming
  • Instrumentation (for testing, performance monitoring and etc.)
  • Online hot patch to fix critical, emergent or security bugs
  • SDK hooking for a better development experience

Integration

Directly add dexposed aar to your project as compile libraries, it contains a jar file "dexposedbridge.jar" two so files "libdexposed.so libdexposed_l.so" from 'dexposed' directory.

Gradle dependency like following:

	dependencies {
	    compile 'com.taobao.android:dexposed:0.1.1@aar'
	}

Insert the following line into the initialization phase of your app, as early as possible:

    public class MyApplication extends Application {

        @Override public void onCreate() {        
            // Check whether current device is supported (also initialize Dexposed framework if not yet)
            if (DexposedBridge.canDexposed(this)) {
                // Use Dexposed to kick off AOP stuffs.
                ...
            }
        }
        ...
    }

It's done.

Basic usage

There are three injection points for a given method: before, after, replace.

Example 1: Attach a piece of code before and after all occurrences of Activity.onCreate(Bundle).

        // Target class, method with parameter types, followed by the hook callback (XC_MethodHook).
		DexposedBridge.findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodHook() {
        
            // To be invoked before Activity.onCreate().
			@Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
				// "thisObject" keeps the reference to the instance of target class.
				Activity instance = (Activity) param.thisObject;
        
				// The array args include all the parameters.
				Bundle bundle = (Bundle) param.args[0];
				Intent intent = new Intent();
				// XposedHelpers provide useful utility methods.
				XposedHelpers.setObjectField(param.thisObject, "mIntent", intent);
		
				// Calling setResult() will bypass the original method body use the result as method return value directly.
				if (bundle.containsKey("return"))
					param.setResult(null);
			}
					
			// To be invoked after Activity.onCreate()
			@Override protected void afterHookedMethod(MethodHookParam param) throws Throwable {
		        XposedHelpers.callMethod(param.thisObject, "sampleMethod", 2);
			}
		});

Example 2: Replace the original body of the target method.

		DexposedBridge.findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodReplacement() {
		
			@Override protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
				// Re-writing the method logic outside the original method context is a bit tricky but still viable.
				...
			}

		});

Checkout the example project to find out more.

Support

Dexposed support all dalvik runtime arm architecture devices from Android 2.3 to 4.4 (no include 3.0). The stability has been proved in our long term product practice.

Follow is support status.

RuntimeAndroid VersionSupport
Dalvik2.2Not Test
Dalvik2.3Yes
Dalvik3.0No
Dalvik4.0-4.4Yes
ART5.0Testing
ART5.1No
ARTMNo

Contribute

We are open to constructive contributions from the community, especially pull request and quality bug report. Currently, the support for new Android Runtime (ART) is still in early beta stage, we value your help to test or improve the implementation.

Dexposed is aimed to be lightweight, transparent and productive. All improvements with these principal in mind are welcome. At the same time, we are actively exploring more potentially valuable use-cases and building powerful tools based upon Dexposed. We're interested in any ideas expanding the use-cases and grateful for community developed tools on top of Dexposed.