mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:48:39 +00:00
Images the loader maps by hand are unknown to the system unwinder, so an exception raised in or passing through one couldn't be dispatched and killed the process. load() now validates the exception directory (entries in bounds, sorted, non-overlapping; zero-length entries allowed, as in System32's symcryptk.dll) and registers it; the loader removes it before freeing the image. Rules measured over 3,780 x64 System32 images (5,023,071 entries) and the 16 package DLLs. Tests: loader_test covers registration, removal and six corrupt tables on hand-built images; pe_loader_test checks a fixture SEH fault is caught by the image's own handler (fails without registration) and, with LEONIDA_GAME_DIR, every package DLL's table. AI-assisted.
38 lines
1.6 KiB
C++
38 lines
1.6 KiB
C++
// Tiny fixture DLL for the rt::Loader tests. It is ordinary test code, not game content.
|
|
//
|
|
// The imports must stay non-empty: tiny_add calls GetCurrentProcessId and records the result, and the test calls
|
|
// tiny_last_pid to prove the IAT entry really points at the host function. The string literal below gives the image
|
|
// a .rdata section, and tiny_text_ptr is initialised with its address so the image also contains a DIR64 base
|
|
// relocation that the test can verify after forcing a relocated mapping. tiny_fault_caught gives it a .pdata entry
|
|
// with an exception handler, for the unwind-registration test.
|
|
#include <windows.h>
|
|
|
|
namespace {
|
|
|
|
const char kTinyText[] = "leonida tiny fixture";
|
|
DWORD g_last_pid = 0;
|
|
|
|
} // namespace
|
|
|
|
extern "C" __declspec(dllexport) int __cdecl tiny_add(int a, int b) {
|
|
g_last_pid = GetCurrentProcessId();
|
|
return a + b;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport) unsigned long __cdecl tiny_last_pid() { return g_last_pid; }
|
|
|
|
// Reads through p inside a structured-exception block. Given a null pointer it faults, and returns -1 only if the
|
|
// dispatcher can find this function's unwind info and handler: that needs the loader to register the image's .pdata.
|
|
extern "C" __declspec(dllexport) int __cdecl tiny_fault_caught(const volatile int* p) {
|
|
__try {
|
|
return *p;
|
|
} __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
|
|
: EXCEPTION_CONTINUE_SEARCH) {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
extern "C" __declspec(dllexport) int tiny_exported_value = 1234;
|
|
|
|
extern "C" __declspec(dllexport) const char* tiny_text_ptr = kTinyText;
|