Defeating control flow flattening

From meltedinhex/analyst-ai-pack · View interactive version

Defeating control flow flattening is an AI agent skill from the GitHub repository meltedinhex/analyst-ai-pack. Defeats control-flow-flattening obfuscation by identifying the dispatcher/state- variable structure and reconstructing the original control flow so the logic becomes readable. Activates for requests to defeat control-flow flattening, deobfuscate an OLLVM-flattened function, or recover original contr

How to use this skill

Skill file

Defeating Control-Flow Flattening

When to Use

switch cases) and you need to recover the original control flow.

Do not use this on non-flattened code — confirm the dispatcher/state-variable pattern first.

This skill analyzes disassembly/CFG data statically and executes nothing.

Prerequisites

JSON).

Workflow

Step 1: Detect the flattening structure

python scripts/analyst.py detect cfg.json

Identifies a dispatcher block (high in-degree, switch/compare on a state variable) and the relay/

case blocks that all branch back to it.

Step 2: Recover state transitions

Track the constant assigned to the state variable in each case to determine the successor block,

rebuilding the true edges.

Step 3: Reconstruct the original CFG

Emit the deflattened successor mapping (case → next case) for re-annotation in the disassembler.

Step 4: Verify

Confirm the recovered flow has a single entry, sane successors, and no orphan blocks.

Validation

Pitfalls

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.