# iciclez/memory-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/iciclez/memory-analyzer
- Repository: https://github.com/iciclez/memory-analyzer

## Overview

##### Project type and purpose
- This is a native Windows C++ “loadable DLL” tool whose job is to be injected or loaded into a target process and then:
- Hook API calls via Import Address Table (IAT) and Microsoft Detours
- Disassemble code at runtime (using Zydis) to discover trampolines or inline JMP hooks
- Monitor and record memory writes/changes
- Log all of the above to an external sink (console, file, etc.)

##### File structure
- Top-level
- Memory Analyzer.sln – Visual Studio solution
- .gitignore, LICENSE, README.md
- /Memory Analyzer (VS project)
- detours.h / detours.lib / detours64.lib – Microsoft Detours hooking library
- Zydis.c / Zydis.h – Zydis disassembler engine
- dllmain.cpp / dllmain.hpp – DllMain entry and unloading logic
- disassembler.cpp / .hpp – wrappers around Zydis for scanning instructions
- memory_analyzer.cpp / .hpp – core memory‐tracking engine
- logger.cpp / .hpp – logging subsystem (format, output)
- mnemosyne.cpp / .hpp – historical/event storage manager
- object.cpp / .hpp – internal representation of memory regions / hooks

##### README for additional insights
- Confirms loadable DLL
- Highlights three key behaviors: memory changes, IAT hooks, JMP hooks

##### Detail without over-splitting
- Every logical module (six in total) rather than every single .cpp file
- Interfaces between them, but avoid listing every function

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host and Injection
    HostProcess["Host Process\n(Windows EXE)"]:::host
    Injector["Injection Mechanism\n(rundll32/manual)"]:::host

    HostProcess -->|load DLL| Injector
    Injector -->|invoke DllMain| DllMain

    subgraph "Memory Analyzer DLL"
        direction TB
        DllMain["DllMain\n(Initialization/Cleanup)"]:::core
        HookManager["Hook Manager\n(Detours Integration)"]:::core
        DisassemblerModule["Disassembler Module\n(Zydis Integration)"]:::core
        MemoryTracking["Memory Tracking Engine"]:::core
        Mnemosyne["Historical/Event Manager\n(Mnemosyne)"]:::core
        Logger["Logger\n(Persistence/Output)"]:::core
        ObjectModule["Object Representations"]:::core

        DllMain -->|initialize hooks| HookManager
        HookManager -->|install hook| DisassemblerModule
        DisassemblerModule -->|scan code| MemoryTracking
        MemoryTracking -->|record memory changes| Mnemosyne
        Mnemosyne -->|dispatch events| Logger
        ObjectModule -->|provide structures| MemoryTracking
    end

    subgraph "External Libraries"
        direction TB
        DetoursLib["Detours Library"]:::ext
        ZydisLib["Zydis Library"]:::ext
    end

    HookManager -->|uses| DetoursLib
    DisassemblerModule -->|uses| ZydisLib

    LogSink["Log Sink\n(Console/File/UI)"]:::sink
    Logger -->|write log| LogSink

    %% Click Events
    click DllMain "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/dllmain.cpp"
    click HookManager "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/detours.h"
    click DisassemblerModule "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/disassembler.cpp"
    click MemoryTracking "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/memory_analyzer.cpp"
    click Mnemosyne "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/mnemosyne.cpp"
    click Logger "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/logger.cpp"
    click ObjectModule "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/object.cpp"
    click DetoursLib "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/detours.lib"
    click ZydisLib "https://github.com/iciclez/memory-analyzer/blob/master/Memory Analyzer/Zydis.c"

    %% Styles
    classDef core fill:#c2f0c2,stroke:#2f6627,color:#234d20
    classDef ext fill:#c2d9f0,stroke:#1f357f,color:#1f2550
    classDef sink fill:#f0d9c2,stroke:#7f4f1f,color:#5a3518
    classDef host fill:#e0e0e0,stroke:#666666,color:#333333
```
