美文网首页
遍历hook Dex中的类

遍历hook Dex中的类

作者: whhccc | 来源:发表于2018-05-18 22:07 被阅读0次
    1. 创建DexFile
    DexFile dexFile = new DexFile("/data/user/0/com.test/.cache/classes.jar")
    
    1. 遍历拿出所有类名
    Enumeration<String> classNames = dexFile.entries();
    while (classNames.hasMoreElements()) {
        final String className = classNames.nextElement();
        log("hook的类:" + className);
    }
    
    1. 找到类对象,进行hook
    Class<?> clazz = XposedHelpers.findClass(className, loadPackageParam.classLoader);
    

    hook构造函数

    XposedBridge.hookAllConstructors(clazz, new XC_MethodHook() {});
    

    hook方法

    XposedBridge.hookMethod(method, new XC_MethodHook() {});
    
    1. 打印hook方法中的日志
    try {
        Object[] args = param.args;
        if (args != null) {
            Method method = (Method) param.method;
            Log.e(TAG, "方法参数个数:" + args.length + " \n方法路径:" + method.toGenericString());
            int i = 0;
            StringBuilder sb = new StringBuilder();
            for (Object obj : args) {
                i++;
                String value;
                if (obj == null) {
                    value = "is null";
                } else if (obj instanceof Context) {
                    value = ((Context) obj).getClass().getName();
                } else if (obj instanceof Byte[]) {
                    value = new String((byte[]) obj,
                            "utf-8") + " \nbyte:" + Arrays
                            .toString((byte[]) obj);
                } else if (obj instanceof Integer || obj instanceof Long || obj instanceof Boolean || obj instanceof String
                        || obj instanceof Double || obj instanceof Byte || obj instanceof Short || obj instanceof Character
                        || obj instanceof Float) {
                    value = String.valueOf(obj);
                } else {
                    value = obj.getClass().getName();
                }
                sb.append(" 参数").append(i).append(":").append(value).append("\n");
            }
            Log.e(TAG, "调用前:" + sb.toString());
        }
    } catch (Exception e) {
    }
    

    相关文章

      网友评论

          本文标题:遍历hook Dex中的类

          本文链接:https://www.haomeiwen.com/subject/cqpndftx.html