# zyantific/zydis architecture

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

- Interactive diagram: https://gitdiagram.com/zyantific/zydis
- Repository: https://github.com/zyantific/zydis

## Overview

##### Main Components
- Core Library: This is the heart of the project. It is divided into several modules:
- Disassembler: Found in files like include/Zydis/Disassembler.h and src/Disassembler.c, along with generated tables (in include/Zydis/Generated and src/Generated).
- Encoder: Responsible for instruction encoding (include/Zydis/Encoder.h, src/Encoder.c, and examples such as EncodeMov.c).
- Formatter: Code for formatting disassembled instructions (include/Zydis/Formatter.h, src/Formatter.c etc.).
- Support Utilities: Other critical modules include the decoder, internal support (e.g., Decoder, Internal files in include/Zydis/Internal, src/Decoder.c), and shared data/utilities.
- Build & Configuration Infrastructure:
- Build System Files: CMakeLists.txt, meson.build, and supporting cmake/ modules indicate that the project supports multiple build systems.
- Visual Studio projects (located in the msvc directory) illustrate support for Windows IDE build processes.
- Examples & Tools:
- Example programs illustrate how to use the library (found in the examples folder, e.g., DisassembleSimple.c, EncodeMov.c).
- Tools like ZydisInfo, ZydisDisasm, and fuzzing tools in the tools and msvc/tools directories showcase applications built on top of the core library.
- Testing & Documentation:
- Tests: The tests folder contains unit/regression tests, regression_encoder, and binary reader/writer scripts.
- Documentation: Doxygen configuration (Doxyfile, files.dox) along with man pages and asset resources.
- Dependencies and Subprojects:
- The “dependencies” folder (with zycore) and “subprojects” indicate that some external or auxiliary libraries are integrated.

##### Establish Relationships and Interactions
- The Core Library serves as the backbone: it provides a well-defined API (via header files in include/) that interconnects the disassembler, encoder, and formatter modules.
- Client Applications (for instance, example programs and command-line tools) interact with the Core Library by linking against it.
- Build Systems (CMake/Meson/Visual Studio) orchestrate how the various components (core library, tests, examples) are compiled and linked.
- Testing modules utilize the core library components to ensure correctness and regression stability.
- Generated files (in src/Generated and include/Zydis/Generated) indicate that at build time, code generation is an important step and should be represented as part of the build process.

##### Architectural Patterns and Design Principles
- Layered Architecture: At the lowest level, you have low-level routines and generated tables. On top of that, the core modules (decoder/encoder/formatter) export a stable API. Finally, client programs and tools layer on top.
- Multi-build and Cross-platform Support: The existence of multiple build systems and configurations indicates that portability and flexible compilation are integral.

##### Instructing the Principal Software Engineer
- At the bottom, show “Core Library” containing Disassembler, Encoder, Formatter, Decoder, and Utility Modules.
- Next, illustrate “Build & Configuration” which connects to the Core Library and also supports the “Examples/Tools” layer.
- Adding annotations such as “No dynamic memory allocation”, “Thread-safe”, and “Cross-platform” to highlight core design principles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Build & Configuration"
        BL["Build System Files"]:::build
        VS["Visual Studio Projects"]:::build
    end

    subgraph "Core Library"
        D["Disassembler Module"]:::core
        E["Encoder Module"]:::core
        F["Formatter Module"]:::core
        DC["Decoder & Support Utilities"]:::core
    end

    subgraph "Applications & Testing"
        EX["Examples"]:::app
        TL["Tools"]:::app
        TS["Tests"]:::app
    end

    subgraph "Documentation"
        DOC["Documentation"]:::doc
    end

    subgraph "Dependencies & Subprojects"
        DEP["External Dependencies"]:::dep
        SUB["Subprojects"]:::dep
    end

    DP["Design Principles:\nNo dynamic memory allocation\nThread-safe\nCross-platform"]:::note

    %% Build systems feed into Core Library
    BL -->|"builds"| D
    BL -->|"builds"| E
    BL -->|"builds"| F
    BL -->|"builds"| DC
    VS -->|"builds"| D
    VS -->|"builds"| E
    VS -->|"builds"| F
    VS -->|"builds"| DC

    %% Design principles influence Core Library
    DP --> D
    DP --> E
    DP --> F
    DP --> DC

    %% Core Library supports Applications & Testing and Documentation
    D -->|"provides API"| EX
    E -->|"provides API"| EX
    F -->|"provides API"| EX
    DC -->|"provides API"| EX

    D -->|"provides API"| TL
    E -->|"provides API"| TL
    F -->|"provides API"| TL
    DC -->|"provides API"| TL

    D -->|"verified by"| TS
    E -->|"verified by"| TS
    F -->|"verified by"| TS
    DC -->|"verified by"| TS

    D -->|"documented in"| DOC
    E -->|"documented in"| DOC
    F -->|"documented in"| DOC
    DC -->|"documented in"| DOC

    %% Dependencies connect to Core Library and Build systems
    DEP --> D
    DEP --> E
    DEP --> F
    DEP --> DC
    SUB --> D
    SUB --> E
    SUB --> F
    SUB --> DC

    BL --> DEP
    BL --> SUB
    VS --> DEP
    VS --> SUB

    %% Click Events
    click D "https://github.com/zyantific/zydis/blob/master/include/Zydis/Disassembler.h"
    click E "https://github.com/zyantific/zydis/blob/master/include/Zydis/Encoder.h"
    click F "https://github.com/zyantific/zydis/blob/master/include/Zydis/Formatter.h"
    click DC "https://github.com/zyantific/zydis/blob/master/include/Zydis/Decoder.h"
    click BL "https://github.com/zyantific/zydis/blob/master/CMakeLists.txt"
    click VS "https://github.com/zyantific/zydis/blob/master/msvc/Zydis.sln"
    click EX "https://github.com/zyantific/zydis/blob/master/examples/Disassemble.c"
    click TL "https://github.com/zyantific/zydis/blob/master/tools/ZydisDisasm.c"
    click TS "https://github.com/zyantific/zydis/blob/master/tests/regression.py"
    click DOC "https://github.com/zyantific/zydis/tree/master/Doxyfile"
    click DEP "https://github.com/zyantific/zydis/tree/master/dependencies/zycore"
    click SUB "https://github.com/zyantific/zydis/tree/master/subprojects"

    %% Styles
    classDef core fill:#ccf,stroke:#333,stroke-width:2px;
    classDef build fill:#f99,stroke:#333,stroke-width:2px;
    classDef app fill:#9f9,stroke:#333,stroke-width:2px;
    classDef doc fill:#fc9,stroke:#333,stroke-width:2px;
    classDef dep fill:#ddd,stroke:#333,stroke-dasharray: 5, 5;
    classDef note fill:#eee,stroke:#333,stroke-width:2px,stroke-dasharray: 2,2;
```
