# restkhz/shellcodeencrypt2dll architecture

> Architecture diagram of the GitHub repository restkhz/shellcodeencrypt2dll, 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/restkhz/shellcodeencrypt2dll
- Repository: https://github.com/restkhz/shellcodeencrypt2dll

## Overview

##### Project type and purpose
- This is a security-oriented CLI tool written in Python and C++.
- Purpose: take raw shellcode, encrypt it (AES-CBC), generate a static Windows DLL loader (with or without embedding the key), optionally patch it further, then load and execute the shellcode via rundll32.

##### File structure
- Top level files:
- README.md – project description, usage, internals
- ShellcodeEncrypt2Dll.py – main Python script (encryption, code-gen, compile)
- patch.py – optional post-build DLL patcher to bypass AV
- template.cpp – C++ loader template that receives encrypted payload and decrypts/executes at runtime
- No separate “frontend/backend,” it’s a CLI-driven code-generation pipeline.

##### README for key insights
- Dependencies: pycryptodome, mingw-w64 toolchain, msfvenom for shellcode.
- Two modes:
- non-standalone (key passed at runtime)
- standalone (key embedded in DLL)
- Build flow: generate header from Python → compile via x86_64-w64-mingw32-g++ → produce loader.dll → optional patch → loader_patched.dll → load with rundll32.

##### Main components and their interactions
a. Shellcode input
- External: msfvenom (or any raw .raw shellcode file)
b. Encryption & code generation (ShellcodeEncrypt2Dll.py)
- Reads raw shellcode and API names
- Encrypts with AES-CBC using user key
- Emits a C/C++ header containing encrypted byte arrays + encrypted function name strings
c. Compilation
- template.cpp + generated header compiled by x86_64-w64-mingw32-g++ → loader.dll
d. Optional patching (patch.py)
- Applies binary modifications to loader.dll to further evade antivirus
- Outputs loader_patched.dll
e. Runtime loader
- Windows rundll32 loads DLL, calls export “EPoint”
- DLL decrypts payload, resolves WinAPI dynamically, allocates executable memory, launches shellcode

##### Architectural patterns & design principles
- Pipeline pattern: linear data flow through stages (encrypt → code-gen → compile → patch → run)
- Code-generation: Python script dynamically producing C++ source artifacts
- Separation of concerns:
- Encryption logic in Python
- Decryption/execution logic in C++ at runtime
- Optional AV-bypass patch in separate script

##### Technologies & external dependencies
- Python 3 + pycryptodome (AES library)
- MinGW-w64 cross-compiler (x86_64-w64-mingw32-g++)
- Windows API: VirtualAlloc, CreateThread, LoadLibrary/GetProcAddress (dynamic loading)
- msfvenom or equivalent for shellcode generation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Inputs
    RawShell["Raw Shellcode (.raw)"]:::io

    %% Documentation
    Docs["README.md"]:::io

    %% Build-time components
    PythonGen["ShellcodeEncrypt2Dll.py\n(Encrypt & Header Gen\nStandalone vs Non-Standalone)"]:::build
    TemplateCPP["template.cpp"]:::build
    Compiler["MinGW-w64 Compiler\n(x86_64-w64-mingw32-g++)"]:::build
    Patcher["patch.py\n(Optional AV-Bypass)"]:::build

    %% Generated Artifacts
    HeaderH["Generated header.h"]:::artifact
    LoaderDLL["loader.dll"]:::artifact
    PatchedDLL["loader_patched.dll"]:::artifact

    %% Runtime Execution
    subgraph "Runtime Execution"
        direction TB
        Rundll["rundll32.exe"]:::runtime
        DLLRuntime["DLL Runtime:\nDecrypt & Execute\n(EPoint export,\nDynamic API resolution,\nVirtualAlloc,\nCreateThread)"]:::runtime
        ShellExec["Shellcode Execution"]:::io
    end

    %% Flow
    Docs --> PythonGen
    RawShell --> PythonGen
    PythonGen --> HeaderH
    HeaderH --> Compiler
    TemplateCPP --> Compiler
    Compiler --> LoaderDLL
    LoaderDLL --> Patcher
    Patcher --> PatchedDLL
    PatchedDLL --> Rundll
    Rundll --> DLLRuntime
    DLLRuntime --> ShellExec

    %% Click Events
    click PythonGen "https://github.com/restkhz/shellcodeencrypt2dll/blob/main/ShellcodeEncrypt2Dll.py"
    click Patcher "https://github.com/restkhz/shellcodeencrypt2dll/blob/main/patch.py"
    click TemplateCPP "https://github.com/restkhz/shellcodeencrypt2dll/blob/main/template.cpp"
    click Docs "https://github.com/restkhz/shellcodeencrypt2dll/blob/main/README.md"

    %% Styles
    classDef build fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef artifact fill:#d4edda,stroke:#333,stroke-width:1px
    classDef runtime fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef io fill:#f8f9fa,stroke:#333,stroke-width:1px
```
