pip install pyelftools
python
from elftools.elf.elffile import ELFFile
python
with open('executable_file', 'rb') as f:
elf_file = ELFFile(f)
python
code_section = elf_file.get_section_by_name('.text')
data_section = elf_file.get_section_by_name('.data')
symtab_section = elf_file.get_section_by_name('.symtab')
for symbol in symtab_section.iter_symbols():
print(symbol.name)
python
new_code_section = elf_file.add_section(ELFSection('.new_code', ''))
new_code_section.data = b'\x90\x90\x90\x90'
code_section.data = b'\x90\x90\x90\x90\x90'
with open('modified_executable_file', 'wb') as f:
f.write(elf_file.get_data())