问题:
我想在android.os.Build中修改一些静态字段,例如android.os.Build.BOARD,android.os.Build.DEVICE,android.os.Build.DISPLAY。
有3种私有静态方法( private static String getString(String property), private static String [] getStringList(String property,String separator), private static long getLong(String property) )在Build.java中。
然后我尝试在android.os.Build中挂钩静态方法'getString(String s)。
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
XposedBridge.log(loadPackageParam.packageName + " -> load ");
Class build = XposedHelpers.findClass(Build.class.getName(), loadPackageParam.classLoader);
XposedHelpers.findAndHookMethod(build, "getString", String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("before ->" + param.args[0]);
super.beforeHookedMethod(param);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("after ->" + param.args[0]);
super.afterHookedMethod(param);
}
});}
当我调用android.os.Build.Model时,我尝试在before / after方法中打印第一个输入参数。但我错了,它没有被触发。
如何挂钩此私有静态方法 在android.os.Build.java中
private static String getString(String property) {
return SystemProperties.get(property, UNKNOWN);}
答案 0 :(得分:0)
public void initZygote(StartupParam startupParam) throws Throwable {
Class clazz = XposedHelpers.findClass(android.os.Build.class.getName(), null);
Method m = XposedHelpers.findMethodExact(clazz, "getString", String.class);
m.setAccessible(true);
XposedBridge.hookMethod(m, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
log("call -> " + (String) param.args[0]);
super.beforeHookedMethod(param);
}
});
String id = (String) m.invoke(null, "ro.build.id");
log("step 1 try invoke->" + id);
log("step 2 Call Build.ID ->" + Build.ID);
}
步骤1可以提升beforeHookedMethod,但步骤2不能。
答案 1 :(得分:-1)