# obfuscator-llvm/obfuscator architecture

> Architecture diagram of the GitHub repository obfuscator-llvm/obfuscator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/obfuscator-llvm/obfuscator
- Repository: https://github.com/obfuscator-llvm/obfuscator

## Overview

##### Project Purpose
- This is the Obfuscator‑LLVM project, intended to implement obfuscation passes within the LLVM compilation pipeline. According to the README, the project provides software protection by integrating with LLVM (in this case, LLVM 4.0).
- The emphasis is on compiler-level transformations so that the compiled code is more resilient against reverse engineering.

##### Main Components
a. The Base Compiler Framework:
- LLVM Core: The standard LLVM components such as the Frontend, the IR (Intermediate Representation), the Pass Manager, and the Backend (the code generator).
b. Obfuscation Modules:
- Custom LLVM Passes: These are the individual obfuscation techniques that are inserted into the LLVM pass pipeline. They may include control flow flattening, instruction substitution, bogus control flows, etc.
c. Integration Points:
- Plugin or Patch Infrastructure: How these obfuscation passes integrate with LLVM’s pass manager or be registered as LLVM extensions.
d. External/Supporting Elements:
- Documentation and Wiki: Though not part of the compiled code itself, the wiki (as seen in the README) provides additional context on usage, design decisions, and potential configuration parameters.
- Build/Configuration Setup: While not shown here explicitly, expect build scripts or configuration files (possibly in the repository) that allow for compiling and integrating the custom passes within LLVM.

##### Relationships and Interactions
- The data flow starts with source code being compiled by LLVM’s Frontend.
- The produced LLVM IR then flows to the custom Obfuscator-LLVM passes.
- Each obfuscation pass might be responsible for a specific transformation on the IR.
- After the obfuscation passes, the modified IR is passed back into LLVM’s optimization and code generation pipelines.
- On the ordering and dependencies where each obfuscation pass might depend on the output of previous ones.

##### Architectural Patterns and Design Principles
- Modular Design: Each obfuscation technique is implemented as an independent LLVM pass.
- Pipeline Integration: The design leverages LLVM’s pass manager framework, effectively “plugging in” new behavior into the standard compilation pipeline.
- Extensibility: The system design should facilitate adding new obfuscation passes or modifying the order of existing ones.
- Separation of Concerns: Clearly separate LLVM’s core compilation responsibilities from the obfuscation functionalities.

##### Including Relevant Technologies
- C++ as the primary programming language.
- LLVM libraries and APIs (particularly for LLVM 4.0).
- Likely usage of CMake or other build systems for managing dependencies and build configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% LLVM Core Pipeline
    subgraph "LLVM Core Pipeline"
        src["Source Code"]:::core
        frontend["LLVM Frontend"]:::core
        ir["LLVM IR Generation"]:::core
        backend["LLVM Optimizer & Backend"]:::core
        machine["Machine Code Output"]:::core
    end

    %% Obfuscation Layer
    subgraph "Obfuscation Layer"
        integration["LLVM Pass Manager Integration"]:::obfuscation
        pass1["Control Flow Flattening"]:::obfuscation
        pass2["Instruction Substitution"]:::obfuscation
        pass3["Bogus Control Flows"]:::obfuscation
    end

    %% External Supporting Element
    doc["Documentation & Wiki"]:::external

    %% Connections in LLVM Core Pipeline
    src -->|"compiles"| frontend
    frontend -->|"generates"| ir

    %% Connection from LLVM Core Pipeline to Obfuscation Layer
    ir -->|"passesIR"| integration
    integration -->|"applies"| pass1
    pass1 -->|"then"| pass2
    pass2 -->|"then"| pass3
    pass3 -->|"modifiedIR"| backend

    backend -->|"generates"| machine

    %% External Documentation providing context
    doc ---|"guides"| integration

    %% Click Events
    click doc "https://github.com/obfuscator-llvm/obfuscator/blob/master/README.md"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef obfuscation fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef external fill:#FFFF99,stroke:#000,stroke-width:1px;
```
