Reproduced The first Xposed module on Android Studio

Source: Internet
Author: User

This article was reproduced from: http://www.open-open.com/lib/view/open1451364108964.html

Environment:

A root phone

Android Studio One

Official documentation reference here.

Preparatory work

We need to download a Xposed installer installed on the phone in advance to manage all the modules.

When the installation is complete, open:

Click Frame,

Click Install/update installation framework,

Click OK to restart, the framework interface is like this:

Writing a new module

Open Android Studio, new project, select Add No Activity

When the new is complete, locate the Build.gradle file in the app directory, and the dependencies

Compile Filetree (dir: ' Libs ', include: [' *.jar '])

Switch

Provided Filetree (dir: ' Libs ', include: [' *.jar '])

Download the Xposedbridgeapi-54.jar and put it in the Libs folder in the app directory.

Add the following code to the application of the Androidmanifest.xml file, where 54 is the number in the previously downloaded file.

<meta-data    android:name= "Xposedmodule"    android:value= "true"/><meta-data    android:name= " Xposeddescription "    android:value=" Kiya ' s test module "/><meta-data    android:name=" Xposedminversion "    android:value= "/>"

Create a new Test class, write:

Package Space.kiya.xposedtest;import De.robv.android.xposed.ixposedhookloadpackage;import De.robv.android.xposed.xposedbridge;import De.robv.android.xposed.callbacks.xc_loadpackage;public class Test Implements ixposedhookloadpackage{    @Override public void Handleloadpackage (Xc_loadpackage.loadpackageparam Loadpackageparam) throws Throwable {        XposedBridge.log ("Loaded:" + loadpackageparam.packagename);}    }

Create a new assets folder, where the new file name is Xposed_init, write the class name you just have, and this should be space.kiya.xposedtest.Test.

This will allow you to compile and install the.

Test

Because the project has no activity, the app is not visible on the desktop.

Come to xposed installer module, you can see our module appears here, now tick it:

Before restarting it to take effect, we create a new filter with tag Xposed in Logcat so that the log of the module output can be filtered out.

This is probably the case:

Loading Xposed v54 (for Zygote) ... Loading Modules from/data/app/space.kiya.xposedtest-1.apk  Loading class space.kiya.xposedtest.TestLoaded: Android...

Such logs can also be seen in the logs of xposed installer.

If there is an error in log:

Java.lang.IllegalAccessError:Class ref in Pre-verified Class resolved to unexpected implementation

The description is caused by Build.gradle not modified in the previous step.

How does xposed work?

When booting, the./init.rc script file starts the Zygote process, Zygote the corresponding program is/system/bin/app_process, then loads the required classes, invokes the initialization method, and then each application that starts is a copy of Zygote, So the zygote process is very important.

By adding a jar package to the classpath, invoking the method in the jar package at a specific location in App_process, the xposed framework implements the app_process with the extended function and replaces the original app_process.

In the/data/data/de.robv.android.xposed.installer/bin/directory there is a Xposedbridge.jar file, it is the referenced jar package, source on GitHub, main function in/src/de /robv/android/xposed/xposedbridge.java, each process is invoked each time it is started. The function of loading the module is also implemented here.

Xposed really powerful is the way it can hook calls. When you decompile and modify the APK, you can insert the xposed command inside, so you can inject your own code before and after the method call.

Xposedbridge has a private local method hookmethodnative, and the code implementation is placed in App_process. This method is called before calling the Hook method, and Hookmethodnative has a The Handlehookedmethod method allows you to modify the arguments passed to the hook function, and the variables even call other methods.

Reproduced The first Xposed module on Android Studio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.