Skip to content

Commit ec0e8bc

Browse files
committed
ElfBuilder: Support adding writeable code section
1 parent df9db60 commit ec0e8bc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

simpleelf/elf_builder.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ def add_section(self, type_, address, size, name, flags):
9999
self._e_shnum += 1
100100
self._sections.append(section)
101101

102-
def add_code_section(self, name, address, size):
103-
self.add_section(self._structs.Elf_SectionType.SHT_PROGBITS, address,
104-
size,
105-
name, elf_consts.SHF_ALLOC | elf_consts.SHF_EXECINSTR)
102+
def add_code_section(self, name: str, address: int, size: int, writeable: bool = False):
103+
flags = elf_consts.SHF_ALLOC | elf_consts.SHF_EXECINSTR
104+
if writeable:
105+
flags |= elf_consts.SHF_WRITE
106+
self.add_section(self._structs.Elf_SectionType.SHT_PROGBITS, address, size, name, flags)
106107

107108
def add_empty_data_section(self, name, address, size):
108109
self.add_section(self._structs.Elf_SectionType.SHT_NOBITS, address,

0 commit comments

Comments
 (0)