Skip to content

Commit

Permalink
elf: fixed .text not allocated at 0
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBotnik committed Oct 3, 2024
1 parent 2bec0d8 commit 54389e9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cle/backends/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,8 @@ def ___segments_overlap(seg1, seg2):
segment_relro.flags = overlapping_segments[0].flags & ~2

def __register_sections(self):
SECTIONS_NOT_TO_ALLOCATE = {"SHT_NOTE", "SHT_MIPS_REGINFO"}

new_addr = 0
sec_list = []

Expand All @@ -1214,7 +1216,8 @@ def __register_sections(self):
new_addr = (new_addr + (align - 1)) // align * align

remap_offset = new_addr - sh_addr
new_addr += sec_readelf.header["sh_size"] # address for next section
if sec_readelf.header["sh_type"] not in SECTIONS_NOT_TO_ALLOCATE:
new_addr += sec_readelf.header["sh_size"] # address for next section

section = ELFSection(sec_readelf, remap_offset=remap_offset)
sec_list.append((sec_readelf, section))
Expand All @@ -1241,7 +1244,7 @@ def __register_sections(self):
b"\0" * sec_readelf.header["sh_size"],
overwrite=True,
)
elif section.type == "SHT_NOTE":
elif section.type in SECTIONS_NOT_TO_ALLOCATE:
pass # observed this case in angr/angr#3829
else: # elif section.type == 'SHT_PROGBITS':
self.memory.add_backer(
Expand Down

0 comments on commit 54389e9

Please sign in to comment.