首页 > 代码库 > Xposed hook实验小程序

Xposed hook实验小程序

1、新建安卓工程;

2、libs文件夹下导入xposedbridge的jar包,并libs右键build path;

3、androidmanifest文件配置修改如下(添加几行即可):

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.xposedtest"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="21" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <meta-data            android:name="xposedmodule"            android:value="http://www.mamicode.com/true"/>        <meta-data            android:name="xposeddescription"            android:value="http://www.mamicode.com/efdetyfdeuf"/>        <meta-data            android:name="xposedminversion"            android:value="http://www.mamicode.com/54"/>                  </application></manifest>

4、在src文件夹下新建类,书写hook代码,如下:

package com.example.xposedtest;import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;import android.graphics.Color;import android.widget.TextView;import de.robv.android.xposed.*;import de.robv.android.xposed.XC_MethodHook.MethodHookParam;import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;public class HookSMS implements IXposedHookLoadPackage{    @Override    public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {        // TODO Auto-generated method stub        if(!lpparam.packageName.equals("com.android.systemui"))            return;        findAndHookMethod("com.android.systemui.statusbar.policy.Clock",lpparam.classLoader,"updateClock",                new XC_MethodHook()        {            @Override            protected void beforeHookedMethod(MethodHookParam param)                    throws Throwable {                // TODO Auto-generated method stub                super.beforeHookedMethod(param);            }            @Override            protected void afterHookedMethod(MethodHookParam param)                    throws Throwable {                TextView tv=(TextView)param.thisObject;                String text=tv.getText().toString();                tv.setText(text+":)");                tv.setTextColor(Color.RED);                            }                    }                );    }}

注意:代码书写时候,接口内重写的函数,右键自动导入即可。

5、在assets文件夹下新建文件,文件内容是hook程序的路径,即com.example.xposedtest.HookSMS

6、总体配置截图如下:

-----------------------------------程序书写配置完毕----------------------------------

Xposed hook实验小程序