# liunicky/simple-dll-injection architecture

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

- Interactive diagram: https://gitdiagram.com/liunicky/simple-dll-injection
- Repository: https://github.com/liunicky/simple-dll-injection

## Overview

##### Project Type and Purpose
- This is a specialized tool for DLL injection in Windows processes using native C++.
- The README and file tree reveal two main parts: an injector application (SimpleDLLInjection) and the payload DLL (located under testlib). The injector uses Windows API calls (e.g., FindWindow, OpenProcess, VirtualAllocEx, CreateRemoteThread) to inject the DLL into a target process.

##### File Structure
- At the top level, you have a directory “C++” containing solution files and two projects:
– "SimpleDLLInjection" – the main injector executable project.
– "testlib" – a project that builds the DLL which is injected into the target process.
- The README provides a complete code example demonstrating the injection flow.

##### Pinpoint the Main Components
a. Injector Application (SimpleDLLInjection):
– Inside or alongside it, annotate the key steps: locating the target window, obtaining the process ID, opening the target process, allocating memory, writing the DLL path, and initiating a remote thread.
b. DLL Payload (testlib.dll):
c. Target Process:
– Since the DLL is injected into an external process (identified by its window title “Tutorial-x86_64”), include a block representing “Target Process (Tutorial-x86_64)”.
d. Windows API/System Services:
e. Development Environment Components:
– Although not part of the runtime system, the Visual Studio solution and project files (SimpleDLLInjection.sln, .vcxproj files) provide build context and can be noted in a “Build/Development” section if desired.

##### Relationships and Data Flow Between Components
1. The Injector locates the target window (via FindWindowA) → retrieves the process ID.
2. The Injector opens the Target Process (using OpenProcess) → allocates memory (VirtualAllocEx), writes the DLL path (WriteProcessMemory).
3. The Injector creates a remote thread in the Target Process (CreateRemoteThread) that calls LoadLibraryA to load the DLL.
- That the flow starts with the injector and crosses over into the target process, which upon receiving the injected DLL may further execute code within its own address space.

##### Architectural Patterns and Design Principles
- Separation of concerns: Clearly distinguish the injector executable from the DLL payload.
- Dependency on Windows API: Indicate that critical functionality is provided via Windows API functions, which orchestrate the injection operation.
- Minimal inter-component dependencies beyond the injection control flow.

##### Final Assembly
- The Injector application initiating the process.
- Communication with the Windows API services for process manipulation.
- The relocation (memory allocation, thread creation) that causes the DLL to load into the Target Process.
- Being very detailed—you want to capture the injection sequence with as many relevant components and API interactions as are indicated by the project’s file structure and README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build/Development Subgraph
    subgraph "Build/Development"
        vsSolution["Solution (SimpleDLLInjection.sln)"]:::dev
        vsProjInjector["Project (SimpleDLLInjection.vcxproj)"]:::dev
        vsProjTestlib["Project (testlib.vcxproj)"]:::dev
    end

    %% Main Application Components
    injector["Injector (SimpleDLLInjection.exe)"]:::injector
    windowsApi["Windows API / OS Services"]:::api
    targetProcess["Target Process (Tutorial-x86_64)"]:::external
    dllPayload["Injected DLL (testlib.dll)"]:::injector

    %% Relationships from Build/Development to application components
    vsProjInjector --> injector
    vsProjTestlib --> dllPayload

    %% Injection and API Interactions
    injector -->|"FindWindowA/GetWindowThreadProcessId"| windowsApi
    injector -->|"OpenProcess,VirtualAllocEx,WriteProcessMemory"| windowsApi
    injector -->|"CreateRemoteThread(LoadLibraryA)"| targetProcess
    targetProcess -->|"DLL_Loaded"| dllPayload

    %% Click Events for mapped components
    click injector "https://github.com/liunicky/simple-dll-injection/blob/master/C++/SimpleDLLInjection/SimpleDLLInjection.cpp"
    click dllPayload "https://github.com/liunicky/simple-dll-injection/blob/master/C++/testlib/dllmain.cpp"
    click vsSolution "https://github.com/liunicky/simple-dll-injection/blob/master/C++/SimpleDLLInjection.sln"
    click vsProjInjector "https://github.com/liunicky/simple-dll-injection/blob/master/C++/SimpleDLLInjection/SimpleDLLInjection.vcxproj"
    click vsProjTestlib "https://github.com/liunicky/simple-dll-injection/blob/master/C++/testlib/testlib.vcxproj"

    %% Styles
    classDef injector fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dev fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
