其實(shí)之前寫寫過一些xposed模塊竿屹。但是每次要用xposed去hook的時(shí)候還是要去網(wǎng)上搜索一遍怎么寫骆撇。所以這次還是記一下筆記好了醉箕。雖然手機(jī)已經(jīng)root意系,但是還是覺得每次要重啟手機(jī)模塊才能生效太麻煩泥耀,所以用了vitualXposed這個(gè)軟件,真心好用蛔添,免root痰催,重啟超級快時(shí)間為0.下面就開始吧。
1. 創(chuàng)建項(xiàng)目
選擇了noActivity
2. 配置build.gradle
不同版本的api配置看鏈接
我一般都是不直接下載的迎瞧,感覺這樣配置比較方便夸溶。
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.xposedtest"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
provided 'de.robv.android.xposed:api:82'
testCompile 'junit:junit:4.12'
}
3. 配置AndroidManifest.xml
主要在Application中添加三個(gè)<meta-data>三個(gè)分別是:是否啟動(dòng)模塊、模塊的描述夹攒、模塊的最低版本
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xposedtest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposeddescription"
android:value="xposedtest01" />
<meta-data
android:name="xposedminversion"
android:value="82" />
</application>
</manifest>
4. 編寫代碼
這個(gè)就沒什么好說的了蜘醋,大家都不一樣的
public class xposedtest implements IXposedHookLoadPackage {
private static String TAG = "hookmain";
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
Log.i(TAG,"Loaded app: "+ lpparam.packageName);
if(lpparam.packageName.equals("com.example.testproxy")){
XposedBridge.log("找到testproxy");
XposedHelpers.findAndHookMethod("com.example.testproxy.ProxyApplication",
lpparam.classLoader, "attachBaseContext", Context.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Context mContext = (Context)param.args[0];
Log.i(TAG, mContext.getApplicationInfo().toString());
}
});
}
}
5. 配置xposed_init
創(chuàng)建assets文件夾胁塞,在文件夾中創(chuàng)建xposed_init文件咏尝,里面寫上模塊的入口點(diǎn)
com.example.xposedtest.xposedtest
總結(jié)
上面幾點(diǎn),1啸罢、2编检、3、5每次基本都是一樣的扰才。