// Unsafe mechanics static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } }
private void setKitKatBatteryColor(int iconColor) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) return; if (mKitKatBatteryView == null) return; boolean debug = mSettingsHelper.isDebugMode(); try { final int[] colors = (int[]) XposedHelpers.getObjectField(mKitKatBatteryView, "mColors"); colors[colors.length - 1] = iconColor; XposedHelpers.setObjectField(mKitKatBatteryView, "mColors", colors); } catch (NoSuchFieldError e) { if (debug) e.printStackTrace(); } try { final Paint framePaint = (Paint) XposedHelpers.getObjectField(mKitKatBatteryView, "mFramePaint"); framePaint.setColor(iconColor); framePaint.setAlpha(100); } catch (NoSuchFieldError e) { if (debug) e.printStackTrace(); } try { final Paint boltPaint = (Paint) XposedHelpers.getObjectField(mKitKatBatteryView, "mBoltPaint"); boltPaint.setColor(Utils.getIconColorForColor(iconColor, Color.BLACK, Color.WHITE, 0.7f)); boltPaint.setAlpha(100); } catch (NoSuchFieldError e) { if (debug) e.printStackTrace(); } try { XposedHelpers.setIntField(mKitKatBatteryView, "mChargeColor", iconColor); } catch (NoSuchFieldError e) { /* Beanstalk, not sure why the ROM changed this */ try { XposedHelpers.setIntField(mKitKatBatteryView, "mBatteryColor", iconColor); } catch (NoSuchFieldError e1) { } if (debug) e.printStackTrace(); } mKitKatBatteryView.invalidate(); }
@Override public void afterHookedMethod(MethodHookParam param) { // Logging string String methodAndParams = "afterHookedMethod(MethodHookParam)"; // Log WiFiKeyView.verboseLog(this, methodAndParams, "ModifyNetworkHook started"); // The WifiConfigController class reference Class<?> wifiConfigControllerClass = param.thisObject.getClass(); for (Field f : wifiConfigControllerClass.getFields()) { WiFiKeyView.verboseLog(this, methodAndParams, "" + f.getName()); } // Get the password field Field mPasswordViewField = null; try { mPasswordViewField = XposedHelpers.findField(wifiConfigControllerClass, "mPasswordView"); // mPasswordViewField = wifiConfigControllerClass.getField("mPasswordView"); } catch (NoSuchFieldError e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "mPasswordView is not found: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } try { mPasswordView = (TextView) mPasswordViewField.get(param.thisObject); } catch (IllegalAccessException e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from mPasswordView field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } catch (IllegalArgumentException e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from mPasswordView field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } Field fAccessPoint = null; try { fAccessPoint = XposedHelpers.findField(wifiConfigControllerClass, "mAccessPoint"); } catch (NoSuchFieldError e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog(this, methodAndParams, "mAccessPoint is not found: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } Class<?> accessPointClass = null; try { accessPointClass = fAccessPoint.get(param.thisObject).getClass(); } catch (IllegalAccessException e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from mAccessPoint field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } catch (IllegalArgumentException e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from mAccessPoint field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } Field fssid = null; try { fssid = XposedHelpers.findField(accessPointClass, "ssid"); } catch (NoSuchFieldError e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from mPasswordView field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } String ssid = null; try { ssid = (String) fssid.get(fAccessPoint.get(param.thisObject)); } catch (IllegalAccessException e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from ssid field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } catch (IllegalArgumentException e) { // Print stack trace e.printStackTrace(); // Report message in Xposed log WiFiKeyView.verboseLog( this, methodAndParams, "Failed to get value from ssid field: " + e.getMessage()); // Don't continue, this will produce more exceptions return; } WiFiKeyView.verboseLog( this, "afterHookedMethod(MethodHookParam);", "After hooked method finished with ssid: " + ssid); new NetworkParseTask(this).execute(ssid); }
private void setNavigationBarIconTint(final int tintColor, boolean force) { if (mNavigationBarView == null) return; if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !force) { return; } ImageView recentsButton = null; ImageView menuButton = null; ImageView backButton = null; ImageView homeButton = null; /* LG BUTTONS */ ImageView qmemoButton = null; ImageView notificationButton = null; Class<?> NavbarEditor = null; try { NavbarEditor = getObjectField(mNavigationBarView, "mEditBar").getClass(); } catch (NoSuchFieldError e) { } try { recentsButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getRecentsButton"); } catch (NoSuchMethodError e) { try { if (NavbarEditor != null) { recentsButton = (ImageView) mNavigationBarView.findViewWithTag( getStaticObjectField(NavbarEditor, "NAVBAR_RECENT")); } } catch (NoSuchFieldError e1) { e1.printStackTrace(); } } try { menuButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getMenuButton"); } catch (NoSuchMethodError e) { try { if (NavbarEditor != null) { menuButton = (ImageView) mNavigationBarView.findViewWithTag( getStaticObjectField(NavbarEditor, "NAVBAR_ALWAYS_MENU")); } } catch (NoSuchFieldError e1) { e1.printStackTrace(); } } try { backButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getBackButton"); } catch (NoSuchMethodError e) { try { backButton = (ImageView) mNavigationBarView.findViewWithTag( getStaticObjectField(NavbarEditor, "NAVBAR_BACK")); } catch (NoSuchFieldError e1) { e1.printStackTrace(); } } try { homeButton = (ImageView) XposedHelpers.callMethod(mNavigationBarView, "getHomeButton"); } catch (NoSuchMethodError e) { try { homeButton = (ImageView) mNavigationBarView.findViewWithTag( getStaticObjectField(NavbarEditor, "NAVBAR_HOME")); } catch (NoSuchFieldError e1) { e1.printStackTrace(); } } /* LG BUTTONS*/ if (qmemoButtonRESID > 0) qmemoButton = (ImageView) mNavigationBarView.findViewById(qmemoButtonRESID); if (notificationButtonRESID > 0) notificationButton = (ImageView) mNavigationBarView.findViewById(notificationButtonRESID); if (recentsButton != null) recentsButton.setColorFilter(tintColor); if (menuButton != null) menuButton.setColorFilter(tintColor); if (backButton != null) backButton.setColorFilter(tintColor); if (homeButton != null) homeButton.setColorFilter(tintColor); if (qmemoButton != null) qmemoButton.setColorFilter(tintColor); if (notificationButton != null) notificationButton.setColorFilter(tintColor); if (mNavigationBarView != null) { Intent intent = new Intent("gravitybox.intent.action.ACTION_NAVBAR_CHANGED"); intent.putExtra("navbarKeyColor", tintColor); intent.putExtra("navbarColorEnable", true); mNavigationBarView.getContext().sendBroadcast(intent); } }