diff options
| author | Josh Ferrell <josh@vector35.com> | 2024-10-23 12:39:33 -0400 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2024-10-23 17:37:33 -0400 |
| commit | bd3d79d51267975a9ff2167bb6731222e9618c27 (patch) | |
| tree | 59c1b71e9958048ac2c77aaddfddc0f8a9b2bb93 /view/elf | |
| parent | 62e450721a5487402522a458e88a93d82e6d3d6f (diff) | |
Add API to bulk add segments, use it in elf view
Diffstat (limited to 'view/elf')
| -rw-r--r-- | view/elf/elfview.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
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<BNSegmentInfo> 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. |
