Method Signature
Description
Initializes the syscall manager by parsing syscall numbers from specified Windows modules and generating syscall stubs. This method must be called before invoking any syscalls, thoughinvoke() will automatically call it if not already initialized.
Parameters
A vector of module identifiers to parse for syscalls. Each module key should be created using the
SYSCALL_ID macro.Default behavior: Parses syscalls from ntdll.dll only.Type notes:- With
SYSCALLS_NO_HASHdefined:SyscallKey_tisstd::string - Without
SYSCALLS_NO_HASH:SyscallKey_tishashing::Hash_t(compile-time hash)
Return Value
Returns
true if initialization succeeds, false otherwise.Success conditions:- At least one module is successfully loaded
- At least one syscall is successfully parsed
- Syscall stubs are successfully generated
- Memory allocation succeeds
- Exception handler registration succeeds (if using exception policy)
- All specified modules fail to load
- No syscalls are parsed from any module
- Memory allocation fails
- Syscall gadgets not found (when using gadget-based policies on Windows x64)
- Exception handler registration fails (when using exception policy)
Behavior Details
Idempotency
The method is idempotent - if already initialized, it returnstrue immediately without re-initializing:
Initialization Process
-
Gadget Search (Windows x64, if
StubPolicy::bRequiresGadgetis true)- Searches the
.textsection ofntdll.dllfor syscall gadgets (0x0F 0x05 0xC3) - Returns
falseif no gadgets are found
- Searches the
-
Module Parsing
- Iterates through each module key in
vecModuleKeys - Loads module information (base address, PE headers, export directory)
- Attempts to parse syscalls using the parser chain (primary parser, then fallback parsers)
- Continues to next module if current module fails to load
- Iterates through each module key in
-
Syscall Randomization
- Randomizes the order of parsed syscalls using Fisher-Yates shuffle with
rdtscp()for entropy - Assigns offsets to each syscall based on stub size
- Randomizes the order of parsed syscalls using Fisher-Yates shuffle with
-
Syscall Sorting
- Sorts syscalls by key for efficient binary search during invocation
-
Stub Generation
- Allocates temporary buffer for all stubs
- Generates individual syscall stubs based on
StubPolicy - Assigns random gadgets to each stub (if applicable)
-
Memory Allocation
- Allocates executable memory using
AllocPolicy - Copies generated stubs to allocated region
- Allocates executable memory using
-
Exception Handler Setup (if using
policies::generator::exception)- Registers vectored exception handler
- Returns
falseif registration fails
Thread Safety
The method is thread-safe:initialize() concurrently. The first thread to acquire the lock will perform initialization, and subsequent calls (even those waiting on the lock) will return true immediately due to the double-checked locking pattern.
Examples
Basic Initialization
Multi-Module Initialization
Explicit Initialization with Error Handling
Lazy Initialization
Platform-Specific Notes
Windows x64
When using gadget-based stub policies (policies::generator::gadget or policies::generator::exception):
- Automatically searches for syscall gadgets in
ntdll.dll - Initialization fails if no gadgets are found
- Uses
rdtscp()instruction for secure randomization
Windows x86
When using exception policy:- Uses
__readfsdword(0xC0)for gadget address (KiFastSystemCall) - No gadget search required
Performance Considerations
- Initialization involves parsing PE headers and export tables, which can be relatively expensive
- Consider calling
initialize()during application startup rather than on first syscall - Once initialized, the manager can be reused for the lifetime of the application
- The randomization and sorting steps add minimal overhead during initialization
See Also
- Manager Overview - Complete Manager class documentation
- Manager Invocation - Details on the
invoke()method - SYSCALL_ID Macro - How to create syscall identifiers