使用Proguard进行混淆与vs. java.lang.reflect.Proxy [英] obfuscation with proguard vs. java.lang.reflect.Proxy

查看:74
本文介绍了使用Proguard进行混淆与vs. java.lang.reflect.Proxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于调试的原因,我使用java.lang.reflect.Proxy东西来实现所有可能的接口的通用方法……但这似乎很难使其与proguard一起使用.有什么建议吗?

I use for debugging reasons the java.lang.reflect.Proxy stuff to have a generic way to implement all possible interfaces... but this seems to be difficult to get it working with proguard. Any suggestions?

THX -马可

public class DebugLogListenerFactory {

public static IAirplaneListenerAll createStreamHandle(ICAirplane plane) {
    DebugLogListenerHandler handler = new DebugLogListenerHandler(plane);
    IAirplaneListenerAll proxy = (IAirplaneListenerAll) Proxy
            .newProxyInstance(IAirplaneListenerAll.class.getClassLoader(),
                    new Class[] { IAirplaneListenerAll.class }, handler);

    plane.addListener(proxy);
    return proxy;
}

private static class DebugLogListenerHandler implements InvocationHandler {


    private final Level levDef = Level.FINE;


    public DebugLogListenerHandler() {
    }

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        System.out.println("invoked" + method);
        String methodName = method.getName();
        String msg = methodName + ": ";
        if (args != null) {
            boolean first = true;
            for (Object o : args) {
                if (first) {
                    first = false;
                } else {
                    msg += " ,";
                }
                msg += o.toString();
            }
        }
        CDebug.getLog().log(levDef, msg);
        return null;
    }
}

}

推荐答案

最简单的解决方案可能是避免缩小/优化/混淆接口及其方法:

The easiest solution is probably to avoid shrinking/optimizing/obfuscating the interface and its methods:

-keep interface some.package.IAirplaneListenerAll {
  <methods>;
}

您可能允许缩小:

-keep,allowshrinking interface some.package.IAirplaneListenerAll {
  <methods>;
}

如果InvocationHandler可以处理混淆的方法名称,则还可以允许混淆:

If the InvocationHandler can deal with obfuscated method names, you might also allow obfuscation:

-keep,allowshrinking,allowobfuscation interface some.package.IAirplaneListenerAll {
  <methods>;
}

这篇关于使用Proguard进行混淆与vs. java.lang.reflect.Proxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆