TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pw4k/ironbrew-2/llms.txt
Use this file to discover all available pages before exploring further.
CFContext class orchestrates control flow obfuscation transformations on Lua bytecode chunks.
Overview
CFContext applies various control flow obfuscation techniques to chunks marked with special global markers (IB_MAX_CFLOW_START and IB_MAX_CFLOW_END). It coordinates multiple transformation passes to make code flow harder to analyze.
Constructor
The root chunk to process for control flow obfuscation
Properties
The root Lua chunk being processed
Methods
DoChunk
The chunk to transform
- Scans for
IB_MAX_CFLOW_STARTandIB_MAX_CFLOW_ENDmarkers - Extracts instruction ranges between markers
- Applies transformations in sequence:
- Test Spam (adds conditional noise)
- Bounce (adds indirect jumps)
- Test Flip (inverts conditional logic)
- Inserts
NewStackopcode if control flow was applied - Recursively processes nested function chunks
DoChunks
Control Flow Markers
To selectively apply control flow obfuscation to specific code sections, use global markers in your Lua source:These markers are removed during obfuscation and replaced with
Move instructions (effectively NOPs).Transformation Types
The following control flow transformations are applied in sequence:| Transformation | Purpose | Source |
|---|---|---|
| Test Spam | Adds bogus conditional tests | Control Flow/Types/TestSpam.cs |
| Bounce | Inserts indirect jumps | Control Flow/Types/Bounce.cs |
| Test Flip | Inverts conditional logic | Control Flow/Types/TestFlip.cs |
| Inlining | Flattens function calls | Control Flow/Types/Inlining.cs |
Usage Example
Integration with IB2.Obfuscate
CFContext is automatically invoked when ControlFlow is enabled in ObfuscationSettings:
How It Works
1. Marker Detection
TheDoChunk method scans for special global function calls:
2. Transformation Application
For each marked section, transformations are applied sequentially:3. Stack Initialization
If any control flow was applied, aNewStack instruction is inserted at the beginning:
Performance Impact
Control flow obfuscation adds significant overhead:- Instruction count: Increases by 50-200% depending on transformations
- Execution time: 2-5x slower due to indirect jumps and extra conditionals
- Code size: Larger due to additional instructions
- Apply selectively using markers
- Disable for performance-critical hot paths
- Test obfuscated code thoroughly
Related APIs
- ObfuscationSettings - Enable/disable control flow obfuscation
- Chunk - The bytecode structure being transformed
- Instruction - Individual instructions being manipulated
- Control Flow Concepts - Detailed explanation of techniques
Source Reference
Source:IronBrew2/Obfuscator/Control Flow/CFContext.cs:12