【问题标题】:obfuscation with proguard vs. java.lang.reflect.Proxyproguard 与 java.lang.reflect.Proxy 的混淆
【发布时间】:2011-04-26 22:14:18
【问题描述】:

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

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;
    }
}

}

【问题讨论】:

    标签: proxy proguard


    【解决方案1】:

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

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

    您可以允许缩小:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 2013-09-30
      • 1970-01-01
      • 2019-03-19
      相关资源
      最近更新 更多