Xposed hook(android)
阿新 • • 發佈:2018-07-07
ppt android ini obj launch ram end device cto 先寫一個測試程序獲取 id
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //控件 TextView test = findViewById(R.id.test); Context context = getApplicationContext(); //權限 //<uses-permission android:name="android.permission.READ_PHONE_STATE" /> if (context.getPackageManager().checkPermission(Manifest.permission.READ_PHONE_STATE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) { String Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getDeviceId(); Log.e("soho",Imei); test.setText(Imei); } else { Log.e("soho","no permission"); } } }
開始 hook
新建一個項目
在application中增加模塊說明
<meta-data android:name="xposedmodule" android:value="true"></meta-data> <meta-data android:name="xposeddescription" android:value="Xposed插件"></meta-data> <meta-data android:name="xposedminversion" android:value="54"></meta-data> ///////////////////////////////////////////////////////////// <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.liuhailong.hook"> <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"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="xposedmodule" android:value="true"></meta-data> <meta-data android:name="xposeddescription" android:value="Xposed插件"></meta-data> <meta-data android:name="xposedminversion" android:value="54"></meta-data> </application> </manifest>
導入 xposed jar
先在 app 中新建 一個文件夾同時必須名為 lib(在 project 視圖)
復制模塊進去
打開模塊依賴
再添加
修改 scope 為
加載下或者運行一下不行重啟 as
會出現 3 個目錄說明加載成功
創建一個類 名稱必須為Main實現IXposedHookLoadPackage接口
實現方法
聲明主入口類路徑
在 main文件夾內建立 assets文件夾必須名為assets
在assets文件夾內新建一個 xposed_init的文件名稱也要一樣
在文件中聲明入口類名稱
使用 findAndHookMethod
package com.example.liuhailong.hook; import android.telephony.TelephonyManager; import de.robv.android.xposed.IXposedHookLoadPackage; import de.robv.android.xposed.XC_MethodReplacement; import de.robv.android.xposed.XposedBridge; import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.callbacks.XC_LoadPackage; public class Main implements IXposedHookLoadPackage { @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { //先判斷要 hook的包也就是那個 app if(!loadPackageParam.packageName.equals("com.example.liuhailong")){ //打印日誌這個打印在 apk上 XposedBridge.log(loadPackageParam.packageName); return; } //打到對應的方法 進行替換 replaceHookedMethod替換方法 //參數1:名稱 參數2:方法名 參數3:實現監聽 重寫方法 XposedHelpers.findAndHookMethod( TelephonyManager.class, "getDeviceId", new XC_MethodReplacement() { @Override protected Object replaceHookedMethod(MethodHookParam argMethodHookParam) throws Throwable { return "我才是序列號!"; } } ); } }
安裝 hook 框架
de.robv.android.xposed.installer_v32_de4f0d.apk
提示要你安裝 hook
點擊框架
點擊安裝它就會要你重啟
重啟完後啟動 hook
點擊模塊
重啟就可以了 只要啟動 hooktest 就會被 hook(hook不要啟動 一般是寫沒有見面的我是為了調試)
Main.java 完整代碼
package com.bluelesson.xposed24;
import android.telephony.TelephonyManager;
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 Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam argLoadPackageParam) throws Throwable {
// 判斷是不是要Hook的包,不是直接返回
if(!argLoadPackageParam.packageName.equals("com.bluelesson.testphoneinfo")){
return;
}
// XposedHelpers.findAndHookMethod(
// TelephonyManager.class,
// "getDeviceId",
// new XC_MethodReplacement() {
// @Override
// protected Object replaceHookedMethod(MethodHookParam argMethodHookParam) throws Throwable {
// return "我才是序列號!";
// }
// }
// );
XposedHelpers.findAndHookMethod(
TelephonyManager.class,
"getDeviceId",
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
XposedBridge.log("beforeHookedMethod");
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("afterHookedMethod");
param.setResult("我是序列號");
}
}
);
}
}
Xposed hook(android)