Пример #1
0
  @Override
  public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

    switch (lpparam.packageName) {
      case PACKAGE_SETTINGS:
        SettingsHooks.hook(lpparam.classLoader);
        break;
      case PACKAGE_SYSTEMUI:
        SystemUIHooks.hookSystemUI(lpparam.classLoader);
        StatusBarHeaderHooks.hook(lpparam.classLoader);
        NotificationPanelHooks.hook(lpparam.classLoader);
        StackScrollAlgorithmHooks.hook(lpparam.classLoader);
        NotificationHooks.hookSystemUI(lpparam.classLoader);
        RecentsStackHooks.hookSystemUI(lpparam.classLoader);
        RecentsNavigation.hookSystemUI(lpparam.classLoader);
        DoubleTapSwKeys.hook(lpparam.classLoader);
        break;
      case PACKAGE_ANDROID:
        DoubleTapHwKeys.hook(lpparam.classLoader);
        LiveDisplayObserver.hook(lpparam.classLoader);
        PermissionGranter.initAndroid(lpparam.classLoader);
        break;
      case PACKAGE_PHONE:
        EmergencyHooks.hook(lpparam.classLoader);
        break;
      case PACKAGE_OWN:
        XposedHelpers.findAndHookMethod(
            SETTINGS_OWN,
            lpparam.classLoader,
            "isActivated",
            XC_MethodReplacement.returnConstant(true));
        if (!sPrefs.getBoolean("can_read_prefs", false))
          XposedHelpers.findAndHookMethod(
              SETTINGS_OWN,
              lpparam.classLoader,
              "isPrefsFileReadable",
              XC_MethodReplacement.returnConstant(false));
        break;
    }

    // Has to be hooked in every app as every app creates own instances of the Notification.Builder
    NotificationHooks.hook(lpparam.classLoader);

    // This actually is only used in the system process, but every app has access, so just to be
    // sure hook everything
    if (ConfigUtils.qs().enable_qs_editor) {
      try {
        Class<?> classCMStatusBarManager =
            XposedHelpers.findClass("cyanogenmod.app.CMStatusBarManager", lpparam.classLoader);
        XposedBridge.hookAllMethods(
            classCMStatusBarManager, "publishTile", XC_MethodReplacement.DO_NOTHING);
        XposedBridge.hookAllMethods(
            classCMStatusBarManager, "publishTileAsUser", XC_MethodReplacement.DO_NOTHING);
      } catch (Throwable ignore) {
      }
    }
  }
Пример #2
0
  public static boolean handleLoadPackage(
      final String packageName, LoadPackageParam lpparam, final boolean test) {
    try {
      Class<?> adView =
          XposedHelpers.findClass("com.amazon.device.ads.AdLayout", lpparam.classLoader);

      XposedBridge.hookAllMethods(
          adView,
          "setListener",
          new XC_MethodHook() {

            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

              Util.log(packageName, "Prevent amazon setlistener");

              if (!test) {
                param.setResult(new Object());
                Main.removeAdView((View) param.thisObject, packageName, true);
              }
            }
          });

      XposedBridge.hookAllMethods(
          adView,
          "loadAd",
          new XC_MethodHook() {

            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

              Util.log(packageName, "Detect Amazon loadAd in " + packageName);

              if (!test) {
                param.setResult(Boolean.valueOf(true));
                Main.removeAdView((View) param.thisObject, packageName, true);
              }
            }
          });

      Util.log(packageName, packageName + " uses Amazon");
    } catch (ClassNotFoundError e) {
      return false;
    }
    return true;
  }
  public BatteryHooks(ColourChangerMod instance, ClassLoader classLoader) {
    mInstance = instance;
    String className = "com.android.systemui.statusbar.policy.BatteryController";
    String addIconMethodName = "addIconView";
    String addLabelMethodName = "addLabelView";
    try {
      Class<?> BatteryController = XposedHelpers.findClass(className, classLoader);

      try {
        XposedHelpers.findAndHookMethod(
            BatteryController,
            addIconMethodName,
            ImageView.class,
            new XC_MethodHook() {
              @Override
              protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                mInstance.addSystemIconView((ImageView) param.args[0]);
              }
            });
      } catch (NoSuchMethodError e) {
        XposedBridge.log("Not hooking method " + className + "." + addIconMethodName);
      }

      try {
        XposedHelpers.findAndHookMethod(
            BatteryController,
            addLabelMethodName,
            TextView.class,
            new XC_MethodHook() {
              @Override
              protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                mInstance.addTextLabel((TextView) param.args[0]);
              }
            });
      } catch (NoSuchMethodError e) {
        XposedBridge.log("Not hooking method " + className + "." + addLabelMethodName);
      }

    } catch (ClassNotFoundError e) {
      // Really shouldn't happen, but we can't afford a crash here.
      XposedBridge.log("Not hooking class: " + className);
    }
  }
  public static void doHook(ClassLoader loader) {
    Class<?> clazz = XposedHelpers.findClass(sClassName, loader);
    XposedBridge.hookAllConstructors(
        clazz,
        new XC_MethodHook() {
          @Override
          protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            ReflectionHelper.setAdditionalInstanceField(
                param.thisObject,
                "mSimpleStatusbarHook",
                new SimpleStatusbarInjector(param.thisObject));
          }
        });

    XposedHelpers.findAndHookMethod(
        clazz,
        "updateNotificationIcons",
        boolean.class,
        ArrayList.class,
        LinearLayout.LayoutParams.class,
        new XC_MethodHook() {
          @Override
          protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            ((SimpleStatusbarInjector)
                    ReflectionHelper.getAdditionalInstanceField(
                        param.thisObject, "mSimpleStatusbarHook"))
                .hookAfterUpdateNotificationIcons();
          }
        });

    XposedHelpers.findAndHookMethod(
        clazz,
        "updateDarkMode",
        new XC_MethodHook() {
          @Override
          protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            ((SimpleStatusbarInjector)
                    ReflectionHelper.getAdditionalInstanceField(
                        param.thisObject, "mSimpleStatusbarHook"))
                .hookAfterUpdateDarkMode();
          }
        });
  }
  private void doClockHooks(ClassLoader loader) {
    Class<?> Clock = XposedHelpers.findClass("com.android.systemui.statusbar.policy.Clock", loader);
    XposedBridge.hookAllConstructors(
        Clock,
        new XC_MethodHook() {
          @Override
          protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            addTextLabel((TextView) param.thisObject);
            mFoundClock = true;
          }
        });

    findAndHookMethod(
        Clock,
        "updateClock",
        new XC_MethodHook() {
          @Override
          protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            TextView textView = (TextView) param.thisObject;
            textView.setTextColor(mColorForStatusIcons);
          }
        });
  }
  @Override
  public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals(PACKAGE)) return;

    Class<?> findClass;

    try {
      findClass =
          XposedHelpers.findClass(PACKAGE + ".recent.RecentAppFxActivity", lpparam.classLoader);
    } catch (Throwable e) {
      XposedBridge.log(e);
      return;
    }

    XposedHelpers.findAndHookMethod(
        findClass,
        "onCreate",
        android.os.Bundle.class,
        new XC_MethodHook() {
          @Override
          protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            Activity thiz = (Activity) param.thisObject;

            // Show status bar
            thiz.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

            // Enable translucent status bar
            thiz.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

            // Get status bar height
            final int statusBarHeight = getStatusBarHeight(thiz.getResources());

            View actionBarView;

            // Get the action bar view
            try {
              // Try to get 'actionContainer' field. It will throw an NoSuchFieldError if it doesn't
              // exists,
              // and if it doesn't try an alternative method.
              actionBarView = (View) XposedHelpers.getObjectField(thiz, "actionContainer");
            } catch (NoSuchFieldError e) {
              // Find root layout. ID is from decompiling SystemUI.apk
              LinearLayout rootLayout = (LinearLayout) thiz.findViewById(0x7f070044);

              // Get first child view
              actionBarView = rootLayout.getChildAt(0);
            }

            // Insert a new View to color the status bar & move action bar down
            View statusBarColor = new View(actionBarView.getContext());

            // Match action bar background, and set minimum height
            statusBarColor.setBackground(actionBarView.getBackground());
            statusBarColor.setMinimumHeight(statusBarHeight);

            // Insert view before action bar into parent
            ((ViewGroup) actionBarView.getParent())
                .addView(
                    statusBarColor,
                    0,
                    new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight));

            // Check for navigation bar before making any changes.
            if (hasNavigationBar(thiz)) {
              // Enable translucent navigation bar
              thiz.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

              // Get 3rd child view to fix bottom padding
              View background = ((ViewGroup) actionBarView.getParent()).getChildAt(2);

              // Get navigation bar height
              int navigationBarHeight = getNavigationBarHeight(thiz.getResources());

              // Increase the bottom padding by navigation bar height
              background.setPadding(
                  background.getPaddingLeft(),
                  background.getPaddingTop(),
                  background.getPaddingRight(),
                  background.getPaddingBottom() + navigationBarHeight);
            }
          }
        });

    XposedBridge.log("[" + TAG + "] Hooked recent apps activity");
  }
  public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals(FACEBOOK_PACKAGE_NAME)) {
      return;
    }

    final Context context = Global.getContext();
    ApplicationLogMaintainer.sendBroadcast(context, "One Tap Facebook Lite Hook Initialized");
    if (!Global.isPackageInstalled(context, ONE_TAP_FACEBOOK_MODULE_PACKAGE_NAME)) {
      ApplicationLogMaintainer.sendBroadcast(context, "One Tap Facebook Lite Module not installed");
      return;
    }

    File hookFile = new File(HookClassNamesFetcher.getHooksFilePath(context));
    try {
      if (!hookFile.exists()) {
        ApplicationLogMaintainer.sendBroadcast(context, "Hook file doesn't exist");
      }

      if (!Global.isFileReadable(hookFile)) {
        ApplicationLogMaintainer.sendBroadcast(context, "Unable to open file for reading");
        ApplicationLogMaintainer.sendBroadcast(context, hookFile.getAbsolutePath());
      }

      String jsonString = Global.readFileToString(hookFile);
      JSONObject jsonObject = Global.isValidJSONObject(jsonString);
      if (jsonObject != null) {
        classNamesMap.clear();
        ApplicationLogMaintainer.sendBroadcast(Global.getContext(), "Cleared Class Names Map");
        Global.loadJSONToMap(classNamesMap, jsonObject.getJSONObject("FacebookLite"));
      }
    } catch (Exception e) {
      ApplicationLogMaintainer.sendBroadcast(context, Global.getStackTrace(e));
    }

    final XC_MethodHook methodHook =
        new XC_MethodHook() {
          protected void afterHookedMethod(MethodHookParam hookParams) throws Throwable {
            try {
              String uri = hookParams.args[1].toString();
              IpcService.startSaveUrlAction(context, uri, FACEBOOK_PACKAGE_NAME);
              ApplicationLogMaintainer.sendBroadcast(context, "Facebook Lite URL : " + uri);
            } catch (Exception e) {
              ApplicationLogMaintainer.sendBroadcast(context, Global.getStackTrace(e));
            }
          }
        };

    int packageVersion =
        context.getPackageManager().getPackageInfo(lpparam.packageName, 0).versionCode;

    ApplicationLogMaintainer.sendBroadcast(
        context, "Facebook Lite Package Version : " + packageVersion);

    Pair<String, String> classPair =
        classNamesMap.get(Global.getXSignificantDigits(packageVersion, 2));
    if (classPair == null) {
      ApplicationLogMaintainer.sendBroadcast(context, "ClassNamePair is null. Todo : Update Hooks");
      return;
    }

    if (!Global.isClassPresent(lpparam.classLoader, classPair.first)
        || !Global.isClassPresent(lpparam.classLoader, classPair.second)) {
      ApplicationLogMaintainer.sendBroadcast(
          context, "Facebook Lite Hooking failed even when ClassPair is not null.");
      return;
    }

    Class mainClass = XposedHelpers.findClass(classPair.first, lpparam.classLoader);
    Class subClass = XposedHelpers.findClass(classPair.second, lpparam.classLoader);

    Object[] objects =
        new Object[] {
          String.class,
          String.class,
          int.class,
          int.class,
          int.class,
          subClass,
          long.class,
          boolean.class,
          long.class,
          String.class,
          boolean.class,
          methodHook
        };

    try {
      XposedHelpers.findAndHookConstructor(mainClass, objects);
      ApplicationLogMaintainer.sendBroadcast(context, "Facebook Lite hooking successful");
    } catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError e) {
      ApplicationLogMaintainer.sendBroadcast(context, Global.getStackTrace(e));
    }
  }