Overview
Thegenerator::direct policy generates inline syscall stubs that execute system calls directly without using syscall; ret gadgets or exception handlers. This is the most straightforward approach and works on both x64 and x86 platforms.
How It Works
The direct generator creates a small assembly stub for each syscall that:- Moves the first argument from
rcxtor10(x64 calling convention) - Loads the syscall number into
eax - Executes the
syscallinstruction - Returns to the caller
Generated Shellcode (x64)
Complete Example
Here’s a complete example fromexamples/basic-usage.cpp that allocates virtual memory using direct syscalls:
Key Components
Allocator Policy
The example usesallocator::section which creates executable memory using NtCreateSection and maps it with execute permissions. Other options include:
allocator::heap- Uses RtlCreateHeap with HEAP_CREATE_ENABLE_EXECUTEallocator::memory- Uses NtAllocateVirtualMemory directly
Generator Policy
Thegenerator::direct policy has these characteristics:
- bRequiresGadget:
false- No need to search for gadgets - getStubSize(): Returns 18 bytes (x64) or 15 bytes (x86)
- generate(): Copies the shellcode template and patches in the syscall number
Syscall Invocation
TheSYSCALL_ID macro computes a compile-time hash of the function name:
Benefits
Performance
Performance
Direct syscalls have minimal overhead - just the syscall instruction itself with no indirection through gadgets or exception handlers.
Simplicity
Simplicity
The implementation is straightforward and easy to understand. No complex gadget searching or exception handling setup.
Cross-Platform
Cross-Platform
Works on both x64 and x86 Windows platforms with appropriate shellcode for each architecture.
Reliability
Reliability
No dependencies on finding specific byte patterns in ntdll.dll or setting up exception handlers.
Use Cases
- General Purpose: Best default choice for most applications
- Performance Critical: When you need the fastest syscall execution
- Simple Projects: When you don’t need advanced evasion techniques
- Legacy Support: Works on both modern and older Windows versions
Limitations
Expected Behavior
When you run the example:See Also
- Gadget Syscalls - Using syscall; ret gadgets
- Exception Syscalls - VEH-based approach
- Custom Generators - Build your own generator