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

Code restructure failed on small program #2274

Closed
ambergorzynski opened this issue Sep 12, 2024 · 2 comments
Closed

Code restructure failed on small program #2274

ambergorzynski opened this issue Sep 12, 2024 · 2 comments
Labels
bug Core Issues in jadx-core module

Comments

@ambergorzynski
Copy link

Issue details

I am using jadx to decompile class files that were originally written in textual bytecode using Jasmin. I am aware that this is an atypical use case and so may be out of scope for jadx! The original method is relatively simple to restructure by hand so I am opening an issue in case it is of interest:

.method public testCase([I[I)V
    .limit stack 5
    .limit locals 6

block_0:
    iconst_0
    istore_3

    sipush 0

    ifeq block_2
    goto block_1
            
block_1: 
    sipush 1

    ifeq block_1
    goto block_2
            
block_2: 
    iinc 3 1
    return
        
.end method

However jadx fails to decompile and warns that code restructuring fails:

package defpackage;

/* compiled from: program.j */
/* loaded from: TestCase.class */
public class TestCase {
    /* JADX WARN: Code restructure failed: missing block: B:2:0x0005, code lost:
    
        if (0 != 0) goto L5;
     */
    /* JADX WARN: Code restructure failed: missing block: B:3:0x0014, code lost:
    
        r9 = 0 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:4:0x001a, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:7:0x000e, code lost:
    
        if (1 == 0) goto L11;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void testCase(int[] r7, int[] r8) {
        /*
            r6 = this;
            r0 = 0
            r9 = r0
            r0 = 0
            if (r0 == 0) goto L14
            goto Lb
        Lb:
            r0 = 1
            if (r0 == 0) goto Lb
            goto L14
        L14:
            int r9 = r9 + 1
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.TestCase.testCase(int[], int[]):void");
    }
}

Relevant log output or stacktrace

No response

Provide sample and class/method full name

I attach a .zip file with the following:

  • program.j which is the original bytecode progam
  • TestCase.class which is the class file associated with program.j
  • TestCase.java which is the output of applying JadX to TestCase.class

example.zip

Jadx version

1.5.0

@skylot
Copy link
Owner

skylot commented Sep 16, 2024

Fixed.
@ambergorzynski thanks for test case, although it is way too synthetic, now jadx outputs

    public void testCase(int[] iArr, int[] iArr2) {
        if (0 != 0) {
            while (1 == 0) {
            }
        }
        int i = 0 + 1;
    }

and it still not compilable because of "unreachable statement" 🤣
Compilable and meaningful cases are preferred 🙂

BTW, if you're still using Jasmin, it will be nice if you also look at my raung project, any feedback is welcome.

@skylot skylot closed this as completed Sep 16, 2024
@ambergorzynski
Copy link
Author

Thanks! Understood on the compilable and meaningful case preference 😁

And thanks for pointing me to raung, looks very cool! I will check it out.

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
Projects
None yet
Development

No branches or pull requests

2 participants