Overview
The power of syscalls-cpp lies in its extensibility through policy-based design. You can create custom policies to implement your own memory allocation strategies, stub generation techniques, or syscall number parsing methods. All policies are validated at compile-time using C++20 concepts, ensuring type safety and proper implementation.Policy Types
syscalls-cpp supports three types of policies:- Allocation Policies - Control how memory for syscall stubs is allocated
- Stub Generation Policies - Define how syscall stub code is generated
- Parsing Policies - Determine how syscall numbers are resolved from system modules
Allocation Policies
Concept Requirements
An allocation policy must satisfy theIsIAllocationPolicy concept:
Required Methods
allocate
uRegionSize- Size of memory region neededvecBuffer- Buffer containing the generated stub codepOutRegion- [out] Pointer to allocated executable memoryhOutHandle- [out] Handle to resource (if needed, otherwise unused)
true on success, false on failure
release
pRegion- Memory region to releasehHandle- Resource handle to close (if applicable)
Built-in Allocation Policies
allocator::section - SEC_NO_CHANGE Protection
allocator::section - SEC_NO_CHANGE Protection
Uses Source: include/syscalls-cpp/syscall.hpp:115-165
NtCreateSection with the SEC_NO_CHANGE flag to create immutable executable memory that cannot be modified, even by the allocating process.allocator::heap - Executable Heap
allocator::heap - Executable Heap
Creates a private executable heap using Source: include/syscalls-cpp/syscall.hpp:167-209
RtlCreateHeap with the HEAP_CREATE_ENABLE_EXECUTE flag.allocator::memory - Virtual Memory
allocator::memory - Virtual Memory
Uses Source: include/syscalls-cpp/syscall.hpp:211-259
NtAllocateVirtualMemory to allocate memory with page protection transition (RW → RX).Stub Generation Policies
Concept Requirements
A stub generation policy must satisfy theIsStubGenerationPolicy concept:
Required Members
bRequiresGadget
syscall; ret sequences) to be found in ntdll.dll.
getStubSize
generate
pBuffer- Buffer to write the stub code intouSyscallNumber- The syscall number to embed in the stubpGadgetAddress- Address of a syscall gadget (ifbRequiresGadgetis true)
Built-in Stub Generation Policies
generator::direct - Self-Contained Syscall
generator::direct - Self-Contained Syscall
Generates a complete, self-contained stub with an inline Source: include/syscalls-cpp/syscall.hpp:309-341
syscall instruction.x64 Shellcode:generator::gadget - Indirect Syscall (x64 only)
generator::gadget - Indirect Syscall (x64 only)
Uses a jump to a Source: include/syscalls-cpp/syscall.hpp:264-292
syscall; ret gadget found in ntdll.dll, avoiding direct syscall instructions in allocated memory.generator::exception - VEH-Based Syscall
generator::exception - VEH-Based Syscall
Triggers an illegal instruction exception (The actual syscall is performed by the VEH handler, which modifies the exception context.Source: include/syscalls-cpp/syscall.hpp:296-307
ud2) to invoke the syscall through a Vectored Exception Handler.Custom Stub Generation Example
Here’s a real-world example of a custom stub generator that encrypts syscall numbers with multiple obfuscation layers:Using the Custom Generator
Parsing Policies
Concept Requirements
A parsing policy must satisfy theIsSyscallParsingPolicy concept:
Required Method
module- Module information structure containing PE headers and export directory
SyscallEntry_t containing syscall names (hashed), numbers, and offsets
Built-in Parsing Policies
parser::directory - Exception/Export Directory
parser::directory - Exception/Export Directory
On x64, uses the exception directory (.pdata) to determine syscall order. On x86, sorts exported Zw* functions by address.x64 Approach:Source: include/syscalls-cpp/syscall.hpp:346-453
parser::signature - Prologue Scanning
parser::signature - Prologue Scanning
Scans function prologues for the syscall number signature and includes hook detection with neighbor scanning.x64 Signature: Source: include/syscalls-cpp/syscall.hpp:455-599
4C 8B D1 B8 [syscall_number]Parser Chains
You can combine multiple parsing policies into a fallback chain:Compile-Time Validation
All policies are validated at compile-time with helpful error messages:Next Steps
Basic Usage
Return to basic usage patterns and common examples
Debugging
Learn how to debug custom policies and troubleshoot issues