skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.99k stars 4.9k forks source link

Code restructure failed on small program #2274

Closed ambergorzynski closed 2 months ago

ambergorzynski commented 2 months ago

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:

example.zip

Jadx version

1.5.0

skylot commented 2 months ago

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" :rofl: Compilable and meaningful cases are preferred :slightly_smiling_face:

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

ambergorzynski commented 2 months ago

Thanks! Understood on the compilable and meaningful case preference :grin:

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