resolve namespace provides functions for dynamically resolving Windows modules and exported functions using FNV-1a hash-based lookups. This enables position-independent shellcode to locate and call Windows APIs without hardcoded addresses.
resolve::module()
Searches for a loaded module’s base address by its FNV-1a name hash.FNV-1a hash of the library name (case-insensitive). Pass
0 to retrieve the base address of the first module in load order.Base address of the module if found, otherwise
0.Implementation Details
- Iterates through the
InLoadOrderModuleListlinked list in the Process Environment Block (PEB) - Compares the hash of each module’s
BaseDllNameagainst the provided hash - Uses case-insensitive hashing to match module names
- Returns the first matching module’s
DllBase
Example Usage
Module names must be hashed as wide-character strings (
wchar_t) since Windows stores module names in Unicode format in the PEB.resolve::api()
Resolves a function export from a module using hash-based lookup with automatic type casting.Base address of the module to resolve the function from (obtained via
resolve::module()).FNV-1a hash of the export symbol name (case-insensitive).
Function signature type for automatic casting of the returned pointer.
Typed function pointer cast to the specified template type, or
nullptr if not found.Example Usage
resolve::_api()
Internal implementation function that performs the actual symbol resolution by parsing PE export tables.Base address of the PE module.
FNV-1a hash of the symbol name to locate.
Address of the resolved function, or
0 if not found or if the PE headers are invalid.Implementation Algorithm
- Validate DOS Header - Checks for
IMAGE_DOS_SIGNATURE(“MZ”) - Validate NT Header - Verifies
IMAGE_NT_SIGNATURE(“PE\0\0”) - Locate Export Directory - Retrieves the export table from the PE Optional Header
- Parse Export Tables - Reads:
AddressOfNames- Array of export name RVAsAddressOfFunctions- Array of function RVAsAddressOfNameOrdinals- Array mapping names to function indices
- Hash Comparison - Iterates through exported names, hashing each and comparing against
symbol_hash - Address Calculation - On match, resolves the final function address using the ordinal mapping
Low-Level Details
Helper Macros
RESOLVE_API()
Convenience macro that combines compile-time hashing with typed API resolution.m- Module base addresss- Function name (unquoted symbol)
RESOLVE_TYPE()
Macro for initializing structure members with hashed values for batch resolution.See the macros documentation for more details on batch API resolution patterns.
