在逆向开发时,除了对类方法的反射,还有对资源布局的替换与插入,主要用到:IXposedHookInitPackageResources,IXposedHookZygoteInit
好了,进入主题
① 替换某apk中的资源,如:图片,文字,数值
@Override public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable { if (TARGET_PACKAGE.equals(resparam.packageName)) { resparam.res.setReplacement(0x90c009f, "客户"); } }
②对某apk中的布局进行插入View
@Override public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable { if (TARGET_PACKAGE.equals(resparam.packageName)) { resparam.res.hookLayout(TARGET_PACKAGE, "layout", "dialer_list_call_normal_item", new XC_LayoutInflated() { @Override public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable { RelativeLayout simpleItem = (RelativeLayout) liparam.view; LinearLayout topLineLinear = (LinearLayout) simpleItem.findViewById(0x90e00e6); if (topLineLinear != null) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) topLineLinear.getLayoutParams(); topLineLinear.requestLayout(); ImageView sexImageView = new ImageView(simpleItem.getContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(lp.height, lp.height); params.leftMargin = 10; sexImageView.setLayoutParams(params); sexImageView.setContentDescription("性别"); sexImageView.setId(sexImageResId); topLineLinear.addView(sexImageView, 1, params); } } }); } }
③向某apk插入新图片或者新布局
private static String MODULE_PATH = null; @Override public void initZygote(StartupParam startupParam) throws Throwable { MODULE_PATH = startupParam.modulePath; } @Override public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable { if (TARGET_PACKAGE.equals(resparam.packageName)) { XModuleResources modRes = XModuleResources.createInstance(MODULE_PATH, resparam.res); sexBoyImageResId = resparam.res.addResource(modRes, R.drawable.boy); sexGrilImageResId = resparam.res.addResource(modRes, R.drawable.boy); } }