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.cpp18
1 files changed, 2 insertions, 16 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp
index 901afcb49..739db66cf 100644
--- a/runtime/test/loader_test.cpp
+++ b/runtime/test/loader_test.cpp
@@ -637,7 +637,7 @@ void test_delay_descriptor_fields() {
637 expect_rejects("a delay-import descriptor without the RVA attribute", img); 637 expect_rejects("a delay-import descriptor without the RVA attribute", img);
638 } 638 }
639 { 639 {
640 const char* what = "a delay import with no name table binds through its address table"; 640 // Without a name table the IAT still holds delay thunks, not import names, so there is no symbol to bind.
641 auto img = make_image(); 641 auto img = make_image();
642 std::fill(img.begin() + 0x200, img.begin() + 0x400, uint8_t{0}); 642 std::fill(img.begin() + 0x200, img.begin() + 0x400, uint8_t{0});
643 auto* d = reinterpret_cast<IMAGE_DELAYLOAD_DESCRIPTOR*>(img.data() + 0x200); 643 auto* d = reinterpret_cast<IMAGE_DELAYLOAD_DESCRIPTOR*>(img.data() + 0x200);
@@ -646,24 +646,10 @@ void test_delay_descriptor_fields() {
646 d->ImportNameTableRVA = 0; 646 d->ImportNameTableRVA = 0;
647 d->ImportAddressTableRVA = 0x1180; 647 d->ImportAddressTableRVA = 0x1180;
648 std::memcpy(img.data() + 0x260, "kernel32.dll\0", 13); 648 std::memcpy(img.data() + 0x260, "kernel32.dll\0", 13);
649 *reinterpret_cast<uint64_t*>(img.data() + 0x380) = 0x1120; // RVA 0x1180: the single hint/name entry
650 *reinterpret_cast<uint16_t*>(img.data() + 0x320) = 0;
651 std::memcpy(img.data() + 0x322, "GetCurrentProcessId\0", 20);
652 auto& dir = nt_of(img)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT]; 649 auto& dir = nt_of(img)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT];
653 dir.VirtualAddress = 0x1000; 650 dir.VirtualAddress = 0x1000;
654 dir.Size = sizeof(IMAGE_DELAYLOAD_DESCRIPTOR); 651 dir.Size = sizeof(IMAGE_DELAYLOAD_DESCRIPTOR);
655 try { 652 expect_rejects("a delay-import descriptor without a name table", img);
656 rt::Loader loader(g_dir);
657 rt::Module& m = loader.load(write_image_as(img, "delay.exe"));
658 void* expected = host_symbol("kernel32.dll", "GetCurrentProcessId");
659 if (m.imports.size() != 1) return failed(what, "expected one bound import");
660 if (m.imports[0].binding != rt::Binding::Host) return failed(what, "the delay import did not bind to the host");
661 if (*reinterpret_cast<void**>(m.base + 0x1180) != expected)
662 return failed(what, "the address table does not hold the host function");
663 pass(what);
664 } catch (const std::exception& e) {
665 failed(what, e.what());
666 }
667 } 653 }
668} 654}
669 655