HOOK process of Xposed framework

1. After creating the project, right-click the app to create a directory lib, drag XposedBridgeApi-54.jar into the lib directory, and then right-click to add it to the local link library

2. Change the build.gradle file under the app and add it to the last line of dependencies

provided files('lib/XposedBridgeApi-54.jar')

3. Create a new folder assets


4. Create the file xposed_init file under assets, the entry address of the hook class method eg:

com.example.administrator.xposed.XposedBigBang

5.AndroidManifest.xml settings 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.Xmodule" android:versionName="1.0" android:versionCode="1">
    <uses-sdk android:minSdkVersion="15"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <meta-data
                android:name="xposedmodule"
                android:value="true"/>
        <meta-data
                android:name="xposeddescription"
                android:value="Xposed module example"/>
        <meta-data
                android:name="xposedminversion"
                android:value="54"/><!-- Corresponding XposedBridge version number-->
    </application>
</manifest>

6. After determining the entry address, create an entry file, that is, a new java class file named XposedBigBang in the com.example.administrator package in the java directory, corresponding to the entry address above

7.

package com.example.administrator.xposed; //Select the package corresponding to your own project here


import android.util.Log;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class XposedBigBang implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        // mark the target app package name
        if (!lpparam.packageName.equals("com.example.administrator.helloworld")) //Select the package you want to hook here
            return;
// Log.d("!!!!!!!!","HOOK CONTENT !!"); //Output to the log of android device monitor
// XposedBridge.log("Loaded app: " + lpparam.packageName); //Output to the xposed log


        // findAndHookMethod(class name of hook method, classLoader, hook method name, hook method parameters..., XC_MethodHook)
        XposedHelpers.findAndHookMethod("android.content.ContextWrapper", lpparam.classLoader, "getPackageManager",String.class,
                new XC_MethodHook() {  

                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// Class clazz = param.thisObject.getClass(); get the parameter object
//                        XposedBridge.log("class name:"+clazz.getName());
//                        XposedBridge.log("BEFORE HOOK SUCCESSFUL");
//// Log.d("BEFORE parameter 1",param.args[0].toString()); can print out the first parameter of the method


                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {

//                            Class clazz = param.thisObject.getClass();

// Object obj=param.getResult(); Get the result returned by the method, pay attention to the type of the result.
//                      //  XposedBridge.log("class name:"+clazz.getName());
//                        XposedBridge.log("AFTER HOOK SUCCESSFUL");
//                        Log.d("create file","");
// XposedBridge.log(obj.toString()); Convert the result to characters and print to the log


                    }
                });


    }
}

8. The xposed version used: de.robv.android.xposed.installer_v33_36570c.apk (not the latest, suitable for novice practice)


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325893287&siteId=291194637