# microsoft/detours architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/detours
- Repository: https://github.com/microsoft/detours

## Overview

Based on our analysis of the file tree and the README, this project is the Microsoft Research Detours Package—a Windows API instrumentation library. Its purpose is to enable monitoring and manipulation of API calls on Windows systems. The project consists of a core detouring library (in the src directory), several sample applications (in the samples directory) that demonstrate how to use the detouring functionality, and a set of tests (in the tests directory) to verify behavior and API interception. It also contains the VC solution files for Visual Studio and many Makefiles/scripts for managing builds and continuous integration (in the .github and root directories).

##### Main Components
- Core Service (Detours Library): Represent the heart of the project by grouping files in the src directory. This includes files such as detours.cpp, detours.h, disassembly modules (disasm.cpp, disolarm.cpp, etc.), module management, and API interception support.
- Sample Applications: The samples folder contains various demos (comeasy, commem, cping, etc.) which show how to use the detouring mechanism in different scenarios. These can be grouped into a “Sample Clients” component.
- Testing Framework: The tests directory includes unit and integration test files (like payload.cpp, test_image_api.cpp, etc.) that verify the functionality of the core library.
- Build and Continuous Integration Infrastructure: Include your build scripts (Makefile, system.mak, and files under .github) as a separate component, indicating the build system, CI pipelines, and dependency management.
- Visual Studio Project Files: Acknowledge the vc directory containing the solution and project files to illustrate the development environment used (Visual Studio integration).

##### Relationships and Interactions
- Indicating that the Visual Studio projects and the Makefiles serve as two parallel build ecosystems (if applicable for different target developers/environments).

##### Architectural Patterns and Design Principles
- Separation of concerns: the detouring logic (core library) is isolated from its real-world usage (samples) and validation (tests).
- The design follows a modular approach with multiple sample implementations demonstrating various use cases of API interception.
- That while the system doesn’t strictly follow a full-stack client–server pattern, it does separate low-level instrumentation (library) from its consumption (samples and tests).

##### Relevant Technologies, Frameworks, or Libraries
- Windows API: As the core mechanism of hook/interception is tied directly to Windows system calls.
- Build Tools: Make (Makefiles) and Visual Studio (VC solution files).
- GitHub workflows and configuration files for CI (e.g., .github/workflows/main.yml).

- A section for the build system/CI configurations showing how they connect to all parts of the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    BuildCI["Build and CI Infrastructure"]:::build
    VS["Visual Studio Project Files"]:::vs
    CoreLib["Core Detours Library"]:::core
    Samples["Sample Applications"]:::sample
    Tests["Testing Framework"]:::test

    BuildCI -->|"builds"| CoreLib
    BuildCI -->|"builds"| Samples
    BuildCI -->|"builds"| Tests

    VS -->|"integrates"| CoreLib

    Samples -->|"depends"| CoreLib
    Tests -->|"tests"| CoreLib

    click CoreLib "https://github.com/microsoft/detours/tree/main/src"
    click Samples "https://github.com/microsoft/detours/tree/main/samples"
    click Tests "https://github.com/microsoft/detours/tree/main/tests"
    click BuildCI "https://github.com/microsoft/detours/tree/main/Makefile"
    click VS "https://github.com/microsoft/detours/tree/main/vc"

    classDef core fill:#ffcccc,stroke:#b30000,stroke-width:2px;
    classDef sample fill:#cceeff,stroke:#003399,stroke-width:2px;
    classDef test fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef build fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef vs fill:#e6ccff,stroke:#660099,stroke-width:2px;
```
