需求描述:008神器生成的数据中,手机型号数据老旧并且android版本低于4.4无法满足现有需求,需要更新手机型号数据并且扩展到更高的android版本。
使用androidKiller反编译008.apk,点击打开链接
xposed框架的作者是rovo89,Xposed框架的原理是修改系统文件,替换了/system/bin/app_process可执行文件,在启动Zygote时加载额外的jar文件(/data/data/de.robv.android.xposed.installer/bin/XposedBridge.jar),并执行一些初始化操作(执行XposedBridge的main方法)。然后我们就可以在这个Zygote上下文中进行某些hook操作。
provided files('libs/XposedBridgeApi-54.jar')
这里使用provided而不用compile是因为xposed框架中已经包含该jar包,所以只建立编译时依赖。
android:name="xposedmodule" android:value="true" /> android:name="xposedminversion" android:value="54" /> android:name="xposeddescription" android:value="测试Xposed" />
public class XposedUtil implements IXposedHookLoadPackage { @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam mLoadPackageParam) throws Throwable { } }
创建完我们hook类之后,我们需要将该类加载到XposedInstaller中,也就是我们必须声明该类的位置,需要在xposed_init中声明:创建assets文件夹,然后在里面新建一个文件,文件名为xposed_init,没有后缀,然后在里面写入我们刚刚创建的类的完整类名
com.dovar.fakermobile.XposedUtil
XposedHelpers.findAndHookMethod()可在目标方法执行之前或之后进行修改,一般用于执行前修改传参或执行后修改返回值或者对数据进行抓包。
XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getSize", Point.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { super.beforeHookedMethod(param); } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); Point mPoint = (Point) param.args[0]; mPoint.y = SharedPref.getintXValue("height"); mPoint.x = SharedPref.getintXValue("width"); XposedBridge.log("getSize"); } });
另外也可通过XposedHelpers.findAndHookMethod()直接对目标方法进行替换,以此影响程序的执行
new XC_MethodReplacement(){ @Override protected Object replaceHookedMethod(MethodHookParam mMethodHookParam) throws Throwable { return null; } };针对多种获取分辨率的方式进行hook:
/** * Display.getWidth() Display.getHeight() * 针对这种方式的获取分辨率 */ XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getWidth", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); param.setResult(SharedPref.getintXValue("width")); XposedBridge.log("getWidth"); } });
/** * Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);method.invoke(display, dm);dpi = dm.heightPixels; * 针对这种方式的获取分辨率 */ XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getRealMetrics", DisplayMetrics.class, new XC_MethodHook(XCallback.PRIORITY_LOWEST) { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); DisplayMetrics metrics = (DisplayMetrics) param.args[0]; metrics.widthPixels = SharedPref.getintXValue("width"); metrics.heightPixels = SharedPref.getintXValue("height"); XposedBridge.log("getRealMetrics_dpi"); } });
/** * Display display = wm.getDefaultDisplay();Point size = new Point();display.getSize(size); * 针对这种方式的获取分辨率 */ XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getSize", Point.class, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); Point mPoint = (Point) param.args[0]; mPoint.y = SharedPref.getintXValue("height"); mPoint.x = SharedPref.getintXValue("width"); XposedBridge.log("getSize"); } });
/** * DisplayMetrics dm = new DisplayMetrics(); display.getMetrics(dm); height = dm.heightPixels; * 针对这种方式的获取分辨率 */ XposedHelpers.findAndHookMethod("android.view.Display", loadPkgParam.classLoader, "getMetrics", DisplayMetrics.class, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); DisplayMetrics metrics = (DisplayMetrics) param.args[0]; metrics.widthPixels = SharedPref.getintXValue("width"); metrics.heightPixels = SharedPref.getintXValue("height"); XposedBridge.log("getMetrics"); } });
修改buildProp文件中的系统值
public void BuildProp(XC_LoadPackage.LoadPackageParam loadPkgParam) { //systemProperties hook XposedHelpers.findAndHookMethod("android.os.SystemProperties", loadPkgParam.classLoader, "get", String.class, String.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { super.beforeHookedMethod(param); String methodName = param.method.getName(); if (methodName.startsWith("get")) { XposedHelpers.findField(Build.class, "BOARD").set(null, SharedPref.getXValue("board")); XposedHelpers.setStaticObjectField(Build.class, "BRAND", SharedPref.getXValue("brand")); XposedHelpers.findField(Build.class, "CPU_ABI").set(null, SharedPref.getXValue("ABI")); XposedHelpers.findField(Build.class, "CPU_ABI2").set(null, SharedPref.getXValue("ABI2")); XposedHelpers.findField(Build.class, "DEVICE").set(null, SharedPref.getXValue("device")); XposedHelpers.findField(Build.class, "DISPLAY").set(null, SharedPref.getXValue("display")); XposedHelpers.findField(Build.class, "FINGERPRINT").set(null, SharedPref.getXValue("fingerprint")); XposedHelpers.findField(Build.class, "HARDWARE").set(null, SharedPref.getXValue("NAME")); XposedHelpers.findField(Build.class, "ID").set(null, SharedPref.getXValue("ID")); XposedHelpers.findField(Build.class, "MANUFACTURER").set(null, SharedPref.getXValue("Manufacture")); XposedHelpers.setStaticObjectField(Build.class, "MODEL", SharedPref.getXValue("model")); XposedHelpers.findField(Build.class, "PRODUCT").set(null, SharedPref.getXValue("product")); XposedHelpers.findField(Build.class, "BOOTLOADER").set(null, SharedPref.getXValue("booltloader")); //主板引导程序 XposedHelpers.findField(Build.class, "HOST").set(null, SharedPref.getXValue("host")); // 设备主机地址 XposedHelpers.findField(Build.class, "TAGS").set(null, SharedPref.getXValue("build_tags")); //描述build的标签 XposedHelpers.findField(Build.class, "TYPE").set(null, SharedPref.getXValue("shenbei_type")); //设备版本类型 XposedHelpers.findField(Build.VERSION.class, "INCREMENTAL").set(null, SharedPref.getXValue("incrementalincremental")); //源码控制版本号 XposedHelpers.findField(android.os.Build.VERSION.class, "RELEASE").set(null, SharedPref.getXValue("AndroidVer")); XposedHelpers.findField(android.os.Build.VERSION.class, "SDK").set(null, SharedPref.getXValue("API")); XposedHelpers.findField(android.os.Build.VERSION.class, "CODENAME").set(null, "REL"); //写死就行 这个值为固定 } } });