0

我想在android中伪造位置。在 android 中,有一种方法可以使用PendingIntent. 这是一个例子:

        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);

BroadcastReceiver在新位置更改时收到事件:

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);
    }
}

所以,我想挂钩这个方法。但我不知道如何挂钩这种方法(即 using PendingIntent)。因为PendingIntent在“某个未来”会有数据,我不知道什么时候会发生。所以在方法之前和之后挂钩requestLocationUpdates似乎不起作用,因为当时PendingIntent还没有任何数据。

请告诉我如何做到这一点。

4

1 回答 1

0

您需要拦截广播接收器,而不是待处理的意图。您可以拦截LocationReceiver.onReceive和更改意图的内容。

为此,onReceive通过定义一个beforeHookedMethod. 使用其参数 ( MethodHookParam params) 检索意图 ( params.args[1]) 并更改其附加 ( intent.replaceExtras(bundle))。

确保您的新捆绑包具有相同的键 ( android.location.LocationManager.KEY_LOCATION_CHANGED),并且您可以设置自己的位置作为值:

Location loc = new Location("yourprovider");
loc.setLatitude(66.6);
loc.setLongitude(66.6);
于 2016-10-31T16:49:40.163 回答