Java Code Examples for de.robv.android.xposed.XposedHelpers#setObjectField()

The following examples show how to use de.robv.android.xposed.XposedHelpers#setObjectField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AweMeHook.java    From xposed-aweme with Apache License 2.0 6 votes vote down vote up
/**
 * 移除推荐的广告
 * @param feedList
 * @return
 */
private Object removeFeedAd(Object feedList) {

    if (feedList == null) return null;

    try {
        List<Object> newItems = new ArrayList<>();
        List<Object> items = (List<Object>) XposedHelpers
                .getObjectField(feedList, mVersionConfig.fieldFeedListItems);

        for (Object item : items) {
            // 只添加非广告视频
            if (!isAd(item)) newItems.add(item);
        }

        // 重新设置列表数据
        XposedHelpers.setObjectField(feedList,
                mVersionConfig.fieldFeedListItems, newItems);
    } catch (Throwable tr) {
        Alog.e("移除广告异常", tr);
    }
    return feedList;
}
 
Example 2
Source File: XposedHelpersWraper.java    From MIUIAnesthetist with MIT License 5 votes vote down vote up
public static void setObjectField(Object obj, String fieldName, Object value) {
    try {
        XposedHelpers.setObjectField(obj, fieldName, value);
    } catch (Throwable t) {
        log(t);
    }
}
 
Example 3
Source File: RevokeMsgHook.java    From XposedWechatHelper with GNU General Public License v2.0 5 votes vote down vote up
private static void handleMessageRecall(ContentValues contentValues) {
    long msgId = contentValues.getAsLong("msgId");
    Object msg = msgCacheMap.get(msgId);
    if (msg != null) {
        long createTime = XposedHelpers.getLongField(msg, "field_createTime");
        XposedHelpers.setIntField(msg, "field_type", contentValues.getAsInteger("type"));
        XposedHelpers.setObjectField(msg, "field_content",
                contentValues.getAsString("content") + "(已被阻止)");
        XposedHelpers.setLongField(msg, "field_createTime", createTime + 1L);
        XposedHelpers.callMethod(storageInsertObject,
                ApiFactory.getCurrent().storage_MsgInfoStorage_insert_method, msg, false);
    }
}
 
Example 4
Source File: AntiRevoke.java    From WechatEnhancement with GNU General Public License v3.0 5 votes vote down vote up
private void handleMessageRecall(ContentValues contentValues) {
    long msgId = contentValues.getAsLong("msgId");
    Object msg = msgCacheMap.get(msgId);
    long createTime = XposedHelpers.getLongField(msg, "field_createTime");
    XposedHelpers.setIntField(msg, "field_type", contentValues.getAsInteger("type"));
    XposedHelpers.setObjectField(msg, "field_content",
            contentValues.getAsString("content") + "(已被阻止)");

    XposedHelpers.setLongField(msg, "field_createTime", createTime + 1L);
    XposedHelpers.callMethod(storageInsertClazz, HookParams.getInstance().MsgInfoStorageInsertMethod, msg, false);

}
 
Example 5
Source File: QsTile.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
public void applyTo(Object state) {
    XposedHelpers.setBooleanField(state, "visible", visible);
    XposedHelpers.setObjectField(state, "icon", getResourceIcon());
    XposedHelpers.setObjectField(state, "label", label);
    XposedHelpers.setBooleanField(state, "autoMirrorDrawable", autoMirrorDrawable);
    XposedHelpers.setBooleanField(state, "value", booleanValue);
}
 
Example 6
Source File: QsTileEventDistributor.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void recreateTiles() {
    try {
        mPrefs.reload();
        if (Utils.isXperiaDevice()) {
            XposedHelpers.setObjectField(mHost, "mQuickSettingsTilesDefault", "");
            XposedHelpers.callMethod(mHost, "onConfigurationChanged");
        } else {
            XposedHelpers.callMethod(mHost, "onTuningChanged",
                    ModQsTiles.TILES_SETTING, (String) null);
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 7
Source File: ModLockscreen.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private static void beforeLockPatternDraw(final Class<? extends Enum> displayModeEnum, final Object thisObject) {
    final Object patternDisplayMode = XposedHelpers.getObjectField(thisObject, "mPatternDisplayMode");
    final Boolean inStealthMode = XposedHelpers.getBooleanField(thisObject, "mInStealthMode");

    if (!mPrefs.getBoolean(GravityBoxSettings.PREF_KEY_LOCKSCREEN_SHOW_PATTERN_ERROR, true) &&
            mPatternDisplayMode == null && patternDisplayMode == Enum.valueOf(displayModeEnum, "Wrong")) {
        mInStealthMode = inStealthMode;
        mPatternDisplayMode = patternDisplayMode;
        XposedHelpers.setBooleanField(thisObject, "mInStealthMode", true);
        XposedHelpers.setObjectField(thisObject, "mPatternDisplayMode", Enum.valueOf(displayModeEnum, "Correct"));
    } else {
        mPatternDisplayMode = null;
    }
}
 
Example 8
Source File: ModLockscreen.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private static void afterLockPatternDraw(final Object thisObject) {
    if (null != mPatternDisplayMode) {
        XposedHelpers.setBooleanField(thisObject, "mInStealthMode", mInStealthMode);
        XposedHelpers.setObjectField(thisObject, "mPatternDisplayMode", mPatternDisplayMode);
        mInStealthMode = false;
        mPatternDisplayMode = null;
    }
}
 
Example 9
Source File: API24.java    From VirtualSensor with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
    super.afterHookedMethod(param);
    ArrayList<Sensor> mFullSensorsList = (ArrayList<Sensor>) XposedHelpers.getObjectField(param.thisObject, "mFullSensorsList");
    HashMap<Integer, Sensor> mHandleToSensor = (HashMap<Integer, Sensor>)((HashMap<Integer, Sensor>) XposedHelpers.getObjectField(param.thisObject, "mHandleToSensor")).clone();

    XposedHelpers.findField(SystemSensorManagerHook.SYSTEM_SENSOR_MANAGER, "mFullSensorsList").setAccessible(true);
    XposedHelpers.findField(SystemSensorManagerHook.SYSTEM_SENSOR_MANAGER, "mHandleToSensor").setAccessible(true);

    this.mSystemSensorManagerHook.fillSensorLists(mFullSensorsList, mHandleToSensor);
    XposedHelpers.setObjectField(param.thisObject, "mHandleToSensor", mHandleToSensor.clone());
    XposedHelpers.setObjectField(param.thisObject, "mFullSensorsList", mFullSensorsList.clone());
}
 
Example 10
Source File: API23.java    From VirtualSensor with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
    super.afterHookedMethod(param);
    ArrayList<Sensor> mFullSensorsList = (ArrayList<Sensor>) XposedHelpers.getObjectField(param.thisObject, "mFullSensorsList");
    SparseArray<Sensor> mHandleToSensor = ((SparseArray<Sensor>) XposedHelpers.getObjectField(param.thisObject, "mHandleToSensor")).clone();

    XposedHelpers.findField(SystemSensorManagerHook.SYSTEM_SENSOR_MANAGER, "mFullSensorsList").setAccessible(true);
    XposedHelpers.findField(SystemSensorManagerHook.SYSTEM_SENSOR_MANAGER, "mHandleToSensor").setAccessible(true);

    this.mSystemSensorManagerHook.fillSensorLists(mFullSensorsList, mHandleToSensor);
    XposedHelpers.setObjectField(param.thisObject, "mHandleToSensor", mHandleToSensor.clone());
    XposedHelpers.setObjectField(param.thisObject, "mFullSensorsList", mFullSensorsList.clone());
}
 
Example 11
Source File: RetalDriverApplication.java    From ratel with Apache License 2.0 4 votes vote down vote up
@Override
protected void attachBaseContext(Context base) {
    //第一步需要call supper,否则Application并不完整,还无法作为context使用,当然此时base context是可用状态
    super.attachBaseContext(base);
    //exposed框架,在driver下面定义,所以需要在替换classloader之前,完成exposed框架的so库加载
    ExposedBridge.initOnce(this, getApplicationInfo(), getClassLoader());

    if (!checkSupport()) {
        throw new IllegalStateException("epic 不支持的版本");
    }
    //释放两个apk,一个是xposed模块,一个是原生的apk,原生apk替换为当前的Application作为真正的宿主,xposed模块apk在Application被替换之前作为补丁代码注入到当前进程
    releaseApkFiles();

    //替换classloader
    Class<?> contextImplClazz = XposedHelpers.findClassIfExists("android.app.ContextImpl", base.getClassLoader());
    Object contextImpl = XposedHelpers.callStaticMethod(contextImplClazz, "getImpl", base);
    Object loadApk = XposedHelpers.getObjectField(contextImpl, "mPackageInfo");
    ClassLoader parentClassLoader = RetalDriverApplication.class.getClassLoader();
    try {
        //  Class<?> aClass = XposedHelpers.findClass("android.app.LoadedApk", RetalDriverApplication.class.getClassLoader());
        parentClassLoader = (ClassLoader) XposedHelpers.getObjectField(loadApk, "mClassLoader");
    } catch (Exception e) {
        //ignore
    }
    String originApkSourceDir = new File(ratelWorkDir(this), originAPKFileName).getAbsolutePath();
    PathClassLoader originClassLoader = new PathClassLoader(originApkSourceDir, parentClassLoader);
    XposedHelpers.setObjectField(loadApk, "mClassLoader", originClassLoader);

    //context中的resource,仍然绑定在老的apk环境下,现在把他们迁移
    ApplicationInfo appinfoInLoadedApk = (ApplicationInfo) XposedHelpers.getObjectField(loadApk, "mApplicationInfo");
    appinfoInLoadedApk.sourceDir = originApkSourceDir;
    XposedHelpers.setObjectField(loadApk, "mAppDir", originApkSourceDir);
    XposedHelpers.setObjectField(loadApk, "mResDir", originApkSourceDir);
    XposedHelpers.setObjectField(loadApk, "mResources", null);
    Resources resources = (Resources) XposedHelpers.callMethod(loadApk, "getResources", currentActivityThread());
    if (resources != null) {
        XposedHelpers.setObjectField(contextImpl, "mResources", resources);
    }
    //替换之后,再也无法访问容器apk里面的资源了,容器中的所有资源全部被替换为原始apk的资源
    loadResources(originApkSourceDir);
}
 
Example 12
Source File: RetalDriverApplication.java    From ratel with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onCreate() {
    super.onCreate();
    String appClassName = getOriginApplicationName();
    if (appClassName == null) {
        loadXposedModule(this);
        return;
    }

    //有值的话调用该Applicaiton
    Object currentActivityThread = currentActivityThread();
    Object mBoundApplication = XposedHelpers.getObjectField("currentActivityThread", "mBoundApplication");

    Object loadedApkInfo = XposedHelpers.getObjectField(mBoundApplication, "info");
    //把当前进程的mApplication 设置成了null
    XposedHelpers.setObjectField(loadedApkInfo, "mApplication", null);
    Application oldApplication = (Application) XposedHelpers.getObjectField(currentActivityThread, "mInitialApplication");

    //http://www.codeceo.com/article/android-context.html
    ArrayList<Application> mAllApplications = (ArrayList<Application>) XposedHelpers.getObjectField(currentActivityThread, "mAllApplications");
    mAllApplications.remove(oldApplication);//删除oldApplication

    ApplicationInfo appinfoInLoadedApk = (ApplicationInfo) XposedHelpers.getObjectField(loadedApkInfo, "mApplicationInfo");

    ApplicationInfo appinfoInAppBindData = (ApplicationInfo) XposedHelpers.getObjectField(mBoundApplication, "appInfo");

    appinfoInLoadedApk.className = appClassName;
    appinfoInAppBindData.className = appClassName;

    loadXposedModule(this);
    //makeApplication 的时候,就会调用attachBaseContext方法
    Application app = (Application) XposedHelpers.callMethod(loadedApkInfo, "makeApplication", false, null);
    XposedHelpers.setObjectField(currentActivityThread, "mInitialApplication", app);

    ArrayMap mProviderMap = (ArrayMap) XposedHelpers.getObjectField(currentActivityThread, "mProviderMap");
    for (Object providerClientRecord : mProviderMap.values()) {
        Object localProvider = XposedHelpers.getObjectField(providerClientRecord, "mLocalProvider");
        XposedHelpers.setObjectField(localProvider, "mContext", app);
    }
    app.onCreate();

}
 
Example 13
Source File: xposedObject.java    From XKik with GNU General Public License v3.0 4 votes vote down vote up
void set(String var, Object value) {
    XposedHelpers.setObjectField(obj, var, value);
}
 
Example 14
Source File: ModDisplay.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
private static void updateAutobrightnessConfig(int[] lux, int[] brightness) {
    if (mDisplayPowerController == null || mContext == null) return;

    if (DEBUG) log("updateAutobrightnessConfig called");
    Resources res = mContext.getResources();
    boolean mtkVirtualValuesSupport = false;
    boolean mtkVirtualValues = false;

    int screenBrightnessDim = res.getInteger(res.getIdentifier(
            "config_screenBrightnessDim", "integer", "android"));
    int screenBrightnessMinimum = res.getInteger(res.getIdentifier(
            "config_screenBrightnessSettingMinimum", "integer", "android"));
    screenBrightnessMinimum = Math.min(screenBrightnessDim, screenBrightnessMinimum);

    boolean useSwAutobrightness = XposedHelpers.getBooleanField(
            mDisplayPowerController, "mUseSoftwareAutoBrightnessConfig");

    if (useSwAutobrightness) {
        // brightness array must have one more element than lux array
        int[] brightnessAdj = new int[lux.length + 1];
        for (int i = 0; i < brightnessAdj.length; i++) {
            if (i < brightness.length) {
                brightnessAdj[i] = brightness[i];
            } else {
                brightnessAdj[i] = 255;
            }
        }
        if (DEBUG) log("updateAutobrightnessConfig: lux=" + Utils.intArrayToString(lux) +
                "; brightnessAdj=" + Utils.intArrayToString(brightnessAdj));

        if (Utils.isMtkDevice()) {
            try {
                mtkVirtualValues = (boolean) XposedHelpers.getStaticBooleanField(
                        mDisplayPowerController.getClass(), "MTK_ULTRA_DIMMING_SUPPORT");
                int resId = res.getIdentifier("config_screenBrightnessVirtualValues",
                        "bool", "android");
                if (resId != 0) {
                    mtkVirtualValues &= res.getBoolean(resId);
                }
                mtkVirtualValuesSupport = true;
                if (DEBUG) log("MTK brightness virtual values: " + mtkVirtualValues);
            } catch (Throwable t) {
                if (DEBUG) log("Couldn't detect MTK virtual values feature");
            }
        }

        Object autoBrightnessSpline = mtkVirtualValuesSupport ? XposedHelpers.callMethod(
                mDisplayPowerController, "createAutoBrightnessSpline",
                lux, brightnessAdj, mtkVirtualValues) :
                XposedHelpers.callMethod(mDisplayPowerController,
                        "createAutoBrightnessSpline", lux, brightnessAdj);
        if (autoBrightnessSpline != null) {
            Object abrCtrl = XposedHelpers.getObjectField(mDisplayPowerController,
                    "mAutomaticBrightnessController");
            XposedHelpers.setObjectField(abrCtrl,
                    "mScreenAutoBrightnessSpline", autoBrightnessSpline);
            if (brightnessAdj[0] < screenBrightnessMinimum) {
                screenBrightnessMinimum = brightnessAdj[0];
            }
        } else {
            XposedHelpers.setBooleanField(mDisplayPowerController, "mUseSoftwareAutoBrightnessConfig", false);
            log("Error computing auto-brightness spline: lux=" + Utils.intArrayToString(lux) +
                    "; brightnessAdj=" + Utils.intArrayToString(brightnessAdj));
        }
    }

    int screenBrightnessRangeMinimum = mtkVirtualValuesSupport ?
            (Integer) XposedHelpers.callMethod(mDisplayPowerController, "clampAbsoluteBrightness",
                    screenBrightnessMinimum, mtkVirtualValues) :
            (Integer) XposedHelpers.callMethod(
                    mDisplayPowerController, "clampAbsoluteBrightness", screenBrightnessMinimum);
    XposedHelpers.setIntField(mDisplayPowerController, "mScreenBrightnessRangeMinimum",
            screenBrightnessRangeMinimum);

    if (DEBUG) log("Autobrightness config updated");
}
 
Example 15
Source File: ModExpandedDesktop.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
private static void setObj(String field, Object value) {
    XposedHelpers.setObjectField(mPhoneWindowManager, field, value);
}
 
Example 16
Source File: SystemSensorManagerHook.java    From VirtualSensor with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void fillSensorLists(ArrayList<Sensor> fullSensorList, Object handleToSensor) throws IllegalAccessException, InstantiationException, InvocationTargetException {
    Iterator<Sensor> iterator = fullSensorList.iterator();

    int minDelayAccelerometer = 0;
    List<SensorModel> sensorsNotToAdd = new ArrayList<>();
    while (iterator.hasNext()) {
        Sensor sensor = iterator.next();
        if (XposedMod.sensorsToEmulate.indexOfKey(sensor.getType()) >= 0) {
            sensorsNotToAdd.add(XposedMod.sensorsToEmulate.get(sensor.getType()));
            if (!sensor.getVendor().equals("Xposed")) XposedMod.sensorsToEmulate.get(sensor.getType()).isAlreadyNative = true;
        }

        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            minDelayAccelerometer = sensor.getMinDelay();
            XposedMod.ACCELEROMETER_RESOLUTION = sensor.getResolution();
        }
        if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) XposedMod.MAGNETIC_RESOLUTION = sensor.getResolution();
    }

    XposedHelpers.findConstructorBestMatch(Sensor.class).setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mName").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mType").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mVendor").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mVersion").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mHandle").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mResolution").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mMinDelay").setAccessible(true);
    XposedHelpers.findField(Sensor.class, "mMaxRange").setAccessible(true);
    if (Build.VERSION.SDK_INT > 19) XposedHelpers.findField(Sensor.class, "mStringType").setAccessible(true);
    if (Build.VERSION.SDK_INT > 19) XposedHelpers.findField(Sensor.class, "mRequiredPermission").setAccessible(true);

    for (int i = 0; i < XposedMod.sensorsToEmulate.size(); i++) {
        SensorModel model = XposedMod.sensorsToEmulate.valueAt(i);
        if (!sensorsNotToAdd.contains(model)) {
            Sensor s = (Sensor) XposedHelpers.findConstructorBestMatch(Sensor.class).newInstance();
            XposedHelpers.setObjectField(s, "mType", XposedMod.sensorsToEmulate.keyAt(i));
            XposedHelpers.setObjectField(s, "mName", model.name);
            XposedHelpers.setObjectField(s, "mVendor", "Xposed");
            XposedHelpers.setObjectField(s, "mVersion", BuildConfig.VERSION_CODE);
            XposedHelpers.setObjectField(s, "mHandle", model.handle);
            XposedHelpers.setObjectField(s, "mMinDelay", model.minDelay == -1 ? minDelayAccelerometer : model.minDelay);
            if (Build.VERSION.SDK_INT > 19)
                XposedHelpers.setObjectField(s, "mStringType", model.stringType);
            XposedHelpers.setObjectField(s, "mResolution", model.resolution == -1 ? 0.01F : model.resolution); // This 0.01F is a placeholder, it doesn't seem to change anything but I keep it
            if (model.maxRange != -1)
                XposedHelpers.setObjectField(s, "mMaxRange", model.maxRange);

            if (!model.permission.equals("none") && Build.VERSION.SDK_INT > 19)
                XposedHelpers.setObjectField(s, "mRequiredPermission", model.permission);

            fullSensorList.add(s);
            if (handleToSensor.getClass() == SparseArray.class) ((SparseArray) handleToSensor).put(model.handle, s);
            else if (handleToSensor.getClass() == HashMap.class) ((HashMap) handleToSensor).put(model.handle, s);
        }
    }
}