0

I want to hook all method of ViewGroup, so write below code:

final Class<?> mViewGroup = XposedHelpers.findClass("android.view.ViewGroup", lpparam.classLoader);
for (final Method method : mViewGroup.getDeclaredMethods()) {
    if (true == Modifier.isAbstract(method.getModifiers())){
        XposedBridge.log("skip abstract:" + method.getName());
        continue;
    }
    XposedBridge.log("----" + method.getName());
    XposedBridge.hookMethod(method, methodHook);
}

final StringBuilder sb = new StringBuilder();
XC_MethodHook methodHook = new XC_MethodHook() {
    @Override
    protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
        dumpParams(param);
    }

    @Override
    protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
        //param.setResult(false);
        XposedBridge.log("after:" + param.getResult());
    }
};

private void dumpParams(XC_MethodHook.MethodHookParam param) {
    sb.setLength(0);
    sb.append(param.method.getName()).append("(");
    for (Object o:param.args) {
        String typnam = "";
        String value = "null";
        if (o != null) {
            typnam = o.getClass().getName();
            value = o.toString();
        }
        sb.append(typnam).append(":").append(value).append(", ");
    }
    XposedBridge.log(sb.toString());
}

But when I run it, hook class sounds fine, but when execute it crashed at android.view.View$AttachInfo:

am_crash: `java.lang.IllegalAccessError,Illegal class access: 'EdHooker45' attempting to access 'android.view.View$AttachInfo' (declaration of 'EdHooker45' appears in /data/user_de/0/.../1129433416.jar),NULL,120]`
lucky1928
  • 8,708
  • 10
  • 43
  • 92
  • Does the error occur when while hooking the methods or when a hooked method is executed. Do you know which of the ViewGroup methods causes this problem? – Robert Nov 09 '19 at 13:14
  • Error happen when execute, the method is AttachInfo from the error log. – lucky1928 Nov 09 '19 at 14:19
  • AttachInfo is a class not a method. There are multiple methods that have a parameter with AttachInfo type. Therefore it is not clear where the error occurs. Furthermore your posted code does not contain the `methodHook` implementation which makes it impossible to guess what command you execute that causes this problem. – Robert Nov 09 '19 at 17:20
  • @Robert Update with methodHook, it only print a log with parameter information input into the method. – lucky1928 Nov 09 '19 at 17:44
  • Have you tried to put the dumpParams code into a `try {} (catch Exception e)` block and log the stacktrace to see which method causes this error? – Robert Nov 10 '19 at 11:23
  • @Robert Do that as suggest but crash still happen. so I guess issue not come from dumpParams function. – lucky1928 Nov 10 '19 at 22:52
  • BTW: Which Android version do you use for testing your code? I remember a new feature in Android 10 that prevents hidden API access. As your XPosed code uses hidden methods and classes you may be affected by this [hidden API protection mechanism](https://stackoverflow.com/questions/55970137). – Robert Nov 11 '19 at 08:35
  • @Robert I am using Android 9.0 (Pie). – lucky1928 Nov 11 '19 at 16:02
  • Sorry I was wrong, this is a Android 9 feature not 10. I really dislike misleading "alphabet versioning scheme of Android". Therefore you may be affected by this "feature". – Robert Nov 11 '19 at 17:57

0 Answers0