Skip to main content

STX - Systems Toolbelt for C++23

STX is a header-only C++23 library providing type-safe abstractions and utilities for systems programming, binary analysis, runtime instrumentation, and scripting at the OS/hardware interface.
Version 2.0.0 — This project is intended for personal use and experimentation. Users are free to fork or modify it, but all usage is at their own risk.

Key Features

Header-Only

Zero dependencies beyond the C++23 standard library

Type Safety

Strong types for offsets, addresses, and function signatures

Zero Overhead

Constexpr-friendly abstractions with no runtime cost

C++ Modules

Optional module support for modern build systems

Core Capabilities

STX provides six specialized modules for low-level programming:
Safe memory access, alignment primitives, and colored hexadecimal dumps for inspection and debugging.
Type-safe, binary-oriented file operations with explicit stream state management.
Strongly-typed wrappers around arbitrary memory addresses for callable functions.
Portable UNIX time conversions and high-resolution stopwatch functionality.
Domain-safe, constexpr-friendly integer and strong-type ranges for iteration.
Fundamental fixed-width types, strong types, and compile-time concepts.

Use Cases

STX is designed for developers working in:
  • Binary Analysis — PE/ELF/Mach-O parsers and format analysis tools
  • Runtime Patching — Memory manipulation and code injection
  • Reverse Engineering — Low-level inspection and instrumentation utilities
  • Systems Programming — Loader implementations and OS interface tooling
  • Security Research — Red teaming and vulnerability research tools

Quick Example

example.cpp
#include <lbyte/stx.hpp>
#include <fstream>

using namespace stx;

auto main() -> int
{
    std::ifstream file { "target.dll", std::ios::binary };
    if ( not file.is_open() ) return EXIT_FAILURE;

    // Read DOS and NT headers with type safety
    auto dos = readfs<IMAGE_DOS_HEADER>(file);
    auto nt = readfs<IMAGE_NT_HEADERS64>(file, offset_t{dos.e_lfanew});

    // Calculate section table offset
    auto sections_offset = offset_t{
        dos.e_lfanew
        + sizeof(u32)
        + sizeof(IMAGE_FILE_HEADER)
        + nt.FileHeader.SizeOfOptionalHeader
    };

    // Bulk read sections into optimized buffer
    auto sections = readfs<IMAGE_SECTION_HEADER>(
        file,
        sections_offset,
        nt.FileHeader.NumberOfSections
    );

    for (const auto& sec : sections) {
        std::println("Section: {}", sec.get_name());
    }

    return EXIT_SUCCESS;
}
This demonstrates type-safe file reading, strong-type offset arithmetic, and zero-overhead bulk allocation with dirty_vector.

Get Started

Quickstart

Get up and running in minutes

Installation

Installation guide for CMake and Xmake

API Reference

Explore the complete API documentation

Examples

Learn from real-world examples

Build docs developers (and LLMs) love