From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Technique:Recognizing code obfuscation" |
|---|
| claim | "O-LLVM control-flow flattening (llvm-4.0 branch) turns a function into a loop: an entry block stores a scrambled i32 into the stack variable switchVar, loopEntry loads it and switches on it (default block switchDefault goes to loopEnd), and loopEnd branches back to loopEntry. Each original block with one successor ends by storing the successor's case number and jumping to loopEnd; a conditional branch becomes a select between two case numbers stored the same way; blocks with no successor (return, unreachable) are left unchanged. Case numbers are not 0,1,2... but scramble32(index, per-function key). The pass first lowers switch instructions, and skips a function that has a single basic block or any invoke terminator (C++ exception handling)." |
|---|
| scope | | level | "tool" |
|---|
| applies_to | "Obfuscator-LLVM" |
|---|
| observed_in | |
|---|
|
|---|
| data | | trigger | "-fla or annotation fla" |
|---|
| effect | "blocks become cases of one switch inside loopEntry/loopEnd; conditional branches become select between two case numbers" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "llvm-4.0 branch head; read the pass: switchVar, loopEntry, loopEnd, switchDefault, SelectInst" |
|---|
| repo | "https://github.com/obfuscator-llvm/obfuscator" |
|---|
| commit | "42f732c274e7cf9d7ddf2097bfc181de7587147e" |
|---|
| path | "lib/Transforms/Obfuscation/Flattening.cpp" |
|---|
|
| type | "source" |
|---|
| detail | "Flattening::flatten read whole: LowerSwitch first; returns false if any block ends in InvokeInst or origBB.size() <= 1; case values from cryptoutils->scramble32; successors==0 skipped, ==1 store+branch to loopEnd, ==2 SelectInst." |
|---|
| repo | "https://github.com/obfuscator-llvm/obfuscator" |
|---|
| commit | "42f732c274e7cf9d7ddf2097bfc181de7587147e" |
|---|
| path | "lib/Transforms/Obfuscation/Flattening.cpp" |
|---|
| lines | "60-242" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "O-LLVM flattening shape" |
|---|
| topic | "Technique:Recognizing code obfuscation/Native obfuscation patterns" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-18T13:53:07.688Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T07:36:08.427Z" |
|---|
| result | "confirmed" |
|---|
| method | "Fetched Flattening.cpp at obfuscator-llvm 42f732c274e7 and read the whole flatten() function (lines 55-242): LowerSwitch, return false on any InvokeInst terminator or <=1 block, switchVar alloca, loopEntry/loopEnd/switchDefault, scramble32(index,key) case values, 0 successors skipped, 1 successor store+br loopEnd, 2 successors SelectInst. Nuance: LowerSwitch runs before the skip checks, so a skipped function may already have its switches lowered." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T06:01:30.907Z" |
|---|
| summary | "Not every block stores a case number (return blocks are left alone), functions with invoke terminators or one block are skipped, case values are scrambled constants" |
|---|
| changed | |
|---|
|
|
|---|