Xposed 修改硬體函式 不適合新手閱讀 這是重寫版本 之前的寫的太垃圾了

世界美景發表於2017-11-03

         具體我就不多說了 xpsoed相關 看老帖子  重寫版本注重程式碼 


   讀取器 獲取硬體相關資訊  方便檢測HOOK成功了嗎 我只獲取了少部分

---------------------------------------------------------------------------------------------------------------------------

 private void init() {
                DisplayMetrics book=new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(book);




                try {
                    Class localClass = Class.forName("android.os.SystemProperties");
                    Object localObject1 = localClass.newInstance();
                    Object localObject2 = localClass.getMethod("get", new Class[] { String.class, String.class }).invoke(localObject1, new Object[] { "gsm.version.baseband", "no message" });
                    setEditText(R.id.get,localObject2+"");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //獲取網路連線管理者
                ConnectivityManager connectionManager = (ConnectivityManager)
                        getSystemService(CONNECTIVITY_SERVICE);
                //獲取網路的狀態資訊,有下面三種方式
                NetworkInfo networkInfo = connectionManager.getActiveNetworkInfo();

                setEditText(R.id.lianwang,networkInfo.getType()+"");
                setEditText(R.id.lianwangname,networkInfo.getTypeName());
                setEditText(R.id.imei, phone.getDeviceId());
                setEditText(R.id.deviceversion,phone.getDeviceSoftwareVersion());
                setEditText(R.id.imsi, phone.getSubscriberId());
                setEditText(R.id.number, phone.getLine1Number());
                setEditText(R.id.simserial, phone.getSimSerialNumber());
                setEditText(R.id.simoperator,phone.getSimOperator());
                setEditText(R.id.simoperatorname, phone.getSimOperatorName());
                setEditText(R.id.simcountryiso, phone.getSimCountryIso());
                setEditText(R.id.workType,phone.getNetworkType()+"");
                setEditText(R.id.netcountryiso,phone.getNetworkCountryIso());
                setEditText(R.id.netoperator,phone.getNetworkOperator());
                setEditText(R.id.netoperatorname,phone.getNetworkOperatorName());


                setEditText(R.id.radiovis,android.os.Build.getRadioVersion());
                setEditText(R.id.wifimac, wifi.getConnectionInfo().getMacAddress());
                setEditText(R.id.getssid,wifi.getConnectionInfo().getSSID());
                setEditText(R.id.getbssid,wifi.getConnectionInfo().getBSSID());
                setEditText(R.id.ip,wifi.getConnectionInfo().getIpAddress()+"");
                setEditText(R.id.bluemac, BluetoothAdapter.getDefaultAdapter()
                        .getAddress());
                setEditText(R.id.bluname, BluetoothAdapter.getDefaultAdapter().getName()
                );

                setEditText(R.id.cpu,Mnt.getCpuName());


                setEditText(R.id.andrlid_id,
                        Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID));
                setEditText(R.id.serial,android.os.Build.SERIAL);
                setEditText(R.id.brand,android.os.Build.BRAND);
                setEditText(R.id.tags, android.os.Build.TAGS);
                setEditText(R.id.device,android.os.Build.DEVICE);
                setEditText(R.id.fingerprint,android.os.Build.FINGERPRINT);
                setEditText(R.id.bootloader, Build.BOOTLOADER);
                setEditText(R.id.release, Build.VERSION.RELEASE);
                setEditText(R.id.sdk,Build.VERSION.SDK);
               // setEditText(R.id.sdk_INT,Build.VERSION.SDK_INT+"");
                setEditText(R.id.codename,Build.VERSION.CODENAME);
                setEditText(R.id.incremental,Build.VERSION.INCREMENTAL);
                setEditText(R.id.cpuabi, android.os.Build.CPU_ABI);
                setEditText(R.id.cpuabi2, android.os.Build.CPU_ABI2);
                setEditText(R.id.board, android.os.Build.BOARD);
                setEditText(R.id.model, android.os.Build.MODEL);
                setEditText(R.id.product, android.os.Build.PRODUCT);
                setEditText(R.id.type, android.os.Build.TYPE);
                setEditText(R.id.user, android.os.Build.USER);
                setEditText(R.id.disply, android.os.Build.DISPLAY);
                setEditText(R.id.hardware, android.os.Build.HARDWARE);
                setEditText(R.id.host, android.os.Build.HOST);
                setEditText(R.id.changshang, android.os.Build.MANUFACTURER);
                setEditText(R.id.phonetype,phone.getPhoneType()+"");
                setEditText(R.id.simstate,phone.getSimState()+"");
                setEditText(R.id.b_id,Build.ID);
                setEditText(R.id.gjtime,android.os.Build.TIME+"");
                setEditText(R.id.width,display.getWidth()+"");
                setEditText(R.id.height,display.getHeight()+"");
                setEditText(R.id.dpi,book.densityDpi+"");
                setEditText(R.id.density,book.density+"");
                setEditText(R.id.xdpi,book.xdpi+"");
                setEditText(R.id.ydpi,book.ydpi+"");
                setEditText(R.id.scaledDensity,book.scaledDensity+"");



                //setEditText(R.id.wl,getNetworkState(this)+"");
                // 方法2
                    DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);
                int width=dm.widthPixels;
                int  height=dm.heightPixels;

                setEditText(R.id.xwidth,width+"");
                setEditText(R.id.xheight,height+"");

            }


            private void setEditText(int id, String s) {
                 ((TextView) this.findViewById(id)).setText(s);
            }
-----------------------------------------------------------------------------------------------------------------------------------
 /**
     * 使用SharedPreferences  儲存輸入框輸入的資料
     */
    private void saveData() {
        try {
            SharedPreferences sh = this.getSharedPreferences("prefs",
                    Context.MODE_WORLD_READABLE);
            SharedPreferences.Editor pre = sh.edit();
            //    Logger.d("儲存內容");
            pre.putString("imei", this.getEditText(R.id.imei));
            pre.putString("deviceversion",this.getEditText(R.id.deviceversion));
            pre.putInt("phonetype", Integer.parseInt(this.getEditText(R.id.phonetype)));
            pre.putInt("simstate", Integer.parseInt(this.getEditText(R.id.simstate)));
            pre.putInt("width", Integer.parseInt(this.getEditText(R.id.width)));
            pre.putInt("height", Integer.parseInt(this.getEditText(R.id.height)));
            pre.putString("imsi", this.getEditText(R.id.imsi));
            pre.putString("number", this.getEditText(R.id.number));
            pre.putString("simserial", this.getEditText(R.id.simserial));
            pre.putString("simoperator", this.getEditText(R.id.simoperator));
            pre.putString("simoperatorname", this.getEditText(R.id.simoperatorname));
            pre.putString("simcountryiso", this.getEditText(R.id.simcountryiso));
            pre.putString("netcountryiso", this.getEditText(R.id.netcountryiso));
            pre.putString("netoperator", this.getEditText(R.id.netoperator));
            pre.putString("netoperatorname", this.getEditText(R.id.netoperatorname));
            pre.putString("radiovis",this.getEditText(R.id.radiovis));
            pre.putString("wifimac", this.getEditText(R.id.wifimac));
            pre.putString("bluemac", this.getEditText(R.id.bluemac));
            pre.putString("bluname",this.getEditText(R.id.bluname));
            pre.putString("serial", this.getEditText(R.id.serial));
            pre.putString("brand", this.getEditText(R.id.brand));
            pre.putString("tags", this.getEditText(R.id.tags));
            pre.putString("device", this.getEditText(R.id.device));
            pre.putString("fingerprint", this.getEditText(R.id.fingerprint));
            pre.putString("bootloader", this.getEditText(R.id.bootloader));
            pre.putString("release", this.getEditText(R.id.release));
            pre.putString("sdk", this.getEditText(R.id.sdk));
            pre.putString("codename", this.getEditText(R.id.codename));
            pre.putString("incremental", this.getEditText(R.id.incremental));
            pre.putString("cpuabi", this.getEditText(R.id.cpuabi));
            pre.putString("cpuabi2", this.getEditText(R.id.cpuabi2));
            pre.putString("board", this.getEditText(R.id.board));
            pre.putString("model", this.getEditText(R.id.model));
            pre.putString("product", this.getEditText(R.id.product));
            pre.putString("type", this.getEditText(R.id.type));
            pre.putString("user", this.getEditText(R.id.user));
            pre.putString("disply", this.getEditText(R.id.disply));
            pre.putString("hardware", this.getEditText(R.id.hardware));
            pre.putString("host", this.getEditText(R.id.host));
            pre.putString("changshang", this.getEditText(R.id.changshang));
            pre.putInt("time", Integer.parseInt(this.getEditText(R.id.gjtime)));
            pre.putString("androidid", this.getEditText(R.id.androidid));
            pre.putInt("dpi", Integer.parseInt(this.getEditText(R.id.dpi)));
            pre.apply();
        } catch (Throwable e) {
            //    Logger.d("寫入內容失敗");
            e.printStackTrace();
        }
    }


 private void setEditText(int id, String s) {
        ((EditText) this.findViewById(id)).setText(s);
    }

    private String getEditText(int id) {
        return ((EditText) this.findViewById(id)).getText().toString();
    }
                  

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

       HOOK 介面     注意HOOK 很重要的一塊 HOOK什麼型別的值 透過SharedPreferences儲存的時候也要是相應

的型別 改的函式是Int 必須是Int 字串必須是字串 傳過來的 getString就得是字串 getint就得是Int  要不然就潰 這個下面程式碼少部分型別貌似不對 這個也是初期的老程式碼  哎懶得找了 大家對付看吧 主要是思路
            

 public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

 readData(lpparam);

}

 private void readData(XC_LoadPackage.LoadPackageParam lpparam) throws IllegalAccessException {

      final XSharedPreferences pre = new XSharedPreferences(this.getClass()
                        .getPackage().getName(), "prefs");
        HookMethod(TelephonyManager.class, "getDeviceId",pre.getString("imei",null));
        HookMethod(TelephonyManager.class, "getDeviceSoftwareVersion", pre.getString("deviceversion",null));
        HookMethod(TelephonyManager.class,"getPhoneType",pre.getInt("phonetype",6));
        HookMethod(TelephonyManager.class,"getSimState",pre.getInt("simstate",6));
        HookMethod(Display.class,"getWidth",pre.getInt("width",6));
        HookMethod(Display.class,"getHeight",pre.getInt("height",6));
       // HookMethod(DisplayMetrics.class,"getDisplayMetrics",pre.getInt("dpi",6));
        HookMethod(TelephonyManager.class,"getSubscriberId",pre.getString("imsi",null));
        HookMethod(TelephonyManager.class, "getLine1Number",pre.getString("number",null));
        HookMethod(TelephonyManager.class, "getSimSerialNumber",pre.getString("simserial",null));
        HookMethod(TelephonyManager.class, "getSimOperator", pre.getString("simoperator",null));
        HookMethod(TelephonyManager.class, "getSimOperatorName", pre.getString("simoperatorname",null));
        HookMethod(TelephonyManager.class, "getSimCountryIso", pre.getString("simcountryiso",null));
        HookMethod(TelephonyManager.class, "getNetworkCountryIso", pre.getString("netcountryiso",null));
        HookMethod(TelephonyManager.class, "getNetworkOperator", pre.getString("netoperator",null));
        HookMethod(TelephonyManager.class, "getNetworkOperatorName", pre.getString("netoperatorname",null));
        HookMethod(android.os.Build.class, "getRadioVersion", pre.getString("radiovis",null));
        HookMethod(WifiInfo.class, "getMacAddress",pre.getString("wifimac",null));
        HookMethod(BluetoothAdapter.class, "getAddress", pre.getString("bluemac",null));
        HookMethod(BluetoothAdapter.class,"getName",pre.getString("bluname",null));
        XposedHelpers.findField(android.os.Build.class, "SERIAL").set(null, pre.getString("serial",null));
        XposedHelpers.findField(android.os.Build.class, "BRAND").set(null, pre.getString("brand",null));
        XposedHelpers.findField(android.os.Build.class, "TAGS").set(null,  pre.getString("tags",null));
        XposedHelpers.findField(android.os.Build.class, "DEVICE").set(null,  pre.getString("device",null));
        XposedHelpers.findField(android.os.Build.class, "FINGERPRINT").set(null,  pre.getString("fingerprint",null));
        XposedHelpers.findField(android.os.Build.class, "BOOTLOADER").set(null,  pre.getString("bootloader",null));
        XposedHelpers.findField(Build.VERSION.class, "RELEASE").set(null,  pre.getString("release",null));
        XposedHelpers.findField(Build.VERSION.class, "SDK").set(null,  pre.getString("sdk",null));
        XposedHelpers.findField(Build.VERSION.class, "CODENAME").set(null,  pre.getString("codename",null));
        XposedHelpers.findField(Build.VERSION.class, "INCREMENTAL").set(null,  pre.getString("incremental",null));
        XposedHelpers.findField(android.os.Build.class, "CPU_ABI").set(null,  pre.getString("cpuabi",null));
        XposedHelpers.findField(android.os.Build.class, "CPU_ABI2").set(null,  pre.getString("cpuabi2",null));
        XposedHelpers.findField(android.os.Build.class, "BOARD").set(null, pre.getString("board",null));
        XposedHelpers.findField(android.os.Build.class, "MODEL").set(null,  pre.getString("model",null));
        XposedHelpers.findField(android.os.Build.class, "PRODUCT").set(null, pre.getString("product",null));
        XposedHelpers.findField(android.os.Build.class, "TYPE").set(null,  pre.getString("type",null));
        XposedHelpers.findField(android.os.Build.class, "USER").set(null,  pre.getString("user",null));
        XposedHelpers.findField(android.os.Build.class, "DISPLAY").set(null, pre.getString("disply",null));
        XposedHelpers.findField(android.os.Build.class, "HARDWARE").set(null, pre.getString("hardware",null));
        XposedHelpers.findField(android.os.Build.class, "HOST").set(null,  pre.getString("host",null));
        XposedHelpers.findField(android.os.Build.class, "MANUFACTURER").set(null,  pre.getString("changshang",null));
        XposedHelpers.findField(android.os.Build.class,"TIME").set(null,pre.getInt("time",7));

                      }    


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

     GPU    相關HOOK 方法  這個網上目前沒有 只有我這一份程式碼  

               mySP.setSharedPref("GLRenderer", "Adreno (TM) 111"); // GPU
                mySP.setSharedPref("GLVendor", "UFU");// GPU廠商     




try {
            XposedHelpers.findAndHookMethod("com.google.android.gles_jni.GLImpl", loadPkgParam.classLoader, "glGetString", Integer.TYPE, new XC_MethodHook() {

                @Override
                protected void beforeHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    //super.beforeHookedMethod(param);
                    if (param.args[0] != null) {
                        if (param.args[0].equals(Integer.valueOf(7936))) {
                            param.setResult(SharedPref.getXValue("GLVendor"));
                        }
                        if (param.args[0].equals(Integer.valueOf(7937))) {
                            param.setResult(SharedPref.getXValue("GLRenderer"));
                        }
                    }
                }
                
            });
        } catch (Exception e) {
            XposedBridge.log("Fake GLVendor|GLRenderer ERROR: " + e.getMessage());
        }*/


---------------------------------------------------------------------------------------------------------------------------------------------

單獨列出來的都是 不太好HOOK 的  其實 這種寫法 不太適合新手閱讀  但沒辦法了


//  螢幕相關函式  解析度啊  xdpi ydpi  等等

    try {
            XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getMetrics", DisplayMetrics.class, new XC_MethodHook(XCallback.PRIORITY_LOWEST) {

                @Override
                protected void afterHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    super.afterHookedMethod(param);
                    final int dpi = tryParseInt(SharedPref.getXValue("DPI"));
                    DisplayMetrics metrics = (DisplayMetrics) param.args[0];
                    metrics.densityDpi = dpi;
                
                }
                
            });
        } catch (Exception e) {
            XposedBridge.log("Fake DPI ERROR: " + e.getMessage());
        }
        
        try {
            XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getRealMetrics", DisplayMetrics.class, new XC_MethodHook(XCallback.PRIORITY_LOWEST) {

                @Override
                protected void afterHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    super.afterHookedMethod(param);
                    final int dpi = tryParseInt(SharedPref.getXValue("DPI"));
                    DisplayMetrics metrics = (DisplayMetrics) param.args[0];
                    metrics.densityDpi = dpi;
                
                }
                
            });
        } catch (Exception e) {
        
        }
        

        try {
            XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getMetrics", DisplayMetrics.class, new XC_MethodHook() {

                @Override
                protected void afterHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    super.afterHookedMethod(param);
                    final float sdensity = tryParsefloat(SharedPref.getXValue("density"));
                    DisplayMetrics metrics = (DisplayMetrics) param.args[0];
                    metrics.density = sdensity;
            
                }
                
            });
        } catch (Exception e) {
        
        }
        
    
        try {
            XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getMetrics", DisplayMetrics.class, new XC_MethodHook() {

                @Override
                protected void afterHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    super.afterHookedMethod(param);
                    final float sxdpi = tryParsefloat(SharedPref.getXValue("xdpi"));
                    DisplayMetrics metrics = (DisplayMetrics) param.args[0];
                    metrics.xdpi = sxdpi;
            
                }
                
            });
        } catch (Exception e) {
            XposedBridge.log("Fake Real DPI ERROR: " + e.getMessage());
        }
        
            
        try {
            XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getMetrics", DisplayMetrics.class, new XC_MethodHook() {

                @Override
                protected void afterHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    super.afterHookedMethod(param);
                    final float sydpi = tryParsefloat(SharedPref.getXValue("ydpi"));
                    DisplayMetrics metrics = (DisplayMetrics) param.args[0];
                    metrics.ydpi = sydpi;
            
                }
                
            });
        } catch (Exception e) {
    
        }
        
       
        try {
            XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getMetrics", DisplayMetrics.class, new XC_MethodHook() {

                @Override
                protected void afterHookedMethod(MethodHookParam param)
                        throws Throwable {
                    // TODO Auto-generated method stub
                    super.afterHookedMethod(param);
                  final     float scdensity = tryParsefloat(SharedPref.getXValue("scaledDensity"));
                    DisplayMetrics metrics = (DisplayMetrics) param.args[0];
                    metrics.scaledDensity = scdensity;
            
                }
                
            });
        
            
        } catch (Exception e) {
    
        }
        
       
    private static int tryParseInt(String s) {
        try {
            return Integer.parseInt(s);
        } catch (NumberFormatException e) {
            return 320;
        }
    }
    
    private static float tryParsefloat(String s) {
        try {
            return Float.parseFloat(s);
        } catch (NumberFormatException e) {
            return (float) 480.0;
        }
    }

--------------------------------------------------------------------------------------------------------------------------------------------

//   get  引數HOOK  需要反射獲取下路徑


    Class<?> classSysProp = Class
                    .forName("android.os.SystemProperties");
            XposedHelpers.findAndHookMethod(classSysProp, "get", String.class,
                    new XC_MethodHook() {

                        @Override
                        protected void afterHookedMethod(MethodHookParam param)
                                throws Throwable {
                            // TODO Auto-generated method stub
                            super.afterHookedMethod(param);                    
                            String serialno = (String) param.args[0];    
                        
                            if (serialno.equals("gsm.version.baseband")
                                    || serialno.equals("no message")
                                ) {
                                param.setResult(SharedPref.getXValue("getBaseband"));
                            }        
                        }

                    });
            
            XposedHelpers.findAndHookMethod(classSysProp, "get", String.class,
                    String.class, new XC_MethodHook() {

                        @Override
                        protected void afterHookedMethod(MethodHookParam param)
                                throws Throwable {
                            // TODO Auto-generated method stub
                            super.afterHookedMethod(param);

                            String serialno = (String) param.args[0];
                            if (serialno.equals("gsm.version.baseband")
                                    || serialno.equals("no message")
                        ) {
                                param.setResult(SharedPref.getXValue("getBaseband"));
                            }
                        }

                    });        



---------------------------------------------------------------------------------------------------------------------

基本上比較難HOOK的函式 我都列出來了  不太適合新手觀看  寫的比較亂  好多種版本混合的程式碼

但核心HOOK 都是對的 除了傳值不太一樣 



相關文章