upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index a59f9d0b1..f2c62ec91 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -65,7 +65,8 @@ uint64_t rva_in(const Module& m, uint64_t va, const char* what) {
65 65
66IMAGE_TLS_DIRECTORY64* tls_directory(Module& m) { 66IMAGE_TLS_DIRECTORY64* tls_directory(Module& m) {
67 auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew); 67 auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew);
68 const auto& dir = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS]; 68 // Through directory(), as every other directory: an entry past NumberOfRvaAndSizes is not a TLS directory.
69 const auto dir = directory(nt, IMAGE_DIRECTORY_ENTRY_TLS);
69 if (!dir.Size || !dir.VirtualAddress) return nullptr; 70 if (!dir.Size || !dir.VirtualAddress) return nullptr;
70 require_range(m.name, dir.VirtualAddress, sizeof(IMAGE_TLS_DIRECTORY64), m.size, "the TLS directory"); 71 require_range(m.name, dir.VirtualAddress, sizeof(IMAGE_TLS_DIRECTORY64), m.size, "the TLS directory");
71 return at<IMAGE_TLS_DIRECTORY64>(m.base, dir.VirtualAddress); 72 return at<IMAGE_TLS_DIRECTORY64>(m.base, dir.VirtualAddress);
@@ -696,7 +697,6 @@ void Loader::initialise(Module& m) {
696 // Only a DLL gets DllMain. An EXE's entry point has a different signature and is the caller's to run. 697 // Only a DLL gets DllMain. An EXE's entry point has a different signature and is the caller's to run.
697 auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew); 698 auto* nt = at<IMAGE_NT_HEADERS64>(m.base, reinterpret_cast<IMAGE_DOS_HEADER*>(m.base)->e_lfanew);
698 if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && m.entry_rva) { 699 if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && m.entry_rva) {
699 if (m.entry_rva >= m.size) throw std::runtime_error(m.name + ": the entry point is outside the image");
700 auto entry = reinterpret_cast<BOOL(NTAPI*)(void*, DWORD, void*)>(m.base + m.entry_rva); 700 auto entry = reinterpret_cast<BOOL(NTAPI*)(void*, DWORD, void*)>(m.base + m.entry_rva);
701 const BOOL ok = entry(m.base, DLL_PROCESS_ATTACH, nullptr); 701 const BOOL ok = entry(m.base, DLL_PROCESS_ATTACH, nullptr);
702 if (startup_trace::enabled()) 702 if (startup_trace::enabled())
@@ -741,6 +741,8 @@ Module& Loader::map_image(const std::filesystem::path& path) {
741 if (!oh.SizeOfImage || oh.SizeOfHeaders < headers_end || oh.SizeOfHeaders > oh.SizeOfImage || 741 if (!oh.SizeOfImage || oh.SizeOfHeaders < headers_end || oh.SizeOfHeaders > oh.SizeOfImage ||
742 oh.SizeOfHeaders > file.size()) 742 oh.SizeOfHeaders > file.size())
743 throw std::runtime_error(name + ": SizeOfHeaders and SizeOfImage don't fit the headers and file"); 743 throw std::runtime_error(name + ": SizeOfHeaders and SizeOfImage don't fit the headers and file");
744 if (oh.AddressOfEntryPoint && oh.AddressOfEntryPoint >= oh.SizeOfImage)
745 throw std::runtime_error(name + ": the entry point is outside the image");
744 746
745 auto* m = new Module; 747 auto* m = new Module;
746 m->name = name; 748 m->name = name;