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

[core] Default switch case lost in endless loop #2351

Closed
eybisi opened this issue Nov 20, 2024 · 3 comments
Closed

[core] Default switch case lost in endless loop #2351

eybisi opened this issue Nov 20, 2024 · 3 comments
Assignees
Labels
bug Core Issues in jadx-core module switch

Comments

@eybisi
Copy link
Contributor

eybisi commented Nov 20, 2024

Issue details

if switch is inside endless while loop, (while(true)) default switch branch is always discarded and lost. Following java code:

    public int jadxEndlessSwitch(int r){
        int r0;
        while(true){
            switch(r){
                case 42:
                    r0 = 32;
                    break;
                case 52:
                    r0 = 42;
                    break;
                default:
                    System.out.println("Default switch case");
                    return 1;
            }
            r = r0;
        }
    }

results in:

    /* JADX WARN: Code restructure failed: missing block: B:8:0x0004, code lost:
   
       java.lang.System.out.println("Default switch case");
    */
   /* JADX WARN: Code restructure failed: missing block: B:9:0x000c, code lost:
   
       return 1;
    */
   /*
       Code decompiled incorrectly, please refer to instructions dump.
   */
   public int jadxEndlessSwitch(int r) {
       int r0;
       while (true) {
           switch (r) {
               case 42:
                   r0 = 32;
                   break;
               case 52:
                   r0 = 42;
                   break;
           }
           r = r0;
       }
   }

I've attached sample app.

Relevant log output or stacktrace

WARN : Code restructure failed: missing block: B:8:0x0004, code lost:

    java.lang.System.out.println("Default switch case");
 in method: org.abc.obfusactiontests.MainActivity.jadxEndlessSwitch(int):int, file: classes3.dex
WARN : Code restructure failed: missing block: B:9:0x000c, code lost:

    return 1;
 in method: org.abc.obfusactiontests.MainActivity.jadxEndlessSwitch(int):int, file: classes3.dex

Provide sample and class/method full name

app-debug.zip

class : org.abc.obfusactiontests.MainActivity
method : jadxEndlessSwitch

Jadx version

dev

@eybisi eybisi added bug Core Issues in jadx-core module labels Nov 20, 2024
@skylot
Copy link
Owner

skylot commented Nov 20, 2024

@eybisi thanks for test case!
Actually, right now I am working on a new approach for break/continue handling (related to #2339), so it affects loops and switches. And I will add your test case into that change, it may take some time though 🙂

@skylot skylot self-assigned this Nov 20, 2024
@skylot skylot added the switch label Nov 20, 2024
@MrIkso
Copy link
Contributor

MrIkso commented Nov 21, 2024

vineflower or fernflower handles this case, maybe it's worth looking at how they perform code generation for such cases...

@skylot
Copy link
Owner

skylot commented Nov 24, 2024

Fixed.
Cause of the issue was incorrect checks for empty default case, hope fix will cover all cases.
Also, rework mentioned above, not going well and will be postponed, so I made a fix just for this case.

@skylot skylot closed this as completed Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module switch
Projects
None yet
Development

No branches or pull requests

3 participants