[英]Xposed: How to hook method that using PendingIntent
我想在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);
}
}
因此,我想使用此方法。 但是我不知道如何钩住这种方法(使用PendingIntent
)。 因为PendingIntent
会在“将来”存储数据,而我不知道何时会发生。 因此,挂接方法requestLocationUpdates
之前和之后似乎都行不通,因为那时PendingIntent
还没有任何数据。
请告诉我该怎么做。
您需要拦截广播接收器,而不是未决的意图。 您可以拦截LocationReceiver.onReceive
并更改意图的内容。
为此,通过定义beforeHookedMethod
拦截onReceive
。 使用其参数( 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.