content: package qing.albatross.demo;
  
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.content.pm.ResolveInfo;
  
  import java.util.List;
  
  import qing.albatross.annotation.DefOption;
  import qing.albatross.annotation.FieldRef;
  import qing.albatross.annotation.MethodHookBackup;
  import qing.albatross.annotation.TargetClass;
  import qing.albatross.core.Albatross;
  import qing.albatross.exception.AlbatrossErr;
  
  public class BinderHook {
    @TargetClass
    static class ParceledListSlice<T> {
      @FieldRef(option = DefOption.VIRTUAL, required = true)
      public List<T> mList;
    }
  
  
    @TargetClass
    static class IPackageManager {
      public static int count = 0;
  
      @MethodHookBackup
      private ParceledListSlice<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, long flags, int userId) {
  
        ParceledListSlice<ResolveInfo> res = queryIntentActivities(intent, resolvedType, flags, userId);
        count = res.mList.size();
        return res;
      }
  
      @MethodHookBackup
      private ParceledListSlice<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
        ParceledListSlice<ResolveInfo> res = queryIntentActivities(intent, resolvedType, flags, userId);
        count = res.mList.size();
        return res;
      }
    }
  
  
    public static class PackageManagerH {
      @FieldRef(option = DefOption.INSTANCE)
      private IPackageManager mPM;
    }
  
    public static void test(boolean hook) throws AlbatrossErr {
      if (!Albatross.isFieldEnable())
        return;
      PackageManager packageManager = Albatross.currentApplication().getPackageManager();
      if (hook) {
        Albatross.hookObject(PackageManagerH.class, packageManager);
      } else
        IPackageManager.count = -1;
      Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
      resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      List<ResolveInfo> res = packageManager.queryIntentActivities(resolveIntent, 0);
      assert res.size() == IPackageManager.count;
    }
  }
  