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.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index 2d691862d..ef6fab7a8 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -314,6 +314,17 @@ Module& Loader::map_image(const std::filesystem::path& path) {
314 require_range(m->name, static_cast<uint64_t>(block->VirtualAddress) + off, sizeof(uint64_t), m->size, 314 require_range(m->name, static_cast<uint64_t>(block->VirtualAddress) + off, sizeof(uint64_t), m->size,
315 "a relocation"); 315 "a relocation");
316 *at<uint64_t>(m->base, block->VirtualAddress + off) += delta; 316 *at<uint64_t>(m->base, block->VirtualAddress + off) += delta;
317 } else if (type == IMAGE_REL_BASED_HIGHLOW) {
318 // A 32-bit absolute address (code built /LARGEADDRESSAWARE:NO), which the x64 Windows loader
319 // also applies. Where the new address no longer fits in 32 bits, Windows would truncate it; the
320 // image would then jump or read through a wrong pointer, so the load is refused instead.
321 require_range(m->name, static_cast<uint64_t>(block->VirtualAddress) + off, sizeof(uint32_t),
322 m->size, "a relocation");
323 auto* slot = at<uint32_t>(m->base, block->VirtualAddress + off);
324 const int64_t moved = static_cast<int64_t>(*slot) + delta;
325 if (moved < 0 || moved > 0xFFFFFFFFll)
326 throw std::runtime_error(m->name + ": a 32-bit (HIGHLOW) relocation does not fit at this base");
327 *slot = static_cast<uint32_t>(moved);
317 } else if (type != IMAGE_REL_BASED_ABSOLUTE) { 328 } else if (type != IMAGE_REL_BASED_ABSOLUTE) {
318 throw std::runtime_error(m->name + ": unsupported relocation type " + std::to_string(type)); 329 throw std::runtime_error(m->name + ": unsupported relocation type " + std::to_string(type));
319 } 330 }