# mochabyte0x/vmkit architecture

> Architecture diagram of the GitHub repository mochabyte0x/vmkit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mochabyte0x/vmkit
- Repository: https://github.com/mochabyte0x/vmkit

## Overview

vmkit is a header-only C++20 template for building IR-bytecode loaders. A loader supplies a mutable context and opcode handlers; the VM optionally decrypts bytecode, decodes and dispatches each operation, and lets handlers perform loader-specific work. The example documents a builder-to-loader shellcode round trip. The source excerpt shows the VM internals, while example behavior and its connections are based on the README; no separate storage or external-service layer is present.

Main entry points: [`vm_loader.hpp`](https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp) (VM Dispatcher), [`example/example_builder.cpp`](https://github.com/mochabyte0x/vmkit/blob/main/example/example_builder.cpp) (Example Builder), [`example/example_loader.cpp`](https://github.com/mochabyte0x/vmkit/blob/main/example/example_loader.cpp) (Example Loader), [`example/payload.bin`](https://github.com/mochabyte0x/vmkit/blob/main/example/payload.bin) (Shellcode Payload)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_loader(("Loader"))
node_builder["Example Builder"]
node_payload["Shellcode Payload<br/>[payload.bin]"]
node_bytecode["IR Bytecode"]
node_vm["VM Dispatcher<br/>[vm_loader.hpp]"]
node_handlers["Opcode Handlers<br/>[vm_loader.hpp]"]
node_context["Loader Context"]
node_config["Config Hooks<br/>[vm_loader.hpp]"]
node_hash["API Hash<br/>[vm_loader.hpp]"]
node_example_loader["Example Loader<br/>[example_loader.cpp]"]

node_builder -->|"reads"| node_payload
node_builder -->|"emits"| node_bytecode
node_loader -->|"invokes"| node_vm
node_example_loader -->|"invokes"| node_vm
node_vm -->|"decodes"| node_bytecode
node_vm -->|"calls hooks"| node_config
node_vm -->|"dispatches"| node_handlers
node_handlers -->|"updates"| node_context

click node_builder "https://github.com/mochabyte0x/vmkit/blob/main/example/example_builder.cpp"
click node_payload "https://github.com/mochabyte0x/vmkit/blob/main/example/payload.bin"
click node_vm "https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp"
click node_handlers "https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp"
click node_config "https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp"
click node_hash "https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp"
click node_example_loader "https://github.com/mochabyte0x/vmkit/blob/main/example/example_loader.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_bytecode,node_context toneIndigo
class node_builder,node_payload,node_vm,node_config,node_example_loader toneTeal
class node_handlers,node_hash toneMint
```

## Components

### Other components

- **Loader**
- [Example Builder](https://github.com/mochabyte0x/vmkit/blob/main/example/example_builder.cpp): `example/example_builder.cpp`
- [Shellcode Payload](https://github.com/mochabyte0x/vmkit/blob/main/example/payload.bin): `example/payload.bin`
- **IR Bytecode**
- [VM Dispatcher](https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp): `vm_loader.hpp`
- [Opcode Handlers](https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp): `vm_loader.hpp`
- **Loader Context**
- [Config Hooks](https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp): `vm_loader.hpp`
- [API Hash](https://github.com/mochabyte0x/vmkit/blob/main/vm_loader.hpp): `vm_loader.hpp`
- [Example Loader](https://github.com/mochabyte0x/vmkit/blob/main/example/example_loader.cpp): `example/example_loader.cpp`

## Connections

- Example Builder → Shellcode Payload: reads (evidence: `README.md`)
- Example Builder → IR Bytecode: emits (evidence: `README.md`)
- Loader → VM Dispatcher: invokes (evidence: `README.md`)
- Example Loader → VM Dispatcher: invokes (evidence: `README.md`)
- VM Dispatcher → IR Bytecode: decodes (evidence: `vm_loader.hpp`)
- VM Dispatcher → Config Hooks: calls hooks (evidence: `vm_loader.hpp`)
- VM Dispatcher → Opcode Handlers: dispatches (evidence: `vm_loader.hpp`)
- Opcode Handlers → Loader Context: updates (evidence: `README.md`)
