软件编程
位置:首页>> 软件编程>> Android编程>> Hook实现Android 微信、陌陌 、探探位置模拟(附源码下载)

Hook实现Android 微信、陌陌 、探探位置模拟(附源码下载)

作者:Mark_YPQ  发布时间:2022-11-14 14:44:43 

标签:Hook,Android,位置模拟

Hook实现Android 微信、陌陌 、探探位置模拟

 最近需要对微信,陌陌等程序进行位置模拟 实现世界各地发朋友圈,搜索附近人的功能,本着站在巨人肩膀上的原则 爱网上搜索一番。

 也找到一些 代码和文章,但是代码大都雷同而且都有一个弊端 比如说 微信 对目标函数实现hook之后第一次打开微信 第一次定位是可以改变的

  但是 我如果想更换地址的话 就需要重启手机了,重新加载hook了,试了很多次都是这样满足不了需求。

为了改进这个地方我们从gps定义的源代码流程开始看寻找hook系统函数的突破口 

 我也是看完之后才找到hook的地方 LocationMangerService  这个类


@Override
public void reportLocation(Location location, boolean passive) {
checkCallerIsProvider(); //检测权限和uid

if (!location.isComplete()) {
 Log.w(TAG, "Dropping incomplete location: " + location);
 return;
}
 //发送位置信息
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("实际 系统 经度"+location.getLatitude() +" 系统 纬度"+location.getLongitude() +"系统 加速度 "+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 系统 经度"+location.getLatitude() +" 系统 纬度"+location.getLongitude() +"系统 加速度 "+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 微信、陌陌 、探探位置模拟(附源码下载)

Hook实现Android 微信、陌陌 、探探位置模拟(附源码下载)

当然还需要hook一些其他的辅助函数 ,这些函数都可以在 Android studio 中看到Java的代码 我们就无需过多解释了 上 源代码

源码下载

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

来源:http://blog.csdn.net/u012889434/article/details/61921933

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com