控制流平坦化
controlFlowFlattening
~1.5x slower
转换代码结构以隐藏原始的程序流程。通过把线性代码转换为带 switch 语句的状态机,让人工分析变得困难得多。
// 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;
}
}
控制流平坦化能与其他基础选项以及 VM 混淆良好组合 —— 启用 VM 后,平坦化得到的状态机会被进一步转换为字节码。
