Skip to content

Commit 23cd212

Browse files
committed
Added check for sharedobject without program header section start address.
1 parent 768f7c7 commit 23cd212

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

view/elf/elfview.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ bool ElfView::Init()
474474
{
475475
if (settings->Contains("loader.imageBase"))
476476
preferredImageBase = settings->Get<uint64_t>("loader.imageBase", this);
477-
477+
478478
if (settings->Contains("loader.platform"))
479479
{
480480
BNSettingsScope scope = SettingsAutoScope;
@@ -658,11 +658,10 @@ bool ElfView::Init()
658658
semantics = ReadOnlyDataSectionSemantics;
659659
else if ((m_elfSections[i].flags & ELF_SHF_WRITE) || In(sectionNames[i], readWriteDataSectionNames))
660660
semantics = ReadWriteDataSectionSemantics;
661-
662661
if (m_elfSections[i].size != 0)
663662
{
664663
if (m_programHeaders.size() == 0)
665-
{
664+
{
666665
// We have an object file so we'll just create segments for the sections
667666
uint32_t flags = 0;
668667
if (semantics == ReadOnlyCodeSectionSemantics)
@@ -671,11 +670,22 @@ bool ElfView::Init()
671670
flags = SegmentReadable | SegmentWritable;
672671
else if (semantics == ReadOnlyDataSectionSemantics)
673672
flags = SegmentReadable;
674-
m_elfSections[i].address = segmentStart;
675-
size_t size = m_elfSections[i].type == ELF_SHT_NOBITS ? 0 : m_elfSections[i].size;
676-
uint64_t adjustedSectionAddr = m_elfSections[i].address + imageBaseAdjustment;
677-
AddAutoSegment(adjustedSectionAddr, m_elfSections[i].size, m_elfSections[i].offset, size, flags);
678-
segmentStart += ((m_elfSections[i].size + 15) & ~15);
673+
if ((m_commonHeader.type == ET_DYN) && (!m_parseOnly))
674+
{
675+
// We have a shared object file without program headers so we'll create segments for the sections
676+
// based on the section address.
677+
size_t size = m_elfSections[i].type == ELF_SHT_NOBITS ? 0 : m_elfSections[i].size;
678+
uint64_t adjustedSectionAddr = m_elfSections[i].address + imageBaseAdjustment;
679+
AddAutoSegment(adjustedSectionAddr, m_elfSections[i].size, m_elfSections[i].offset, size, flags);
680+
}
681+
else
682+
{
683+
m_elfSections[i].address = segmentStart;
684+
size_t size = m_elfSections[i].type == ELF_SHT_NOBITS ? 0 : m_elfSections[i].size;
685+
uint64_t adjustedSectionAddr = m_elfSections[i].address + imageBaseAdjustment;
686+
AddAutoSegment(adjustedSectionAddr, m_elfSections[i].size, m_elfSections[i].offset, size, flags);
687+
segmentStart += ((m_elfSections[i].size + 15) & ~15);
688+
}
679689
}
680690
else if ((m_elfSections[i].address + m_elfSections[i].size + imageBaseAdjustment) > GetEnd() || ((m_elfSections[i].address + imageBaseAdjustment) < GetStart()))
681691
{
@@ -690,7 +700,6 @@ bool ElfView::Init()
690700
GetParentView()->AddAutoSection(sectionNames[i], m_elfSections[i].offset, m_elfSections[i].size, DefaultSectionSemantics, type, m_elfSections[i].align, m_elfSections[i].entrySize, linkedSection, infoSection, m_elfSections[i].info);
691701
}
692702
}
693-
694703
// Apply architecture and platform
695704
if (!m_arch)
696705
{

0 commit comments

Comments
 (0)