0

I want to fake location in android. In android, there is a way for getting location using PendingIntent. Here is an example:

        LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
        String proximitys = "ACTION";
        IntentFilter filter = new IntentFilter(proximitys);
        LocationReceiver mReceiver = new LocationReceiver();
        registerReceiver(mReceiver, filter);
        Intent intent = new Intent(proximitys);
        PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0,
                intent, PendingIntent.FLAG_CANCEL_CURRENT);

        service.requestLocationUpdates("network", 1000, 0.001f, proximityIntent);

And BroadcastReceiver will receive event when new location change:

public class LocationReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //Do this when the system sends the intent
        Bundle b = intent.getExtras();
        Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);
    }
}

So, I want to hook this method. But I don't know how to hook this kind of method (that using PendingIntent). because PendingIntent will have data in "some future", and I don't know when it will happen. So hooking both before and after of method requestLocationUpdates seem not work because at that time, PendingIntent doesn't have any data yet.

Please tell me how to do this.

Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107

1 Answers1

0

You need to intercept the broadcast receiver, not the pending intent. You can intercept LocationReceiver.onReceive and change the contents of the intent.

To do so intercept the onReceive by defining a beforeHookedMethod. Use its parameter (MethodHookParam params) to retrieve the intent (params.args[1]) and change its extras (intent.replaceExtras(bundle)).

Make sure your new bundle has the same key (android.location.LocationManager.KEY_LOCATION_CHANGED) and as value you can set your own location:

Location loc = new Location("yourprovider");
loc.setLatitude(66.6);
loc.setLongitude(66.6);
4knahs
  • 629
  • 4
  • 14