Hook實現Android 微信、陌陌 、探探位置模擬(附源碼下載)
Hook實現Android 微信、陌陌 、探探位置模擬
最近需要對微信,陌陌等程序進行位置模擬 實現世界各地發(fā)朋友圈,搜索附近人的功能,本著站在巨人肩膀上的原則 愛網上搜索一番。
也找到一些 代碼和文章,但是代碼大都雷同而且都有一個弊端 比如說 微信 對目標函數實現hook之后第一次打開微信 第一次定位是可以改變的
但是 我如果想更換地址的話 就需要重啟手機了,重新加載hook了,試了很多次都是這樣滿足不了需求。
為了改進這個地方我們從gps定義的源代碼流程開始看尋找hook系統(tǒng)函數的突破口
我也是看完之后才找到hook的地方 LocationMangerService 這個類
@Override
public void reportLocation(Location location, boolean passive) {
checkCallerIsProvider(); //檢測權限和uid
if (!location.isComplete()) {
Log.w(TAG, "Dropping incomplete location: " + location);
return;
}
//發(fā)送位置信息
mLocationHandler.removeMessages(MSG_LOCATION_CHANGED, location);
Message m = Message.obtain(mLocationHandler, MSG_LOCATION_CHANGED, location);
m.arg1 = (passive ? 1 : 0);
mLocationHandler.sendMessageAtFrontOfQueue(m);
}
那么我們可以hook掉這個location的參數 修改為我們想要定位的地方就可以實現效果了,
XposedHelpers.findAndHookMethod("com.android.server.LocationManagerService", lpparam.classLoader, "reportLocation", Location.class, boolean.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Location location = (Location) param.args[0];
XposedBridge.log("實際 系統(tǒng) 經度"+location.getLatitude() +" 系統(tǒng) 緯度"+location.getLongitude() +"系統(tǒng) 加速度 "+location.getAccuracy());
XSharedPreferences xsp =new XSharedPreferences("com.markypq.gpshook","markypq");
if (xsp.getBoolean("enableHook",true)){
double latitude = Double.valueOf(xsp.getString("lan","117.536246"))+ (double) new Random().nextInt(1000) / 1000000 ;
double longtitude = Double.valueOf(xsp.getString("lon","36.681752"))+ (double) new Random().nextInt(1000) / 1000000 ;
location.setLongitude(longtitude);
location.setLatitude(latitude);
XposedBridge.log("hook 系統(tǒng) 經度"+location.getLatitude() +" 系統(tǒng) 緯度"+location.getLongitude() +"系統(tǒng) 加速度 "+location.getAccuracy());
}
}
});
如果我想主動調用這個函數 必須要得到這個LocationMangerService 的對象 獲取這個對象可以通過hook LocationManager 的構造函數獲取,
XposedBridge.hookAllConstructors(LocationManager.class,new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
if (param.args.length==2) {
Context context = (Context) param.args[0]; //這里的 context
XposedBridge.log(" 對 "+getProgramNameByPackageName(context)+" 模擬位置");
//把權限的檢查 hook掉
XposedHelpers.findAndHookMethod(context.getClass(), "checkCallingOrSelfPermission", String.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
if (param.args[0].toString().contains("INSTALL_LOCATION_PROVIDER")){
param.setResult(PackageManager.PERMISSION_GRANTED);
}
}
});
XposedBridge.log("LocationManager : " + context.getPackageName() + " class:= " + param.args[1].getClass().toString());
//獲取到 locationManagerService 主動調用 對象的 reportLocation 方法 可以去模擬提供位置信息
//這里代碼中并沒有涉及到主動調用
Object locationManagerService = param.args[1];
}
}
});


當然還需要hook一些其他的輔助函數 ,這些函數都可以在 Android studio 中看到Java的代碼 我們就無需過多解釋了 上 源代碼
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
Flutter?Widget?之FocusableActionDetector使用詳解
這篇文章主要為大家介紹了Flutter?Widget?之FocusableActionDetector使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
Android頂部狀態(tài)欄透明化并釋放空間的兩種實現方法
這篇文章主要介紹了Android頂部狀態(tài)欄透明化并釋放空間的兩種實現方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03
android高仿小米時鐘(使用Camera和Matrix實現3D效果)
這篇文章主要介紹了android高仿小米時鐘(使用Camera和Matrix實現3D效果),非常具有實用價值,需要的朋友可以參考下。2017-01-01

