Get the App
SLTechnology News&Howtos  ›  Development  › 

How to develop entry-level Xposed plug-ins

Shulou Source: shulou.com Published: 2022-06-03 06:11:48 10月02日 Update

This article shows you how to develop entry-level Xposed plug-ins, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Preface

The use of Xposed is needless to say, it can hook any code written by java, modify and replace the resource files inside apk.

As for how to develop a plug-in for XPosed, the official answer is as follows:

Https://github.com/rovo89/XposedBridge/wiki/Development-tutorial

After reading this article, you can basically write the simplest demo.

Now let's talk about how to write the simplest demo.

1. Create a new android project first (android studio is recommended)

This project does not require any activity, and the related component references can be deleted, so that the compiled apk is very small.

two。 Modify the build.gradle of the project

2 additional configurations

Repositories {jcenter ();}

Dependencies {provided 'de.robv.android.xposed:api:82'}

3. Modify AndroidManifest.xml so that xposed can recognize the plug-in

Normally, xposed can't tell if our application is a xposed plug-in, so we have to declare ourselves with a tag on manifest. The official examples are as follows

To put it simply, just add the following three attributes to the application configuration section

4. Implement the interface of xposed

The blank class is as follows

Package cn.coderstory.xposeddemo;public class Demo {}

If we want this class to have the ability to hook various kinds of code, we need to have this class implement some of the interfaces provided by the xposed framework.

The specific implementation of the interface depends on our specific requirements.

Common frontal interfaces are as follows

IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPackageResources, etc.

The IXposedHookZygoteInit interface implements the hook capability of the ZygoteInit phase, which is used to execute the relevant code before the Zygote process starts, and things in the framework are usually changed here.

The IXposedHookLoadPackage interface implements the ability to load hook in the app phase, which is used for hook app code

The IXposedHookInitPackageResources interface implements the hook capability when loading app resources, which is used to modify some app resources, such as layout files.

5. Write specific code logic

Now let's write a function, such as hiding the search box in the MIUI drop-down menu.

Reference source code

Package cn.coderstory.xposeddemo;import de.robv.android.xposed.IXposedHookInitPackageResources;import de.robv.android.xposed.callbacks.XC_InitPackageResources / * * Created by cc on 2017-1-3. * hide the MIUI drop-down menu search box * / IXposedHookInitPackageResources API to modify the resource file public class Demo implements IXposedHookInitPackageResources {@ Override public void handleInitPackageResources (XC_InitPackageResources.InitPackageResourcesParam resparam) {/ / if you are currently dealing with systemui if (resparam.packageName.equals ("com.android.systemui")) {/ / call the setReplacement method to change the name to config_show_statusbar_search The variable value is false resparam.res.setReplacement (resparam.packageName "bool", "config_show_statusbar_search", false) }}}

In this way, the function is written.

6. Create and edit xposed_init configuration files

Next we need to create a new directory called assets in the project, and then create a new file named xposed_init in the directory, text type. This file mainly records all the classes in app that implement the xposed function, and when you boot, xposed will load these classes in turn.

Create a new assets directory

Create a new xposed_init file with a type of Text

If there are multiple classes in the path to write the current class in xposed_init, then write one per line, multiple write multiple lines

7. Compilation and installation

When compiling, you need to turn off the instant run function of android studio.

After installing on the phone, you need to check the enable module on xposed install and restart it.

The above is how to develop entry-level Xposed plug-ins. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Interfaces files plug-ins code resources functions capabilities development directories compilation configuration content multiple official that is skills time knowledge articles types Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB macOS Apple Shulou Tech Info