使用 proguard 与 java.lang.reflect.Proxy 进行混淆

发布于 2024-11-03 05:52:13 字数 1373 浏览 6 评论 0原文

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

谢谢 -马可

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

}

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
-Marco

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-11-10 05:52:13

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

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

您可能允许缩小:

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

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

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

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

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

You might allow shrinking:

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

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

-keep,allowshrinking,allowobfuscation interface some.package.IAirplaneListenerAll {
  <methods>;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文