javaandroidxposed

Hook to BroadcastReceiver using Xposed Framework


How to hook a onReceive method inside BroadcastReceiver?

public class RecentsActivity extends Activity
{
  mIntentReceiver = new BroadcastReceiver()
  {
    public void onReceive(Context context, Intent intent)
    {
      ...
    }
  };
}

Solution

  • Since the BroadcastReceiver is an abstract class and this is an inline class definition, perhaps you can retrieve this BroadcastReceiver this way:

    for(Class<?> cls : <package_name>.RecentsActivity.class.getDeclaredClasses()){
        if(BroadcastReceiver.isAssignableFrom(cls)){
            //hook onReceive
        }
    }
    

    Otherwise try to check the application smali code using the apktool.

    There probably is a file named RecentsActivity$N (where N is a number). Just do Class.forName("<packagename>.RecentsActivity$N") and hook this class onReceive method.

    Good luck!