Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I make sure that functions are not overloaded to the same name when they have different return types? #430

Open
koen-lyfo opened this issue Aug 26, 2024 · 1 comment

Comments

@koen-lyfo
Copy link

I'm working on a Javacard applet. I'm using Proguard because I have almost no memory on that card. I also optimize aggressively because of this. Proguard will overload functions, which is fine, but if an overloaded function has a different return type from another function, then the converter (which turns the JAR into something that the card understands) will throw an error.

I want proguard to overload functions, except when they have different return types.

My rules:

-verbose
-allowaccessmodification
-optimizeaggressively
-dontwarn java.lang.Class
-repackageclasses com.example
-optimizationpasses 10
-keepattributes Exceptions
-optimizations !code/simplification/arithmetic,!code/simplification/cast
-useuniqueclassmembernames

-keep public class com.example.MyApplet {
    public static void install(byte[], short, byte);
    public void process(javacard.framework.APDU);
    public void processToolkit(short);
    public void uninstall();
}

Below is an example. I'm concerned with the bottom functions:

public class MyApplet extends Applet implements ToolkitInterface, AppletEvent {
    byte[] timerIds = new byte[3];
    MyApplet() {}

    public void configureToolkit() {
        ToolkitRegistry toolkitRegistry = ToolkitRegistrySystem.getEntry();

       for(byte i = 0; i < (byte) timerIds.length; i++ {
            timerIds[i] = toolkitRegistry.allocateTimer();
        }

        toolkitRegistry.setEvent(EVENT_PROFILE_DOWNLOAD);
    }

    public static void install(byte[] bArray, short bOffset, byte bLength) {
        MyApplet applet = MyApplet();
        applet.register();
        applet.configureToolkit();
    }

    public void process(APDU apdu) {}

    public void processToolkit(short event) {
        switch(event)
            case EVENT_PROFILE_DOWNLOAD:
                for(byte i = 0; i < (byte) timerIds.length; i++ {
                    startTimer(timerIds[i], i);
                }
                break;
            case EVENT_TIMER_EXPIRATION:
                byte timerId = getTimerId();
                startTimer(timerId, (byte) 5);
                break;
            default:
                break;
        }
    }

    public void uninstall() {}

    // If these are not inlined, they will get the same name.
    // But they have different return types
    void startTimer(byte timerId, byte seconds) {
         // impl
    }

    byte getTimerId() {
        // impl
    }
}

Most of the time these types of functions are inlined. But assume that for some reason these functions cannot be inlined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@koen-lyfo and others