Docs
/
Basic Obfuscation
/

Control Flow Flattening

Control Flow Flattening

controlFlowFlattening
~1.5x slower

Transforms the code structure to hide the original program flow. Makes manual analysis much harder by converting linear code into a state machine with a switch statement.

// Before
function process() {
    step1();
    step2();
    step3();
}

// After (flattened)
function process() {
    var state = '0|1|2'.split('|'), i = 0;
    while (true) {
        switch (state[i++]) {
            case '0': step1(); continue;
            case '1': step2(); continue;
            case '2': step3(); continue;
        }
        break;
    }
}

Control flow flattening composes well with other basic options and with VM obfuscation — the flattened state machine is further transformed into bytecode when VM is enabled.