Skip to content

Commit 4edbacc

Browse files
committed
Fix ELF loader image base calculation to include memory-only PT_LOAD segments.
1 parent b4d4a66 commit 4edbacc

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

view/elf/elfview.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,15 @@ bool ElfView::Init()
451451
bool initialImageBaseSet = false;
452452
for (const auto& i : m_programHeaders)
453453
{
454-
if ((i.type != ELF_PT_LOAD) || (!i.fileSize))
454+
// Skip segments that are not loadable or have no memory size
455+
if ((i.type != ELF_PT_LOAD) || (i.memorySize == 0))
455456
continue;
456457

457-
if (!initialImageBaseSet)
458+
if (!initialImageBaseSet || (i.virtualAddress < initialImageBase))
458459
{
459460
initialImageBase = i.virtualAddress;
460461
initialImageBaseSet = true;
461462
}
462-
else if (i.virtualAddress < initialImageBase)
463-
initialImageBase = i.virtualAddress;
464463
}
465464

466465
SetOriginalImageBase(initialImageBase);

0 commit comments

Comments
 (0)