Overview
Adding new APIs involves four main steps:- Add the API to the instance struct in
include/common.h - Use the
D_APImacro to declare the API - Resolve the module base in the constructor
- Use the
RESOLVE_IMPORTmacro to resolve all APIs
Step-by-Step Guide
1. Add to Instance Struct
First, editinclude/common.h and add a new struct for your module inside the instance class. For example, to add user32.dll with MessageBoxA:
include/common.h
2. Understanding the Macros
Stardust uses several macros to simplify API resolution:D_API Macro
TheD_API macro declares a function pointer:
include/macros.h
RESOLVE_TYPE Macro
TheRESOLVE_TYPE macro stores the compile-time hash of the function name:
include/resolve.h
3. Resolve Module Base
Insrc/main.cc, update the instance::instance() constructor to resolve your module:
src/main.cc
4. Understanding RESOLVE_IMPORT
TheRESOLVE_IMPORT macro automatically resolves all APIs in a module struct:
include/macros.h
- Iterates through all members of the struct
- Takes the stored hash value
- Calls
resolve::_api()to find the function address - Replaces the hash with the actual function pointer
Complete Example: Adding MessageBoxA
Here’s a complete example showing howuser32.MessageBoxA is added:
common.h (lines 40-79)
main.cc Constructor (lines 26-39)
Using the API (lines 59-61)
Loading Modules at Runtime
If a module isn’t loaded in the PEB, you can load it dynamically:Best Practices
Multiple APIs from Same Module
You can add multiple APIs from the same module:Error Handling
Always check if module resolution succeeded:Compile-Time Hashing
All string hashing happens at compile time usingexpr::hash_string, which means:
- No function names in the final shellcode
- Smaller binary size
- Better evasion characteristics
Troubleshooting
API Not Resolving
If your API isn’t resolving:- Verify the module is loaded: Check with
resolve::module() - Check API name spelling: Must match exactly
- Ensure API is exported: Use
dumpbin /exportson the DLL - Debug with
DBG_PRINTF: See Debugging Guide
Compilation Errors
Common compilation errors:- “undeclared identifier”: Add Windows headers or forward declare
- “conflicting types”: Check function signature matches Windows API
- “struct count mismatch”: Ensure
RESOLVE_TYPEcount matchesD_APIcount
