xposed入门笔记

学xposed时的一些笔记

AndroidManifest.xml

按下面给的示例修改AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.robv.android.xposed.mods.tutorial"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <meta-data
            android:name="xposedmodule"
            android:value="true" />
        <meta-data
            android:name="xposeddescription"
            android:value="Easy example which makes the status bar clock red and adds a smiley" />
        <meta-data
            android:name="xposedminversion"
            android:value="30" />
    </application>
</manifest>

XposedBridgeApi.jar

http://forum.xda-developers.com/xposed/xposed-api-changelog-t2714067
到这里下载jar包,在项目中新建lib目录,将jar包放入lib目录,设置Scope为Provided

Java

package com.lanyus.sms106to10086;

import android.app.PendingIntent;
import android.content.Context;
import android.widget.Toast;
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;

import java.util.ArrayList;

/**
 * Created by Ly on 2015/9/28.
 */
public class Main implements IXposedHookLoadPackage{
    public Main() {
        super();
    }

    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        XposedHelpers.findAndHookMethod("android.telephony.SmsManager", lpparam.classLoader, "sendTextMessage",
                String.class, String.class, String.class, PendingIntent.class, PendingIntent
                        .class, new XC_MethodHook() {
                    public void afterHookedMethod(MethodHookParam param) throws Throwable {
                        XposedBridge.log(param.args[0] + ":" + param.args[2]);
                    }

                    public void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        if (((String)param.args[0]).substring(0, 3).equals("106")) {
                            XposedBridge.log(param.args[0] + ":" + param.args[2]);
                            param.args[0] = "10086";
                        }
                    }
                });
        XposedHelpers.findAndHookMethod("android.telephony.SmsManager", lpparam.classLoader, "sendDataMessage",
                String.class, String.class, Short.TYPE, byte[].class, PendingIntent.class,
                PendingIntent.class, new XC_MethodHook() {
            public void afterHookedMethod(MethodHookParam param) throws Throwable {
                XposedBridge.log(param.args[0] + ":" + param.args[2]);
            }

            public void beforeHookedMethod(MethodHookParam param) throws Throwable {
                if(((String)param.args[0]).substring(0, 3).equals("106")) {
                    XposedBridge.log(param.args[0] + ":" + param.args[2]);
                    param.args[0] = "10086";
                }
            }
        });
        XposedHelpers.findAndHookMethod("android.telephony.SmsManager", lpparam.classLoader, "sendMultipartTextMessage",
                String.class, String.class, ArrayList.class, ArrayList.class, ArrayList
                        .class, new XC_MethodHook() {
                    public void afterHookedMethod(MethodHookParam param) throws Throwable {
                        XposedBridge.log(param.args[0] + ":" + param.args[2]);
                    }

                    public void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        if(((String)param.args[0]).substring(0, 3).equals("106")) {
                            XposedBridge.log(param.args[0] + ":" + param.args[2]);
                            param.args[0] = "10086";
                        }
                    }
                });
    }
}

xposed_init

增加assets/xposed_init文件

com.lanyus.sms106to10086.Main

标签: none

添加新评论