diff options
| author | Ayinaki <ayinakidev@gmail.com> | 2026-11-21 19:40:33 +0000 |
|---|---|---|
| committer | Ayinaki <ayinakidev@gmail.com> | 2026-11-21 19:56:27 +0000 |
| commit | ff573ee55ecc402ca2a4242f3b9a43edbb146638 (patch) | |
| tree | 2d93c861dec8e30d685fb722ff7390711ad96c58 /runtime/src/pe_loader.h | |
| parent | 4c75ce537add406b426d0a1dc84d9a01fb4c86c9 (diff) | |
loader: follow forwarded exports and validate delay-import descriptors
parse_exports stored base + RVA for every export, but an export whose RVA lands inside the export
directory is a forwarder string ("KERNEL32.Sleep"), not code, so an import of one received a pointer
into the string. Forwarders are now recorded separately and followed when an import asks for one:
bundled modules first, then LoadLibraryEx/GetProcAddress for system DLLs, with a depth cap so two
modules re-exporting each other stop instead of recursing. An unresolvable forwarder records the
import as unimplemented.
The delay-import walk also assumed every descriptor is RVA-based and has a name table. A descriptor
without dlattrRva stores 32-bit virtual addresses, which cannot address an x64 image base, so it is
rejected with a message instead of being misread. A missing address table is rejected, and a missing
name table now reads its entries back through the address table.
Diffstat (limited to 'runtime/src/pe_loader.h')
| -rw-r--r-- | runtime/src/pe_loader.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/runtime/src/pe_loader.h b/runtime/src/pe_loader.h index e6e7c07c7..8d9e0a224 100644 --- a/runtime/src/pe_loader.h +++ b/runtime/src/pe_loader.h | |||
| @@ -35,7 +35,8 @@ struct Module { | |||
| 35 | bool has_tls_slot = false; | 35 | bool has_tls_slot = false; |
| 36 | bool initialised = false; | 36 | bool initialised = false; |
| 37 | std::vector<ImportRecord> imports; | 37 | std::vector<ImportRecord> imports; |
| 38 | std::map<std::string, void*> exports; // by name, plus "#ordinal" | 38 | std::map<std::string, void*> exports; // by name, plus "#ordinal" |
| 39 | std::map<std::string, std::string> forwarders; // same keys, holding "module.symbol" for re-exports | ||
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | class Loader { | 42 | class Loader { |
| @@ -58,6 +59,7 @@ private: | |||
| 58 | Module& map_image(const std::filesystem::path& path); | 59 | Module& map_image(const std::filesystem::path& path); |
| 59 | void bind_imports(Module& m); | 60 | void bind_imports(Module& m); |
| 60 | void* resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal); | 61 | void* resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal); |
| 62 | void* resolve_forwarder(const std::string& spec, Binding& binding, int depth); | ||
| 61 | void parse_exports(Module& m); | 63 | void parse_exports(Module& m); |
| 62 | void protect_sections(Module& m); | 64 | void protect_sections(Module& m); |
| 63 | 65 | ||