upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/loader_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/loader_test.cpp')
-rw-r--r--runtime/test/loader_test.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp
index 194174b00..d5248bd06 100644
--- a/runtime/test/loader_test.cpp
+++ b/runtime/test/loader_test.cpp
@@ -397,6 +397,42 @@ void test_imports() {
397 } 397 }
398} 398}
399 399
400void test_import_name_rvas() {
401 for (bool delay : {false, true}) {
402 auto img = make_import_image("testshim.dll", "F");
403 if (delay) {
404 std::fill(img.begin() + 0x200, img.begin() + 0x240, uint8_t{0});
405 auto* d = reinterpret_cast<IMAGE_DELAYLOAD_DESCRIPTOR*>(img.data() + 0x200);
406 d->Attributes.AllAttributes = 1;
407 d->DllNameRVA = 0x1060;
408 d->ImportNameTableRVA = 0x1100;
409 d->ImportAddressTableRVA = 0x1180;
410 auto* nt = nt_of(img);
411 nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] = {};
412 auto& dir = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT];
413 dir.VirtualAddress = 0x1000;
414 dir.Size = 2 * sizeof(IMAGE_DELAYLOAD_DESCRIPTOR);
415 }
416 const char* valid = delay ? "a valid delay-import name RVA loads" : "a valid import name RVA loads";
417 std::string error;
418 if (load(write_image(img), error) != 0)
419 failed(valid, error);
420 else
421 pass(valid);
422
423 *reinterpret_cast<uint64_t*>(img.data() + 0x300) = (1ull << 32) | 0x1120;
424 const char* invalid = delay ? "a delay-import name RVA with high bits is rejected"
425 : "an import name RVA with high bits is rejected";
426 error.clear();
427 if (load(write_image(img), error) == 0)
428 failed(invalid, "the image loaded");
429 else if (error.find("an import name runs past the image") == std::string::npos)
430 failed(invalid, error);
431 else
432 pass(invalid);
433 }
434}
435
400void test_delay_imports() { 436void test_delay_imports() {
401 { 437 {
402 auto img = make_image(); 438 auto img = make_image();
@@ -1099,6 +1135,7 @@ int main() {
1099 test_relocations(); 1135 test_relocations();
1100 test_exports(); 1136 test_exports();
1101 test_imports(); 1137 test_imports();
1138 test_import_name_rvas();
1102 test_delay_imports(); 1139 test_delay_imports();
1103 test_initialise(); 1140 test_initialise();
1104 test_initialise_rejects(); 1141 test_initialise_rejects();