3.4 KiB
Test Payloads (tests/loader/src/)
Location: tests/loader/src/
These C source files are compiled into DLL and EXE payloads that the test runner feeds to the reflective loaders. Each payload is designed to validate a specific capability of the loading pipeline from basic FFI argument passing to TLS callback execution.
All DLL payloads export functions that return sentinel values (0xFEEDC0DE, 0x1337C0DE, etc.) to signal success or specific failure modes. The test runner validates these return values across architecture boundaries.
test_dll.c
The primary DLL test payload. Exercises three critical loader capabilities:
Exports
-
SayHello(s1, s2, n3): Validates that the FFI bridge correctly passes three arguments. Returns0xFEEDC0DEif the arguments exactly match("bonjour", "hello", 12), otherwise0xDEADBEEF. -
VerifyInit(): Validates two things simultaneously:- DllMain execution:
DllMain(DLL_PROCESS_ATTACH)writes0xA77AC4EDinto a global variable.VerifyInitreads it back. - Relocation correctness: The global lives in
.data. If relocations were not applied, the pointer reference will read garbage.
Returns
0xC001D00Don success. - DllMain execution:
test_dll_advanced.c
Exercises complex loader capabilities: multi-DLL imports, heap allocation, and dynamic loading.
Exports
AdvancedExport(input_str): CallsGetSystemInfo(kernel32), allocates heap memory viamalloc, copies the input string, dynamically loadsuser32.dllviaLoadLibraryA, and resolvesMessageBoxAviaGetProcAddress. Returns0x1337C0DEif all operations succeed with input"advanced_test".VerifyImports(): Stress-tests IAT resolution by calling a diverse set of kernel32 APIs (GetCurrentProcessId,GetCurrentThreadId,VirtualAlloc/Free,GetSystemTimeAsFileTime). Also verifiesDllMainwas called exactly once. Returns0xCA11AB1Eon success.
test_dll_empty.c
A completely empty DLL with no export or custom imports beyond what the compiler forces for DllMain. Tests that the loader gracefully handles a missing Export Directory without crashing. The test runner expects the loader to report "Error: Requested export was not found".
test_dll_tls.c
Registers a TLS callback via the .CRT$XLB section using #pragma section and __declspec(allocate). The callback writes a sentinel (0x7153CA11) into a global variable during DLL_PROCESS_ATTACH.
Exports
VerifyTLS(): Reads the sentinel back. Returns0x71500C01if the TLS callback fired,0x715FA110if it did not.
This validates that the reflective loader correctly parses IMAGE_TLS_DIRECTORY and iterates the callback array before invoking DllMain.
test_exe.c
A basic EXE payload that validates relocations and imports:
- Checks that a
.dataglobal (g_reloc_canary = 0xCAFEBABE) survived relocation. - Calls
GetCurrentProcessId()through the resolved IAT.
Exits with code 0x7A (122) on success.
test_exe_advanced.c
An advanced EXE payload that validates CRT initialization:
- Performs
memcpy,strlen,strcmpto verify the CRT was bootstrapped. - Calls
mallocandprintfto exercise heap and stdio. - Calls
GetCurrentProcessIdandGetCurrentThreadIdfor multi-API IAT verification.
Exits with code 0x1337 on success. The test runner matches "Successfully allocated and printed" in stdout.