Obfuscation with proguard vs. java.lang.reflect.Proxy

I use for debugging reasons that the java.lang.reflect.Proxy material has a common way to implement all possible interfaces ... but it seems hard to get it working with proguard. Any suggestions?

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

}

0
source share
1 answer

The simplest solution is probably to avoid reducing / optimizing / obfuscating the interface and its methods:

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

You can enable compression:

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

If the InvocationHandler can handle obfuscated method names, you can also enable obfuscation:

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

Source: https://habr.com/ru/post/1569956/


All Articles