From bd3d79d51267975a9ff2167bb6731222e9618c27 Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Wed, 23 Oct 2024 12:39:33 -0400 Subject: Add API to bulk add segments, use it in elf view --- view/elf/elfview.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'view/elf/elfview.cpp') diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp index 4edb2ca7..8be478f1 100644 --- a/view/elf/elfview.cpp +++ b/view/elf/elfview.cpp @@ -496,21 +496,37 @@ bool ElfView::Init() m_entryPoint = m_entryPoint + imageBaseAdjustment; - for (auto& i : m_programHeaders) + // Add segments in bulk first { - uint64_t adjustedVirtualAddr = i.virtualAddress + imageBaseAdjustment; - - if (i.type == ELF_PT_LOAD) // || i.type == ELF_PT_GNU_RELRO) + vector segmentsToAdd; + for (auto& i : m_programHeaders) { - uint32_t flags = 0; - if (i.flags & 1) - flags |= SegmentExecutable; - if (i.flags & 2) - flags |= SegmentWritable; - if (i.flags & 4) - flags |= SegmentReadable; - AddAutoSegment(adjustedVirtualAddr, i.memorySize, i.offset, i.fileSize, flags); + uint64_t adjustedVirtualAddr = i.virtualAddress + imageBaseAdjustment; + if (i.type == ELF_PT_LOAD) // || i.type == ELF_PT_GNU_RELRO) + { + uint32_t flags = 0; + if (i.flags & 1) + flags |= SegmentExecutable; + if (i.flags & 2) + flags |= SegmentWritable; + if (i.flags & 4) + flags |= SegmentReadable; + + BNSegmentInfo segmentInfo; + segmentInfo.start = adjustedVirtualAddr; + segmentInfo.length = i.memorySize; + segmentInfo.dataOffset = i.offset; + segmentInfo.dataLength = i.fileSize; + segmentInfo.flags = flags; + segmentsToAdd.push_back(segmentInfo); + } } + AddAutoSegments(segmentsToAdd); + } + + for (auto& i : m_programHeaders) + { + uint64_t adjustedVirtualAddr = i.virtualAddress + imageBaseAdjustment; // Create sections for the program headers with the standard section names. This will ensure that // the standard name for sections such as .dynamic will always refer to what the loader actually uses. -- cgit v1.3.1