Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/writeable code section #4

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions simpleelf/elf_builder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections import namedtuple

from construct import Padding
from simpleelf.elf_consts import ELFCLASS32

from simpleelf.elf_structs import ElfStructs
from simpleelf import elf_consts
from simpleelf.elf_consts import ELFCLASS32
from simpleelf.elf_structs import ElfStructs


class ElfBuilder:
Expand Down Expand Up @@ -99,10 +98,11 @@ def add_section(self, type_, address, size, name, flags):
self._e_shnum += 1
self._sections.append(section)

def add_code_section(self, name, address, size):
self.add_section(self._structs.Elf_SectionType.SHT_PROGBITS, address,
size,
name, elf_consts.SHF_ALLOC | elf_consts.SHF_EXECINSTR)
def add_code_section(self, name: str, address: int, size: int, writeable: bool = False):
flags = elf_consts.SHF_ALLOC | elf_consts.SHF_EXECINSTR
if writeable:
flags |= elf_consts.SHF_WRITE
self.add_section(self._structs.Elf_SectionType.SHT_PROGBITS, address, size, name, flags)

def add_empty_data_section(self, name, address, size):
self.add_section(self._structs.Elf_SectionType.SHT_NOBITS, address,
Expand Down