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] A NullPointerException occurs in decompiling multi-entry loops #1611

Closed
AIRTEspresso opened this issue Aug 10, 2022 · 3 comments
Closed
Labels
bug Core Issues in jadx-core module

Comments

@AIRTEspresso
Copy link

Describe error
Hi, I am doing some testing on Jadx, as I like this tool and use it a lot. I hope Jadx can give better decompilation results. Here is a failure I find in decompiling multi-entry loops (maybe, I am not sure):
Source code

    void mainTest(String[]strArr1){
        int i21 = 11 , i22 , i23 = 241 , i24 , i28;
        double d2;
        vMeth(i21);
        for(d2 = 18; d2 < 352; ++ d2){
            i23 = 1;
            while(++ i23 < 75){}
        }
        i22 =(int)instanceCount;
        for(i24 = 1; i24 < 243; i24 ++)
            switch(i24 % 9 + 18){
            case 11 : for(i28 = 1; ; )i28 ^= i21;
            case 21 : i21 /= 61145;
                break;
            case 22 : i22 += i23;
        }
        System.out.println("i21 d2 i22 = " + i21 + "," + Double.doubleToLongBits(d2)+ "," + i22);
    }

and here is the failure warning I got from the decompiled code:

    /*  JADX ERROR: NullPointerException in pass: RegionMakerVisitor
        java.lang.NullPointerException
        	at java.base/java.util.BitSet.and(BitSet.java:917)
        	at jadx.core.utils.BlockUtils.getPathCross(BlockUtils.java:735)
        	at jadx.core.utils.BlockUtils.getPathCross(BlockUtils.java:811)
        	at jadx.core.dex.visitors.regions.IfMakerHelper.restructureIf(IfMakerHelper.java:88)
        	at jadx.core.dex.visitors.regions.RegionMaker.processIf(RegionMaker.java:706)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:155)
        	at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:94)
        	at jadx.core.dex.visitors.regions.RegionMaker.processLoop(RegionMaker.java:262)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:138)
        	at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:94)
        	at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:52)
        */
    /* JADX WARN: Failed to detect multi-entry loops
    java.lang.ArrayIndexOutOfBoundsException: Index 24 out of bounds for length 23
    	at jadx.core.dex.visitors.blocks.FixMultiEntryLoops.colorDFS(FixMultiEntryLoops.java:90)
    	at jadx.core.dex.visitors.blocks.FixMultiEntryLoops.colorDFS(FixMultiEntryLoops.java:92)
     */
    void mainTest(java.lang.String[] r9) {
        /*
            r8 = this;
            r9 = 11
            r8.vMeth(r9)
            r0 = 241(0xf1, float:3.38E-43)
            r1 = 4625759767262920704(0x4032000000000000, double:18.0)
        La:
            r3 = 4644900065679245312(0x4076000000000000, double:352.0)
            r5 = 1
            int r6 = (r1 > r3 ? 1 : (r1 == r3 ? 0 : -1))
            if (r6 >= 0) goto L1c
            r0 = 1
        L12:
            int r0 = r0 + r5
            r3 = 75
            if (r0 >= r3) goto L18
            goto L12
        L18:
            r3 = 4607182418800017408(0x3ff0000000000000, double:1.0)
            double r1 = r1 + r3
            goto La
        L1c:
            long r3 = r8.instanceCount
            int r4 = (int) r3
            r3 = 11
        L21:
            r6 = 243(0xf3, float:3.4E-43)
            if (r5 >= r6) goto L41
            int r6 = r5 % 9
            int r6 = r6 + 18
            if (r6 == r9) goto L3e
            r7 = 21
            if (r6 == r7) goto L36
            r7 = 22
            if (r6 == r7) goto L34
            goto L3b
        L34:
            int r4 = r4 + r0
            goto L3b
        L36:
            r6 = 61145(0xeed9, float:8.5682E-41)
            int r3 = r3 / r6
        L3b:
            int r5 = r5 + 1
            goto L21
        L3e:
        L3f:
            goto L3f
        L41:
            java.io.PrintStream r9 = java.lang.System.out
            long r0 = java.lang.Double.doubleToLongBits(r1)
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            r2.<init>()
            java.lang.String r5 = "i21 d2 i22 = "
            r2.append(r5)
            r2.append(r3)
            java.lang.String r3 = ","
            r2.append(r3)
            r2.append(r0)
            r2.append(r3)
            r2.append(r4)
            java.lang.String r0 = r2.toString()
            r9.println(r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.Test.mainTest(java.lang.String[]):void");
    }

Version:
Jadx : 1.4.1
Java JDK: 11.0.3
Android decompiler: dx8 of 30.0.2 building tool
Input Version: dex files

Would you like to have a look? All the source file, the compilation file and the decompiled files are available at
multientryloopfailure.zip

@skylot
Copy link
Owner

skylot commented Aug 10, 2022

@AIRTEspresso thanks for nice test cases, but can you stop for some time? At least give me a change to fix these issues 🤣

@AIRTEspresso
Copy link
Author

Sure.....Not in a hurry, you can fix these issues when you have enough time. I performed a long-time analysis on these test cases and recent days I eventually finish the analysis and plan to report all of them, it is why there are so many issues.... 😅

skylot added a commit that referenced this issue Aug 10, 2022
@skylot
Copy link
Owner

skylot commented Aug 10, 2022

Fixed. Actually, it is a weird test case because it contains an empty endless loop, so I don't think it can appear in real code.
Also, if possible, please check your cases with the latest unstable build of jadx, some issues can be already be fixed or throw different exception which can be a little confusing.
Anyway, thank you for this report 👍

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