# lief-project/lief architecture

> Architecture diagram of the GitHub repository lief-project/lief, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lief-project/lief
- Repository: https://github.com/lief-project/lief

## Overview

##### Main Components Structure

**┌─ Core Library ─────────────────────┐**
- ┌─────────────┐  ┌──────────────┐  │
- Format Parser│  │Binary Stream │  │
- ┘  └──────────────┘  │
- ┌─────────────┐  ┌──────────────┐  │
- Abstract   │  │    Utils     │  │
- ┘  └──────────────┘  │
- ┘

**┌─ File Format Support ──────────────┐**
- ┌────┐ ┌────┐ ┌─────┐ ┌────────┐  │
- ELF │ │ PE │ │MachO│ │Android │  │
- ┘ └────┘ └─────┘ └────────┘  │
- ┘

**┌─ API Bindings ───────────────────┐**
- ┌────┐ ┌────────┐ ┌──────────┐  │
- C++ │ │ Python │ │  Rust    │  │
- ┘ └────────┘ └──────────┘  │
- ┘

##### Component Details

For each major component, include:

a) Format Parsers:
- Input handling
- Format-specific structures
- Parsing logic
- Modification capabilities

b) Extended Features:
- DWARF/PDB debug info
- Objective-C metadata
- Dyld Shared Cache
- Disassembler/Assembler

##### Data Flow

Interaction between components:
**Input Binary → Parser → Abstract Representation ↔ Modification API → Output Binary**

##### Specific Implementation Details

Architectural patterns:
- Visitor pattern for binary format traversal
- Factory pattern for parser creation
- Abstract interfaces for format-agnostic operations

##### Integration Points

External integration:
- CMake build system
- Package management
- API access points

##### The separation between core functionality and extended features

Remember to highlight the cross-platform nature of the library and its ability to handle multiple binary formats through a unified interface.

This design should reflect LIEF's primary goal of providing a unified interface for parsing, modifying, and abstracting various executable formats while maintaining extensibility and ease of use across different programming languages.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Library"]
        direction TB
        Abstract["Abstract Layer"]
        BinaryStream["Binary Stream"]
        Utils["Utils"]
        Parser["Format Parser"]
    end

    subgraph Formats["File Format Support"]
        direction TB
        ELF["ELF Format"]
        PE["PE Format"]
        MachO["MachO Format"]
        
        subgraph Android["Android Formats"]
            direction TB
            ART["ART Format"]
            DEX["DEX Format"]
            OAT["OAT Format"]
            VDEX["VDEX Format"]
        end
    end

    subgraph API["API Bindings"]
        direction TB
        CPP["C++ API"]
        Python["Python API"]
        Rust["Rust API"]
    end

    subgraph Extended["Extended Features"]
        direction TB
        DWARF["DWARF Debug"]
        PDB["PDB Debug"]
        ObjC["Objective-C"]
        Dyld["Dyld Cache"]
        Asm["Assembler/Disassembler"]
    end

    subgraph Core_Impl["Core Implementation"]
        direction TB
        Source["Main Source"]
        Tests["Tests"]
        Examples["Examples"]
        Docs["Documentation"]
    end

    subgraph Build["Build System"]
        direction TB
        CMake["CMake Config"]
        CMakeModules["CMake Modules"]
    end

    Platform["Platform Support"]
    Logging["Logging System"]
    ErrorHandling["Error Handling"]

    %% Relationships
    Abstract --> Parser
    BinaryStream --> Parser
    Parser --> ELF & PE & MachO & Android
    Parser --> Extended
    Extended --> API
    Core --> API
    Formats --> API

    %% Click events
    click Abstract "https://github.com/lief-project/LIEF/tree/main/include/LIEF/Abstract/"
    click BinaryStream "https://github.com/lief-project/LIEF/tree/main/include/LIEF/BinaryStream/"
    click Utils "https://github.com/lief-project/LIEF/blob/main/include/LIEF/utils.hpp"
    click ELF "https://github.com/lief-project/LIEF/tree/main/include/LIEF/ELF/"
    click PE "https://github.com/lief-project/LIEF/tree/main/include/LIEF/PE/"
    click MachO "https://github.com/lief-project/LIEF/tree/main/include/LIEF/MachO/"
    click ART "https://github.com/lief-project/LIEF/tree/main/include/LIEF/ART/"
    click DEX "https://github.com/lief-project/LIEF/tree/main/include/LIEF/DEX/"
    click OAT "https://github.com/lief-project/LIEF/tree/main/include/LIEF/OAT/"
    click VDEX "https://github.com/lief-project/LIEF/tree/main/include/LIEF/VDEX/"
    click CPP "https://github.com/lief-project/LIEF/tree/main/api/c/"
    click Python "https://github.com/lief-project/LIEF/tree/main/api/python/"
    click Rust "https://github.com/lief-project/LIEF/tree/main/api/rust/"
    click DWARF "https://github.com/lief-project/LIEF/tree/main/include/LIEF/DWARF/"
    click PDB "https://github.com/lief-project/LIEF/tree/main/include/LIEF/PDB/"
    click ObjC "https://github.com/lief-project/LIEF/tree/main/include/LIEF/ObjC/"
    click Dyld "https://github.com/lief-project/LIEF/tree/main/include/LIEF/DyldSharedCache/"
    click Asm "https://github.com/lief-project/LIEF/tree/main/include/LIEF/asm/"
    click Source "https://github.com/lief-project/LIEF/tree/main/src/"
    click Tests "https://github.com/lief-project/LIEF/tree/main/tests/"
    click Examples "https://github.com/lief-project/LIEF/tree/main/examples/"
    click Docs "https://github.com/lief-project/LIEF/tree/main/doc/"
    click CMake "https://github.com/lief-project/LIEF/blob/main/CMakeLists.txt"
    click CMakeModules "https://github.com/lief-project/LIEF/tree/main/cmake/"
    click Platform "https://github.com/lief-project/LIEF/tree/main/include/LIEF/platforms/"
    click Logging "https://github.com/lief-project/LIEF/blob/main/include/LIEF/logging.hpp"
    click ErrorHandling "https://github.com/lief-project/LIEF/blob/main/include/LIEF/errors.hpp"

    %% Styling
    classDef core fill:#a8d1f0
    classDef format fill:#90EE90
    classDef api fill:#FFB347
    classDef extended fill:#DDA0DD
    classDef impl fill:#F0E68C
    classDef build fill:#E6E6FA
    classDef system fill:#D3D3D3

    class Abstract,BinaryStream,Utils,Parser core
    class ELF,PE,MachO,Android,ART,DEX,OAT,VDEX format
    class CPP,Python,Rust api
    class DWARF,PDB,ObjC,Dyld,Asm extended
    class Source,Tests,Examples,Docs impl
    class CMake,CMakeModules build
    class Platform,Logging,ErrorHandling system
```
