Xposed 常用方法和技巧

修改IMEI:

HookIMEI(TelephonyManager.class, "getDeviceId", data);
public static void HookIMEI(final Class<?> cls, final String method, final String result) {
    log(TAG+"->HookIMEI:"+result);
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void   
            afterHookedMethod(MethodHookParam param)throws Throwable {
                param.setResult(result);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookIMEI:"+ e.getMessage());
    }
}

修改IMSI:

HookIMSI(TelephonyManager.class, "getSubscriberId", data);
public static void HookIMSI(final Class<?> cls, final String method, final String result) {
    log(TAG+"->HookIMSI:"+result);
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                param.setResult(result);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookIMSI:"+ e.getMessage());
    }
}

修改Android_id:

HookAndroidID(Secure.class, "getString", Secure.ANDROID_ID, data);
HookAndroidID(System.class, "getString", Secure.ANDROID_ID, data);
public static void HookAndroidID(final Class<?> cls, final String method, final String type, final String result) {
    try {
        log(TAG+"->HookAndroidID:"+result);

        Object[] obj = new Object[3];
        obj[0] = ContentResolver.class;
        obj[1] = String.class;
        obj[2] = new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                if (param.args[1].equals(type)) {
                    param.setResult(result);
                }
            }
        };
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookAndroidID:"+ e.getMessage());
    }
}

修改Build相关参数:

// Hoook Build.ID
HookBuildID(Build.class, "ID", data);
public static void HookBuildID(final Class<?> cls, String fieldName, final String result) {
    log(TAG+"->HookBuildID:"+result);
    try {
        XposedHelpers.setStaticObjectField(cls, fieldName, result);
    } catch (Throwable e) {
        log("ERROR:HookBuildID:"+ e.getMessage());
    }
}

// Hook Build.SDK_INT
HookVersionSDKInt(Build.VERSION.class, "SDK_INT", sdkInt);
public static void HookVersionSDKInt(final Class<?> cls, String fieldName, final int result) {
    log(TAG+"->HookVersionSDKInt:"+result);
    try {
        XposedHelpers.setStaticObjectField(cls, fieldName, result);
    } catch (Throwable e) {
        log("ERROR:HookVersionSDKInt:"+ e.getMessage());
    }
}
// 其它Build修改同理

修改WifiInfo相关参数:

// Hook getBSSID
HookWifiBSSID(WifiInfo.class, "getBSSID", bssid);
public static  void HookWifiBSSID(final Class<?> cls, final String method, final String result) {
    log(TAG+"->HookWifiBSSID:"+result);
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                param.setResult(result);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookWifiBSSID:"+ e.getMessage());
    }
}

修改DisplayMetrics相关参数:

// Hook getMetrics
HookDisplayMetrics(Display.class, "getMetrics", width, height, desity, desityDpi, xDpi, yDpi);
public static void HookDisplayMetrics(final Class<?> cls, final String method, 
        final int widthPixels, final int heightPixels,
        final Float desity, final int desityDpi, final Float xDpi,
        final Float yDpi) {
    try {
        Object[] obj = new Object[2];
        obj[0] = DisplayMetrics.class;
        obj[1] = new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                DisplayMetrics dm = (DisplayMetrics)param.args[0];
                if(heightPixels > 0)dm.heightPixels = heightPixels;
                if(widthPixels > 0)dm.widthPixels = widthPixels;
                if(desityDpi > 0)dm.densityDpi = desityDpi;
                if(yDpi > 0.0f)dm.ydpi = yDpi;
                if(xDpi > 0.0f)dm.xdpi = xDpi;
                if(desity > 0.0f)dm.density = desity;
                if(widthPixels > 0 ){
                    Field widField = DisplayMetrics.class.getDeclaredField("noncompatWidthPixels");
                    widField.setAccessible(true);
                    widField.set(dm, widthPixels);
                }
                if(heightPixels > 0 ){
                    Field heightField = DisplayMetrics.class.getDeclaredField("noncompatHeightPixels");
                    heightField.setAccessible(true);
                    heightField.set(dm, heightPixels);
                }
                if(desityDpi > 0){
                    Field ddpiCompatField = DisplayMetrics.class.getDeclaredField("noncompatDensityDpi");
                    ddpiCompatField.setAccessible(true);
                    ddpiCompatField.set(dm, desityDpi);
                }
                if(xDpi > 0.0f){
                    Field xdpiCompatField = DisplayMetrics.class.getDeclaredField("noncompatXdpi");
                    xdpiCompatField.setAccessible(true);
                    xdpiCompatField.set(dm, xDpi);
                }
                if(yDpi > 0.0f){
                    Field ydpiCompatField = DisplayMetrics.class.getDeclaredField("noncompatYdpi");
                    ydpiCompatField.setAccessible(true);
                    ydpiCompatField.set(dm, yDpi);
                }
            }
        };
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookDisplayMetrics:"+ e.getMessage());
    }
}

修改Display相关参数:

// Hook getWidth  getHeight
HookDisplayWidth(Display.class, "getWidth", disWidth);
HookDisplayHeight(Display.class, "getHeight", disHeight);
public static void HookDisplayHeight(final Class<?> cls, final String method, final int result) {
    log(TAG+"->HookDisplayHeight:"+result);
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                param.setResult(result);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookDisplayHeight:"+ e.getMessage());
    }
}
public static void HookDisplayWidth(final Class<?> cls, final String method, final int result) {
    log(TAG+"->HookDisplayWidth:"+result);
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                param.setResult(result);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookDisplayWidth:"+ e.getMessage());
    }
}

修改SystemHttpAgent相关参数:

// Hook System getProperty
HookSystemHttpAgent(System.class, "getProperty", data));
public static void HookSystemHttpAgent(final Class<?> cls, final String method, final String result) {
    log(TAG+"->HookSystemHttpAgent: "+result);
    try {
        Object[] obj = new Object[2];
        obj[0] = String.class;
        obj[1] = new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                if(param.args[0].equals("http.agent")){
                    param.setResult(result);
                }
            }
        };
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookSystemHttpAgent:"+ e.getMessage());
    }
}

修改手机安装包信息:

// Hook ApplicationPackageManager getInstalledPackages
HookInstalledPackages("android.app.ApplicationPackageManager", lpparam, "getInstalledPackages")
public static void HookInstalledPackages(String className, LoadPackageParam lpparam, String method) {
    log(TAG+"->HookInstalledPackages.");
    try {
        ClassLoader loader = lpparam.classLoader;
        Object[] obj = new Object[2];
        obj[0] = Integer.TYPE.getName();
        obj[1]= new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                List<PackageInfo> packs = (List<PackageInfo>) param.getResult();
                List<PackageInfo> res = new ArrayList<PackageInfo>();
                for(PackageInfo pi:packs){
                     if(pi.applicationInfo.packageName.contains("com.microvirt") 
                        || pi.applicationInfo.packageName.contains("com.thirdparty.superuser") 
                        || pi.applicationInfo.packageName.contains("de.robv.android.xposed.installer"))
                     {
                          continue;
                     }
                     res.add(pi);
                }
                param.setResult(res);
            }
        };
        XposedHelpers.findAndHookMethod(className, loader, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookInstalledPackages:"+ e.getMessage());
    }
}

WIFI链接信息:

// Hook WifiManager getConnectionInfo
HookWifiGetConnectionInfo(WifiManager.class, "getConnectionInfo", bssid, wifiMac, ssid);
public static void HookWifiGetConnectionInfo(final Class<?> cls, final String method, 
            final String mBSSID, final String mMacAddress, final String mSSID) {
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                log(TAG+"->HookWifiGetConnectionInfo:afterHookedMethod");
                WifiInfo result = (WifiInfo)param.getResult();
                WifiInfo wInfo = WifiInfo.class.getConstructor(WifiInfo.class).newInstance(result);
                // 
                Field fieldBssid = WifiInfo.class.getDeclaredField("mBSSID");
                fieldBssid.setAccessible(true);
                fieldBssid.set(wInfo, mBSSID);
                // 
                Field fieldMac = WifiInfo.class.getDeclaredField("mMacAddress");
                fieldMac.setAccessible(true);
                fieldMac.set(wInfo, mMacAddress);
                // 
                try {
                    Field fieldSSID = WifiInfo.class.getDeclaredField("mSSID");
                    fieldSSID.setAccessible(true);
                    fieldSSID.set(wInfo, mSSID);
                } catch (Throwable ex) {
                    try {
                        Field fieldWifiSsid = WifiInfo.class.getDeclaredField("mWifiSsid");
                        fieldWifiSsid.setAccessible(true);
                        Object mWifiSsid = fieldWifiSsid.get(wInfo);
                        if (mWifiSsid != null) {
                            Method methodCreateFromAsciiEncoded = mWifiSsid.getClass().getDeclaredMethod(
                                    "createFromAsciiEncoded", String.class);
                            fieldWifiSsid.set(wInfo, methodCreateFromAsciiEncoded.invoke(null, mSSID));
                        }
                    } catch (Throwable exex) {
                        Log.d("", exex.toString());
                    }
                }
                param.setResult(wInfo);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    } catch (Throwable e) {
        log("ERROR:HookWifiGetConnectionInfo:"+ e.getMessage());
    }
}

WIFI扫描信息:

// Hook WifiManager getScanResults
HookWifiGetScanResult(WifiManager.class, "getScanResults", json));
public static void HookWifiGetScanResult(final Class<?> cls, final String method, final String paramString) {
    try {
        Object[] obj = new Object[]{new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param)throws Throwable {
                List<ScanResult> rtn =(List<ScanResult>) param.getResult();
                List<ScanResult> scanResults = new ArrayList<ScanResult>() ;
                if(rtn.size()>0){
                    JSONArray array = new JSONArray(json);
                    for(int i=0; i<array.length(); i++){
                        JSONObject js   = array.getJSONObject(i);
                        String wifiname = js.getString("wifiname");
                        String wifimac  = js.getString("wifimac");
                        ScanResult scan = ScanResult.class.getConstructor(ScanResult.class).newInstance(rtn.get(0));
                        Field fieldssid = ScanResult.class.getDeclaredField("SSID");
                        fieldssid.setAccessible(true);
                        fieldssid.set(scan, wifiname);

                        Field fieldBssid = ScanResult.class.getDeclaredField("BSSID");
                        fieldBssid.setAccessible(true);
                        fieldBssid.set(scan, wifimac);
                        scanResults.add(scan);
                    }
                }
                param.setResult(scanResults);
            }
        }};
        XposedHelpers.findAndHookMethod(cls, method, obj);
    }catch (Throwable e) {
        log("ERROR:HookWifiGetConnectionInfo:"+ e.getMessage());
    }
}

File信息:

// Hook WifiManager getScanResults
public static class CHashMap{
    public String key   = "";
    public String value = "";

    public static CHashMap getNewHashMap(String key, String value){
        CHashMap map = new CHashMap();
        map.key = key;
        map.value = value;
        return map;
    }
}
// 需要修改的文件列表
List<CHashMap> hookFileList = new ArrayList<CHashMap>();
hookFileList.add(CHashMap.getNewHashMap("/system/app/Superuser",    "/sb/noZuoNoDie_su"));
hookFileList.add(CHashMap.getNewHashMap("/system/app/Suser",        "/sb/noZuoNoDie_su"));
hookFileList.add(CHashMap.getNewHashMap("/system/bin/su",           "/sb/noZuoNoDie_su"));
hookFileList.add(CHashMap.getNewHashMap("/system/xbin/su",          "/sb/noZuoNoDie_su"));
hookFileList.add(CHashMap.getNewHashMap("/system/sbin/su",          "/sb/noZuoNoDie_su"));
hookFileList.add(CHashMap.getNewHashMap("/sbin/su",                 "/sb/noZuoNoDie_su"));
hookFileList.add(CHashMap.getNewHashMap("/vendor/bin/su",           "/sb/noZuoNoDie_su"));
// 其它指定目录
String fileRoot = "/sdcard/hardwareInfo/";
hookFileList.add(CHashMap.getNewHashMap("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", fileRoot + "cpuinfo_max_freq"));
hookFileList.add(CHashMap.getNewHashMap("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq", fileRoot + "cpuinfo_min_freq"));
hookFileList.add(CHashMap.getNewHashMap("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq", fileRoot + "cpuinfo_cur_freq"));
hookFileList.add(CHashMap.getNewHashMap("/proc/cpuinfo", fileRoot + "cpuinfo"));
hookFileList.add(CHashMap.getNewHashMap("/proc/meminfo", fileRoot + "meminfo"));
// Hook     
HookFile_path(lpparam, hookFileList);
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值