Introduction
The syscalls-cpp library is built on a policy-based architecture that leverages C++20 concepts to provide compile-time verified, modular building blocks for syscall execution. Rather than providing a single monolithic implementation, the library allows you to compose different strategies (policies) for memory allocation, stub generation, and syscall number resolution. The core principle is modularity. You are not given a black box; you are given building blocks.The Three Policy Types
The library defines three distinct policy categories, each enforced through C++20 concepts:1. Allocation Policies (IsIAllocationPolicy)
Control where and how syscall stubs are stored in memory:
allocator::section- UsesSEC_NO_CHANGEsections for immutable stubsallocator::heap- Uses executable heaps withHEAP_CREATE_ENABLE_EXECUTEallocator::memory- Standard virtual memory with RW → RX transition
2. Stub Generation Policies (IsStubGenerationPolicy)
Control how syscalls are executed:
generator::direct- Classic self-containedsyscallinstructiongenerator::gadget- Indirect execution viasyscall; retgadgets from ntdll (x64 only)generator::exception- VEH-based approach usingud2breakpoints
3. Parsing Policies (IsSyscallParsingPolicy)
Control how syscall numbers are resolved:
parser::directory- Uses exception directory (x64) or sorted exports (x86)parser::signature- Scans function prologues with hook detection and halo gates
C++20 Concepts
The library uses C++20 concepts to enforce policy contracts at compile-time. This ensures type safety and provides clear error messages if a policy doesn’t meet requirements.IsIAllocationPolicy Concept
static bool allocate(...)- Allocate and populate memorystatic void release(...)- Clean up allocated resources
IsStubGenerationPolicy Concept
static constexpr bool bRequiresGadget- Whether the policy needs syscall gadgetsstatic constexpr size_t getStubSize()- Size of generated stub in bytesstatic void generate(...)- Generate the stub code
IsSyscallParsingPolicy Concept
static std::vector<SyscallEntry_t> parse(...)- Extract syscall numbers from a module
The Manager Template
TheManager class template is the central component that ties policies together:
- Validates policies at compile-time using static assertions
- Initializes the syscall infrastructure by parsing modules and generating stubs
- Provides the
invoke()method for executing syscalls with type safety - Manages resource lifecycle through RAII principles
Policy Composition Flow
When you create a Manager instance, the following happens:- Parsing Phase: Parsers extract syscall numbers from ntdll.dll (or other modules)
- Randomization: Syscall entries are shuffled for OPSEC
- Stub Generation: Each syscall gets a stub generated based on the generation policy
- Allocation: All stubs are written to memory using the allocation policy
- Ready: The
invoke()method can now be called to execute syscalls
Static Assertions for Policy Validation
The library provides helpful compile-time error messages when policies don’t meet requirements:- All template parameters satisfy their respective concepts
- Compilation fails early with clear error messages
- No runtime surprises due to missing or incorrect policy implementations
Next Steps
Allocation Policies
Learn about the three allocation strategies and their security implications
Stub Generation Policies
Understand how syscall stubs are generated and executed
Parsing Policies
Explore syscall number resolution and hook detection
Policy Composition
Master the art of composing policies for your use case