diff options
| author | Dea7hsmiles <188018312+dea7hsmiless@users.noreply.github.com> | 2026-11-21 13:46:21 -0800 |
|---|---|---|
| committer | Dea7hsmiles <188018312+dea7hsmiless@users.noreply.github.com> | 2026-11-21 15:51:43 -0800 |
| commit | f6b3d3a24c533d213178c9a927014abe1fadfc1f (patch) | |
| tree | 7b917dbb0e351085b6eb56568f12cae2748c3d2f /runtime/test/loader_test.cpp | |
| parent | 4abd54571b6efa02d97eda4711792fa00b455dc3 (diff) | |
Loader: reject a delay-import descriptor with no name table
An IAT without an INT still holds delay thunks, not name RVAs, so eager binding has no symbol to resolve. Reject the form with a clear error. A scan of the installed x64 System32 tree found 4,620 DLLs and 17,558 delay descriptors, none with a missing INT or without dlattrRva. The test now expects the rejection.
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 18 |
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 | ||