From 4edbacc27800be28f890985898a29213da5a9135 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Sat, 5 Jul 2025 08:54:22 -0400 Subject: Fix ELF loader image base calculation to include memory-only PT_LOAD segments. --- view/elf/elfview.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'view/elf/elfview.cpp') diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp index d7dc1203..536e016e 100644 --- a/view/elf/elfview.cpp +++ b/view/elf/elfview.cpp @@ -451,16 +451,15 @@ bool ElfView::Init() bool initialImageBaseSet = false; for (const auto& i : m_programHeaders) { - if ((i.type != ELF_PT_LOAD) || (!i.fileSize)) + // Skip segments that are not loadable or have no memory size + if ((i.type != ELF_PT_LOAD) || (i.memorySize == 0)) continue; - if (!initialImageBaseSet) + if (!initialImageBaseSet || (i.virtualAddress < initialImageBase)) { initialImageBase = i.virtualAddress; initialImageBaseSet = true; } - else if (i.virtualAddress < initialImageBase) - initialImageBase = i.virtualAddress; } SetOriginalImageBase(initialImageBase); -- cgit v1.3.1