Gui-Yom / hlbc

Hashlink bytecode disassembler, analyzer, decompiler and assembler.
https://gui-yom.github.io/hlbc/
MIT License
51 stars 7 forks source link

Heavily nested functions do not decompile correctly #5

Open N3rdL0rd opened 1 week ago

N3rdL0rd commented 1 week ago

I was poking around the Dead Cells bytecode with the GUI and noticed that a lot of functions seemed to cut off at a certain depth, even though the opcodes still had more instructions - so I wrote a small test class:

class Nested {
    static function main() {
        var b = 512.0;
        while (b > 5) {
            b /= 2;
            if (b < 10) {
                while (b < 100) {
                    b *= 2;
                    if (b > 50) {
                        break;
                    }
                }
            }
        }
    }
}

Once decompiled, it yields the following output:

class Nested {
    static function main() {
        var b = 512;
        while ([no condition]) {
            b = b / 2;
            while ([no condition]) {
                b = b * 2;
                break;
            }
        }
    }
}

I assume the [no condition] blocks are a separate issue - but the lack of nesting beyond a certain point is far more concerning when it comes to the overall accuracy of the decompilation.