private String getLollipopRecentTask() { /** @hide Process is hosting the current top activities. Note that this covers * all activities that are visible to the user. */ final int PROCESS_STATE_TOP = 2; try { Field processStateField = ActivityManager.RunningAppProcessInfo.class.getDeclaredField("processState"); List<ActivityManager.RunningAppProcessInfo> processes = ((ActivityManager) AndroidAppHelper.currentApplication().getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo process : processes) { if (process.importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && process.importanceReasonCode == 0) { int state = processStateField.getInt(process); if (state == PROCESS_STATE_TOP) { String[] packname = process.pkgList; return packname[0]; } } } } catch (Exception e) { XposedBridge.log(e); } return ""; }
@Override public void modifySensor(final XC_LoadPackage.LoadPackageParam lpparam) { XposedHelpers.findAndHookMethod( "android.hardware.SystemSensorManager$ListenerDelegate", lpparam.classLoader, "onSensorChangedLocked", Sensor.class, float[].class, long[].class, int.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) { Sensor sensor = (Sensor) param.args[0]; Context context = AndroidAppHelper.currentApplication(); //Use processName here always. Not packageName. if (!isPackageAllowedToSeeTrueSensor(lpparam.processName, sensor, context) && getSensorStatus(sensor, context) == Constants.SENSOR_STATUS_MOCK_VALUES) { // Get the mock values from the settings. float[] values = getSensorValues(sensor, context); //noinspection SuspiciousSystemArraycopy System.arraycopy(values, 0, param.args[1], 0, values.length); } } } ); }
@Override public void modifySensor(final XC_LoadPackage.LoadPackageParam lpparam) { XposedHelpers.findAndHookMethod("android.hardware.SystemSensorManager", lpparam.classLoader, "getFullSensorList", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { //Without this, you'd never be able to edit the values for a removed sensor! Aaah! if (!lpparam.packageName.equals(BuildConfig.APPLICATION_ID)) { //Create a new list so we don't modify the original list. @SuppressWarnings("unchecked") List<Sensor> fullSensorList = new ArrayList<>((Collection<? extends Sensor>) param.getResult()); Iterator<Sensor> iterator = fullSensorList.iterator(); Context context = AndroidAppHelper.currentApplication(); while (iterator.hasNext()) { Sensor sensor = iterator.next(); if (!isPackageAllowedToSeeTrueSensor(lpparam.processName, sensor, context) && getSensorStatus(sensor, context) == Constants.SENSOR_STATUS_REMOVE_SENSOR) { iterator.remove(); } } param.setResult(fullSensorList); } } }); }
public static ModuleResources createInstance(String modulePath, XResources origRes) { if(modulePath == null) throw new IllegalArgumentException("modulePath must not be null"); AssetManager assets = (AssetManager)newInstance(AssetManager.class); callMethod(assets, "addAssetPath", modulePath); ModuleResources res; if(origRes != null) res = new ModuleResources(assets, origRes.getDisplayMetrics(), origRes.getConfiguration()); else res = new ModuleResources(assets, null, null); AndroidAppHelper.addActiveResource(modulePath, res.hashCode(), false, res); return res; }
/** * Usually called with the automatically injected {@code MODULE_PATH} constant of the first parameter * and the resources received in the callback for {@link XposedBridge#hookInitPackageResources} (or * {@code null} for system-wide replacements. */ public static XModuleResources createInstance(String modulePath, XResources origRes) { if (modulePath == null) throw new IllegalArgumentException("modulePath must not be null"); AssetManager assets = new AssetManager(); assets.addAssetPath(modulePath); XModuleResources res; if (origRes != null) res = new XModuleResources(assets, origRes.getDisplayMetrics(), origRes.getConfiguration()); else res = new XModuleResources(assets, null, null); AndroidAppHelper.addActiveResource(modulePath, res.hashCode(), false, res); return res; }
private static void selectCallType(final XC_MethodHook.MethodHookParam param) { Resources res = AndroidAppHelper.currentApplication().getResources(); String callWithHangouts = res.getString( res.getIdentifier(HANGOUTS_STR_CALL_WITH_HANGOUTS, "string", HANGOUTS_RES_PKG_NAME)); String callWithCellular = res.getString( res.getIdentifier(HANGOUTS_STR_CALL_WITH_PSTN, "string", HANGOUTS_RES_PKG_NAME)); CharSequence options[] = new CharSequence[]{callWithHangouts, callWithCellular}; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(""); builder.setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: hangoutsCall(param); break; case 1: cellularCall(); break; } } }); builder.show(); }
private static String getCrashTip() { Context context = null; try { context = AndroidAppHelper.currentApplication().createPackageContext(PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY); return context.getString(R.string.crash_tip) + ": "; } catch (PackageManager.NameNotFoundException e) { return ""; } }
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable { if (!lpparam.packageName.equals("zebpay.Application")) return; findAndHookMethod("zebpay.Application.activity.SplashActivity", lpparam.classLoader, "b", new XC_MethodReplacement() { @Override protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { String warning = "App has been hooked by third party app, but ignored by Zebpay Unblock. HODL!"; Context context = AndroidAppHelper.currentApplication(); Toast toast = Toast.makeText(context, warning, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } }); }
private String getShotObject() { String ret = getLollipopRecentTask(); if (ret.isEmpty()) if (BoolConfigIO.get(REC)) return "RecentTasksList"; else return "unknown"; else if (((KeyguardManager) AndroidAppHelper.currentApplication().getSystemService(Context.KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()) return "LockScreen"; else { Log.d(TAG, "getShotObject:" + ret); return ret; } }
public boolean connect(Context context) { if (isConnected()) { return true; } ComponentName cn; if (context == null) { // only valid from Xposed context in hooked app context = AndroidAppHelper.currentApplication(); cn = new ComponentName(THIS_APP, THIS_APP + ".JoystickService"); } else { cn = new ComponentName(context, JoystickService.class); } if (context != null) { if (messenger == null) { messenger = new Messenger(incomingHandler); } Intent intent = new Intent(); intent.setComponent(cn); if (!context.bindService(intent, this, Context.BIND_AUTO_CREATE)) { Toast.makeText(AndroidAppHelper.currentApplication(), "Unable to start service! Did you reboot after updating?", Toast.LENGTH_SHORT).show(); } return true; } return false; }
@SuppressWarnings("deprecation") @Override public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable { prefs = AndroidAppHelper.getSharedPreferencesForPackage(MY_PACKAGE_NAME, Common.PREFS, Context.MODE_PRIVATE); //prefs = new XSharedPreferences(MY_PACKAGE_NAME, Common.PREFS).makeWorldReadable(); MODULE_PATH = startupParam.modulePath; mDebugMode = prefs.getBoolean(Common.PREF_DEBUG_MODE, false); }
@Override public void modifySensor(final XC_LoadPackage.LoadPackageParam lpparam) { XC_MethodHook mockSensorHook = new XC_MethodHook() { @SuppressWarnings("unchecked") @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Object systemSensorManager = XposedHelpers.getObjectField(param.thisObject, "mManager"); SparseArray<Sensor> sensors = getSensors(systemSensorManager); // params.args[] is an array that holds the arguments that dispatchSensorEvent received, which are a handle pointing to a sensor // in sHandleToSensor and a float[] of values that should be applied to that sensor. int handle = (Integer) (param.args[0]); // This tells us which sensor was currently called. Sensor sensor = sensors.get(handle); Context context = AndroidAppHelper.currentApplication(); if (!isPackageAllowedToSeeTrueSensor(lpparam.processName, sensor, context) && getSensorStatus(sensor, context) == Constants.SENSOR_STATUS_MOCK_VALUES) { float[] values = getSensorValues(sensor, context); /*The SystemSensorManager compares the array it gets with the array from the a SensorEvent, and some sensors (looking at you, Proximity) only use one index in the array but still send along a length 3 array, so we copy here instead of replacing it outright. */ //noinspection SuspiciousSystemArraycopy System.arraycopy(values, 0, param.args[1], 0, values.length); } } }; XposedHelpers.findAndHookMethod("android.hardware.SystemSensorManager$SensorEventQueue", lpparam.classLoader, "dispatchSensorEvent", int.class, float[].class, int.class, long.class, mockSensorHook); }
@Override public void initZygote(StartupParam startupParam) throws Throwable { loadPrefs(); try { XposedHelpers.findAndHookMethod( Resources.class, "updateConfiguration", Configuration.class, DisplayMetrics.class, "android.content.res.CompatibilityInfo", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { if (param.args[0] == null) { return; } String packageName; Resources res = ((Resources) param.thisObject); if (res instanceof XResources) { packageName = ((XResources) res).getPackageName(); } else if (res instanceof XModuleResources) { return; } else { try { packageName = XResources.getPackageNameDuringConstruction(); } catch (IllegalStateException e) { return; } } String hostPackageName = AndroidAppHelper.currentPackageName(); boolean isActiveApp = hostPackageName.equals(packageName); Configuration newConfig = null; if (packageName != null) { Locale loc = getPackageSpecificLocale(packageName); if (loc != null) { newConfig = new Configuration((Configuration) param.args[0]); setConfigurationLocale(newConfig, loc); if (isActiveApp) { Locale.setDefault(loc); } } } if (newConfig != null) { param.args[0] = newConfig; } } } ); } catch (Throwable t) { XposedBridge.log(t); } }
@Override public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable { installPackageHook = new XC_MethodHook() { @Override public void beforeHookedMethod(MethodHookParam param) throws Throwable { mContext = AndroidAppHelper.currentApplication(); mContext = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext"); boolean isInstallStage = "installStage".equals(param.method.getName()); int flags = 0; int id = 0; if (isInstallStage) { try { id = 4; flags = (Integer) XposedHelpers.getObjectField(param.args[id], "installFlags"); XposedBridge.log("PreventADBInstall: Hook Flags Success!"); } catch (Exception e) { XposedBridge.log(e); } } else { try { id = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? 2 : 1; flags = (Integer) param.args[id]; XposedBridge.log("PreventADBInstall: Hook Flags Success!"); } catch (Exception e) { XposedBridge.log(e); } } if (isInstallStage) { Object sessions = param.args[id]; XposedHelpers.setIntField(sessions, "installFlags", flags); param.args[id] = sessions; } else { param.args[id] = flags; } if ((getCallingUid() == 2000) || (getCallingUid() == 0)) { param.setResult(null); XposedBridge.log("PreventADBInstall: Block Success!"); Looper.prepare(); Toast.makeText(mContext, "拦截 ADB 安装成功!", Toast.LENGTH_LONG).show(); Looper.loop(); return; } } }; }
private static Context getContext() { return (Context) AndroidAppHelper.currentApplication(); }
@Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { if (!lpparam.packageName.equals("android")) return; XC_MethodHook hook = new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { settingsHelper.reload(); if (settingsHelper.isModDisabled()) return; Intent intent = (Intent) XposedHelpers.getObjectField(param.thisObject, "intent"); // The launching app does not expect data back. It's safe to run the activity in a // new task. int requestCode = getIntField(param.thisObject, "requestCode"); if (requestCode != -1) return; // The intent already has FLAG_ACTIVITY_NEW_TASK set, no need to do anything. if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == Intent.FLAG_ACTIVITY_NEW_TASK) return; String intentAction = intent.getAction(); // If the intent is not a known safe intent (as in, the launching app does not expect // data back, so it's safe to run in a new task,) ignore it straight away. if (intentAction == null) return; // If the app is launching one of its own activities, we shouldn't open it in a new task. int uid = ((ActivityInfo) getObjectField(param.thisObject, "info")).applicationInfo.uid; if (getIntField(param.thisObject, "launchedFromUid") == uid) return; ComponentName componentName = (ComponentName) getObjectField(param.thisObject, "realActivity"); String componentNameString = componentName.flattenToString(); // Log if necessary. if (settingsHelper.isLogEnabled()) { // Get context Context context = AndroidAppHelper.currentApplication(); if (context != null) context.sendBroadcast(new Intent(Common.INTENT_LOG).putExtra(Common.INTENT_COMPONENT_EXTRA, componentNameString)); else XposedBridge.log("activityforcenewtask: couldn't get context."); XposedBridge.log("activityforcenewtask: componentString: " + componentNameString); } // If the blacklist is used and the component is in the blacklist, or if the // whitelist is used and the component isn't whitelisted, we shouldn't modify // the intent's flags. boolean isListed = settingsHelper.isListed(componentNameString); String listType = settingsHelper.getListType(); if ((listType.equals(Common.PREF_BLACKLIST) && isListed) || (listType.equals(Common.PREF_WHITELIST) && !isListed)) return; intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } }; Class ActivityRecord = findClass("com.android.server.am.ActivityRecord", lpparam.classLoader); XposedBridge.hookAllConstructors(ActivityRecord, hook); }