public class HookInit implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage ( final XC_LoadPackage.LoadPackageParam lpparam ) throws Throwable {
XposedHelpers.findAndHookMethod ( "android.app.ContextImpl", lpparam.classLoader, "checkCallingOrSelfPermission", String.class, new XC_MethodReplacement ( ){
@Override
protected Object replaceHookedMethod ( XC_MethodHook.MethodHookParam p1 ) throws Throwable {
int i=0;
return i;
}
}
);
XposedHelpers.findAndHookMethod ( "android.app.Application", lpparam.classLoader, "attach", Context.class, new XC_MethodHook ( ){
@Override
protected void afterHookedMethod ( MethodHookParam param ) throws Throwable {
Class <?>wmg=XposedHelpers.findClass ( "android.view.WindowManagerGlobal", lpparam.classLoader );
final Object wm=XposedHelpers.callStaticMethod ( wmg, "getWindowManagerService" );
Method setForcedDisplayDensityForUser=XposedHelpers.findMethodBestMatch ( wm.getClass ( ), "setForcedDisplayDensityForUser", int.class, int.class, int.class );
setForcedDisplayDensityForUser.invoke ( wm, 160, Display.DEFAULT_DISPLAY, AndroidAppHelper.currentApplicationInfo ( ).uid );
}
}
);
}
}
目的是想通过 WindowManagerGlobal 获取 WindowManagerService ,然后调用 setForcedDisplayDensityForUser 方法,因为这个方法会用 checkCallingOrSelfPermission 方法检查是否有权限,所以我修改了他的返回值为 0 。
setForcedDisplayDensityForUser 的源码:
@Override
public void setForcedDisplayDensityForUser(int displayId, int density, int userId) {
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Must hold permission " +
android.Manifest.permission.WRITE_SECURE_SETTINGS);
但这样修改后还是抛出异常"Must hold permission…"
大佬们有没有什么建议