# connorpatterson/pe-loader-sample architecture

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

- Interactive diagram: https://gitdiagram.com/connorpatterson/pe-loader-sample
- Repository: https://github.com/connorpatterson/pe-loader-sample

## Overview

##### Project Type and Purpose
- This is a two-part Windows PE crypter proof-of-concept, written in C++.
- Part 1 (“XOR-Cipher-Executable”) is a CLI tool that takes a PE file, applies an XOR cipher, and emits “crypt.exe.”
- Part 2 (“Pe-Loader-Sample”) is a custom PE loader. It embeds the encrypted PE as a resource, decrypts it in memory at runtime, performs relocations and import resolution, and then transfers execution to it—all without writing the decrypted image to disk.

##### File Structure
Top-level folders:
- XOR-Cipher-Executable
– XOR-Cipher-Executable.cpp (main encryption logic)
– README.md (usage instructions)
- Loader-Sample-master
– .vcproj (Visual Studio project definition for the loader)
– src/
- PeLdr.cpp / PeLdr.h (core loader code: map image, fix relocations, resolve imports)
- Main.cpp (entry point modified to load from resource rather than disk)
- Debug.h, PEB.h (helper headers), resource.h
– .gitignore, .gitattributes
Observations:
– Two distinct executables, each with its own source and build configuration.
– The loader uses Windows resource mechanism (RCDATA) to carry the encrypted payload.
– No database or external service; the system relies on OS services for memory mapping and PE parsing.

##### README for Insights
- The crypter tutorial: codeproject.com/Articles/1174823…
- Workflow: encrypt → embed as resource → build loader → run loader → in-memory decryption and execution.
- Modifications: loader removed disk I/O, arguments, added XOR decryption prior to invoking original loader logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Offline Encryption Stage
    subgraph "Offline Encryption Stage"
        direction TB
        Input["Input PE File"]:::misc
        XOR["XOR-Cipher CLI Tool"]:::encryption
        Usage["Usage Instructions"]:::encryption
        Input -->|"Encrypt"| XOR
        XOR --> crypt["Encrypted Payload (crypt.exe)"]:::encryption
        XOR -.-> Usage
    end

    %% Embedding Stage
    crypt --> rc["Resource Compiler (rc.exe)"]:::misc
    rc --> loaderBin["PE-Loader Binary"]:::loader

    %% Loader Runtime Stage
    subgraph "Loader Runtime"
        direction TB
        ResourceAPI["Resource Extraction\n(RCDATA)"]:::loader
        Decrypt["XOR Decryption Engine"]:::loader
        Parser["PE Parser & Memory Mapper"]:::loader
        Reloc["Relocator"]:::loader
        Resolve["Import Resolver"]:::loader
        Exec["Execution Transfer"]:::loader
        loaderBin --> ResourceAPI
        ResourceAPI --> Decrypt
        Decrypt --> Parser
        Parser --> Reloc
        Reloc --> Resolve
        Resolve --> Exec
        Exec -->|"In-memory Execution"| OS["Windows OS Kernel/\nMemory Manager"]:::os
    end

    %% Project Files
    subgraph "Project Files"
        direction TB
        VSProj["PE-Loader Project (.vcproj)"]:::misc
        LoaderReadme["Loader README.md"]:::misc
        ResourceDef["Resource Definitions\n(resource.h)"]:::misc
        Entry["Loader Entry Point\n(Main.cpp)"]:::misc
        PeLdrCpp["PeLdr.cpp"]:::misc
        PeLdrH["PeLdr.h"]:::misc
        DebugH["Debug.h"]:::misc
        PEBH["PEB.h"]:::misc
        Gitig[".gitignore"]:::misc
        Gitat[".gitattributes"]:::misc
        License["LICENSE"]:::misc
        TopReadme["Top-Level README.md"]:::misc
    end

    %% Click Events
    click XOR "https://github.com/connorpatterson/pe-loader-sample/blob/master/XOR-Cipher-Executable/XOR-Cipher-Executable.cpp"
    click Usage "https://github.com/connorpatterson/pe-loader-sample/blob/master/XOR-Cipher-Executable/README.md"
    click VSProj "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/Pe-Loader-Sample.vcproj"
    click LoaderReadme "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/README.md"
    click ResourceDef "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/src/resource.h"
    click Entry "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/src/Main.cpp"
    click PeLdrCpp "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/src/PeLdr.cpp"
    click PeLdrH "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/src/PeLdr.h"
    click DebugH "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/src/Debug.h"
    click PEBH "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/src/PEB.h"
    click Gitig "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/.gitignore"
    click Gitat "https://github.com/connorpatterson/pe-loader-sample/blob/master/Loader-Sample-master/.gitattributes"
    click License "https://github.com/connorpatterson/pe-loader-sample/tree/master/LICENSE"
    click TopReadme "https://github.com/connorpatterson/pe-loader-sample/blob/master/README.md"

    %% Styles
    classDef encryption fill:#a2cffe,stroke:#0366d6,color:#0366d6;
    classDef loader fill:#b7e4c7,stroke:#2d6a4f,color:#2d6a4f;
    classDef os fill:#e9ecef,stroke:#6c757d,color:#495057;
    classDef misc fill:#f0efeb,stroke:#adb5bd,color:#343a40;
```
