# ulexec/shelf-loading architecture

> Architecture diagram of the GitHub repository ulexec/shelf-loading, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ulexec/shelf-loading
- Repository: https://github.com/ulexec/shelf-loading

## Overview

##### Main Components
- Source Code Files:
- Static PIE Loader (static-pie-loader.c) which likely contains the core loader logic.
- Test code (test.c) for exercising or demonstrating the loader’s functionality.
- Header files under the include directory (embedded.h and static-pie-loader.h) supporting modular definitions.
- Linker Script:
- static-pie.ld that directs the linker on how to layout the final PIE binary.
- Build and Deployment Tools:
- Makefile and build_and_run.sh script to automate compilation and testing.
- Dockerfile to create a containerized build environment if needed.
- Utility Scripts:
- strip_headers.py likely handles post-compilation modifications to remove or adjust headers for the desired evasive behavior.
- Documentation:
- README.md that provides context and credits, indicating that this tool is meant for creating evasive executables, possibly for security testing or research.

##### Flow and Interactions
- Development Environment: The Dockerfile indicates containerized builds, which encapsulate the build tools and runtime environment.
- Compilation Process:
- The Makefile (invoked manually or via build_and_run.sh) orchestrates the compile steps for the source files.
- The compiler uses the provided static-pie.ld linker script to enforce static PIE properties.
- Post-Compilation Processing:
- strip_headers.py is applied post-compilation to modify the output binary headers, hinting at techniques used to evade standard detection or analysis.
- Testing/Execution:
- test.c is used to test the final binary. The build_and_run.sh wraps up the build and run cycle for quick validation.

##### Architectural Patterns and Design Principles
- Modular Structure: The separation into source, include, and script files shows emphasis on clear modularization.
- Build Pipeline Pattern: There is a defined sequence from writing source code, invoking build scripts, applying linker customizations, and finally testing the output.
- Containerization: Dockerfile usage presents an isolated build environment ensuring consistency.
- Automation: The Makefile and build shell script automate steps to ensure repeatable builds.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Source Code Subgraph
    subgraph "Source Code"
        loader("static-pie-loader.c"):::source
        header1("include/static-pie-loader.h"):::source
        header2("include/embedded.h"):::source
        testCode("test.c"):::source
        doc("README.md"):::doc
    end

    %% Build System Subgraph
    subgraph "Build System"
        makefile("Makefile"):::build
        buildScript("build_and_run.sh"):::build
        docker("Dockerfile"):::build
    end

    %% Linker and Binary Customization Subgraph
    subgraph "Linker & Customization"
        ldScript("static-pie.ld"):::link
        strip("strip_headers.py"):::link
    end

    %% Output and Execution Nodes
    bin("Static PIE Executable"):::executable
    testExec("Test/Execution"):::execution

    %% Connections: Source Code to Build System
    loader --> makefile
    header1 --> makefile
    header2 --> makefile
    testCode --> makefile
    doc --> loader

    %% Connections: Build System to Linker & Customization
    makefile --> ldScript
    buildScript --> ldScript
    docker --> ldScript

    %% Connections: Linking to Final Binary
    ldScript --> bin
    strip --> bin

    %% Connections: Final binary to Test Execution
    bin --> testExec

    %% Click Events
    click loader "https://github.com/ulexec/shelf-loading/blob/master/static-pie-loader.c"
    click header1 "https://github.com/ulexec/shelf-loading/blob/master/include/static-pie-loader.h"
    click header2 "https://github.com/ulexec/shelf-loading/blob/master/include/embedded.h"
    click testCode "https://github.com/ulexec/shelf-loading/blob/master/test.c"
    click doc "https://github.com/ulexec/shelf-loading/blob/master/README.md"
    click makefile "https://github.com/ulexec/shelf-loading/tree/master/Makefile"
    click buildScript "https://github.com/ulexec/shelf-loading/blob/master/build_and_run.sh"
    click docker "https://github.com/ulexec/shelf-loading/tree/master/Dockerfile"
    click ldScript "https://github.com/ulexec/shelf-loading/blob/master/static-pie.ld"
    click strip "https://github.com/ulexec/shelf-loading/blob/master/strip_headers.py"

    %% Styles
    classDef source fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef build fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef link fill:#fdfd96,stroke:#333,stroke-width:2px;
    classDef executable fill:#ffb6c1,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef execution fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef doc fill:#dda0dd,stroke:#333,stroke-width:2px;
```
