leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
2.03k stars 262 forks source link

TCB decompiled wrongly #166

Open GraxCode opened 4 years ago

GraxCode commented 4 years ago

CFR version

329eadca515e0f7939f40c3f2355c273548740ef

Compiler

Fingers

Description

I again had some fun making really ugly testcases. Output:

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public Object flowTest() {
        MultiJump multiJump;
        try {
            multiJump = this;
        }
        catch (Exception exception) {
            if (exception != null) {
                return null;
            }
            multiJump = null;
        }
        Object.throwsNPE();
        do {
            // Infinite loop
        } while (true);
    }

Expected something like:

    public Object flowTest() {
        while (true) {
            try {
                Object.throwsNPE();
                do {
                    // Infinite loop
                } while (true);
            }
            catch (Exception ex) {
                if (ex != null) {
                    return null;
                }
                continue;
            }
            break;
        }
    }

Object.throwsNPE(); should be in the try catch block. The CFR output would lead to throwing a NPE, while the real code would return null.

Example

MultiJump.class.txt

GraxCode commented 4 years ago

Note: CFR 0.149 Output:

    /*
     * Unable to fully structure code
     * Enabled unnecessary exception pruning
     */
    public Object flowTest() {
        try {
            v0 = this;
lbl3: // 2 sources:
            do {
                Object.throwsNPE();
                do {
                    // Infinite loop
                } while (true);
                break;
            } while (true);
        }
        catch (Exception v1) {
            if (v1 != null) {
                return null;
            }
            v0 = null;
            ** continue;
        }
    }