Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lief.ELF.SECTION_TYPES.ARM_PREEMPTMAP : "ARM_PREEMPTMAP",
lief.ELF.SECTION_TYPES.DYNAMIC : "DYNAMIC",
lief.ELF.SECTION_TYPES.DYNSYM : "DYNSYM",
lief.ELF.SECTION_TYPES.FINI_ARRAY : "FINI_ARRAY",
lief.ELF.SECTION_TYPES.GNU_ATTRIBUTES : "GNU_ATTRIBUTES",
lief.ELF.SECTION_TYPES.GNU_HASH : "GNU_HASH",
lief.ELF.SECTION_TYPES.GNU_VERDEF : "GNU_VERDEF",
lief.ELF.SECTION_TYPES.GNU_VERNEED : "GNU_VERNEED",
lief.ELF.SECTION_TYPES.GNU_VERSYM : "GNU_VERSYM",
lief.ELF.SECTION_TYPES.GROUP : "GROUP",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.PREINIT_ARRAY : "PREINIT_ARRAY",
lief.ELF.SECTION_TYPES.PROGBITS : "PROGBITS",
lief.ELF.SECTION_TYPES.REL : "REL",
lief.ELF.SECTION_TYPES.RELA : "RELA",
lief.ELF.SECTION_TYPES.SHLIB : "SHLIB",
lief.ELF.SECTION_TYPES.STRTAB : "STRTAB",
lief.ELF.SECTION_TYPES.SYMTAB : "SYMTAB",
lief.ELF.SECTION_TYPES.SYMTAB_SHNDX : "SYMTAB_SHNDX",
}
lief.ELF.SECTION_TYPES.DYNSYM : "DYNSYM",
lief.ELF.SECTION_TYPES.FINI_ARRAY : "FINI_ARRAY",
lief.ELF.SECTION_TYPES.GNU_ATTRIBUTES : "GNU_ATTRIBUTES",
lief.ELF.SECTION_TYPES.GNU_HASH : "GNU_HASH",
lief.ELF.SECTION_TYPES.GNU_VERDEF : "GNU_VERDEF",
lief.ELF.SECTION_TYPES.GNU_VERNEED : "GNU_VERNEED",
lief.ELF.SECTION_TYPES.GNU_VERSYM : "GNU_VERSYM",
lief.ELF.SECTION_TYPES.GROUP : "GROUP",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.PREINIT_ARRAY : "PREINIT_ARRAY",
lief.ELF.SECTION_TYPES.PROGBITS : "PROGBITS",
lief.ELF.SECTION_TYPES.REL : "REL",
lief.ELF.SECTION_TYPES.RELA : "RELA",
lief.ELF.SECTION_TYPES.SHLIB : "SHLIB",
lief.ELF.SECTION_TYPES.STRTAB : "STRTAB",
lief.ELF.SECTION_TYPES.SYMTAB : "SYMTAB",
lief.ELF.SECTION_TYPES.SYMTAB_SHNDX : "SYMTAB_SHNDX",
}
ELF_SEGMENT_FLAGS = {
lief.ELF.SECTION_TYPES.GNU_VERSYM : "GNU_VERSYM",
lief.ELF.SECTION_TYPES.GROUP : "GROUP",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.PREINIT_ARRAY : "PREINIT_ARRAY",
lief.ELF.SECTION_TYPES.PROGBITS : "PROGBITS",
lief.ELF.SECTION_TYPES.REL : "REL",
lief.ELF.SECTION_TYPES.RELA : "RELA",
lief.ELF.SECTION_TYPES.SHLIB : "SHLIB",
lief.ELF.SECTION_TYPES.STRTAB : "STRTAB",
lief.ELF.SECTION_TYPES.SYMTAB : "SYMTAB",
lief.ELF.SECTION_TYPES.SYMTAB_SHNDX : "SYMTAB_SHNDX",
}
ELF_SEGMENT_FLAGS = {
lief.ELF.SEGMENT_FLAGS.R : "R",
lief.ELF.SEGMENT_FLAGS.W : "W",
lief.ELF.SEGMENT_FLAGS.X : "X",
lief.ELF.SEGMENT_FLAGS.NONE : "None"
}
lief.ELF.SECTION_FLAGS.TLS : "T",
lief.ELF.SECTION_FLAGS.WRITE : "W",
lief.ELF.SECTION_FLAGS.XCORE_SHF_CP_SECTION : "XC"
}
ELF_SECTION_TYPES = {
lief.ELF.SECTION_TYPES.ARM_ATTRIBUTES : "ARM_ATTRIBUTES",
lief.ELF.SECTION_TYPES.ARM_DEBUGOVERLAY : "ARM_DEBUGOVERLAY",
lief.ELF.SECTION_TYPES.ARM_EXIDX : "ARM_EXIDX",
lief.ELF.SECTION_TYPES.ARM_OVERLAYSECTION : "ARM_OVERLAYSECTION",
lief.ELF.SECTION_TYPES.ARM_PREEMPTMAP : "ARM_PREEMPTMAP",
lief.ELF.SECTION_TYPES.DYNAMIC : "DYNAMIC",
lief.ELF.SECTION_TYPES.DYNSYM : "DYNSYM",
lief.ELF.SECTION_TYPES.FINI_ARRAY : "FINI_ARRAY",
lief.ELF.SECTION_TYPES.GNU_ATTRIBUTES : "GNU_ATTRIBUTES",
lief.ELF.SECTION_TYPES.GNU_HASH : "GNU_HASH",
lief.ELF.SECTION_TYPES.GNU_VERDEF : "GNU_VERDEF",
lief.ELF.SECTION_TYPES.GNU_VERNEED : "GNU_VERNEED",
lief.ELF.SECTION_TYPES.GNU_VERSYM : "GNU_VERSYM",
lief.ELF.SECTION_TYPES.GROUP : "GROUP",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.PREINIT_ARRAY : "PREINIT_ARRAY",
lief.ELF.SECTION_TYPES.PROGBITS : "PROGBITS",
lief.ELF.SECTION_TYPES.REL : "REL",
lief.ELF.SECTION_TYPES.RELA : "RELA",
lief.ELF.SECTION_TYPES.SHLIB : "SHLIB",
lief.ELF.SECTION_TYPES.STRTAB : "STRTAB",
lief.ELF.SECTION_TYPES.SYMTAB : "SYMTAB",
lief.ELF.SECTION_TYPES.SYMTAB_SHNDX : "SYMTAB_SHNDX",
}
ELF_SEGMENT_FLAGS = {
lief.ELF.SEGMENT_FLAGS.R : "R",
lief.ELF.SEGMENT_FLAGS.W : "W",
lief.ELF.SEGMENT_FLAGS.X : "X",
lief.ELF.SEGMENT_FLAGS.NONE : "None"
}
ELF_SEGMENT_TYPES = {
lief.ELF.SEGMENT_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.GNU_VERNEED : "GNU_VERNEED",
lief.ELF.SECTION_TYPES.GNU_VERSYM : "GNU_VERSYM",
lief.ELF.SECTION_TYPES.GROUP : "GROUP",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.PREINIT_ARRAY : "PREINIT_ARRAY",
lief.ELF.SECTION_TYPES.PROGBITS : "PROGBITS",
lief.ELF.SECTION_TYPES.REL : "REL",
lief.ELF.SECTION_TYPES.RELA : "RELA",
lief.ELF.SECTION_TYPES.SHLIB : "SHLIB",
lief.ELF.SECTION_TYPES.STRTAB : "STRTAB",
lief.ELF.SECTION_TYPES.SYMTAB : "SYMTAB",
lief.ELF.SECTION_TYPES.SYMTAB_SHNDX : "SYMTAB_SHNDX",
}
ELF_SEGMENT_FLAGS = {
lief.ELF.SEGMENT_FLAGS.R : "R",
lief.ELF.SEGMENT_FLAGS.W : "W",
lief.ELF.SEGMENT_FLAGS.X : "X",
lief.ELF.SEGMENT_FLAGS.NONE : "None"
}
ELF_SECTION_TYPES = {
lief.ELF.SECTION_TYPES.ARM_ATTRIBUTES : "ARM_ATTRIBUTES",
lief.ELF.SECTION_TYPES.ARM_DEBUGOVERLAY : "ARM_DEBUGOVERLAY",
lief.ELF.SECTION_TYPES.ARM_EXIDX : "ARM_EXIDX",
lief.ELF.SECTION_TYPES.ARM_OVERLAYSECTION : "ARM_OVERLAYSECTION",
lief.ELF.SECTION_TYPES.ARM_PREEMPTMAP : "ARM_PREEMPTMAP",
lief.ELF.SECTION_TYPES.DYNAMIC : "DYNAMIC",
lief.ELF.SECTION_TYPES.DYNSYM : "DYNSYM",
lief.ELF.SECTION_TYPES.FINI_ARRAY : "FINI_ARRAY",
lief.ELF.SECTION_TYPES.GNU_ATTRIBUTES : "GNU_ATTRIBUTES",
lief.ELF.SECTION_TYPES.GNU_HASH : "GNU_HASH",
lief.ELF.SECTION_TYPES.GNU_VERDEF : "GNU_VERDEF",
lief.ELF.SECTION_TYPES.GNU_VERNEED : "GNU_VERNEED",
lief.ELF.SECTION_TYPES.GNU_VERSYM : "GNU_VERSYM",
lief.ELF.SECTION_TYPES.GROUP : "GROUP",
lief.ELF.SECTION_TYPES.HASH : "HASH",
lief.ELF.SECTION_TYPES.HIPROC : "HIPROC",
lief.ELF.SECTION_TYPES.HIUSER : "HIUSER",
lief.ELF.SECTION_TYPES.INIT_ARRAY : "INIT_ARRAY",
lief.ELF.SECTION_TYPES.LOOS : "LOOS",
lief.ELF.SECTION_TYPES.LOPROC : "LOPROC",
lief.ELF.SECTION_TYPES.LOUSER : "LOUSER",
lief.ELF.SECTION_TYPES.MIPS_ABIFLAGS : "MIPS_ABIFLAGS",
lief.ELF.SECTION_TYPES.MIPS_OPTIONS : "MIPS_OPTIONS",
lief.ELF.SECTION_TYPES.MIPS_REGINFO : "MIPS_REGINFO",
lief.ELF.SECTION_TYPES.NOBITS : "NOBITS",
lief.ELF.SECTION_TYPES.NOTE : "NOTE",
lief.ELF.SECTION_TYPES.NULL : "NULL",
lief.ELF.SECTION_TYPES.PREINIT_ARRAY : "PREINIT_ARRAY",
lief.ELF.SECTION_TYPES.PROGBITS : "PROGBITS",
lief.ELF.SECTION_TYPES.REL : "REL",
lief.ELF.SECTION_TYPES.RELA : "RELA",
def create_section_dynamic(elf):
section = Section()
section.name = ".dynamic"
section.type = lief.ELF.SECTION_TYPES.DYNAMIC
section.flags = lief.ELF.SECTION_FLAGS.WRITE | lief.ELF.SECTION_FLAGS.ALLOC
section.link = INDEX_DYNSTR
section.information = 0
section.entry_size = 0x10
segment = get_dynamic_segment(elf)
section.virtual_address = segment.virtual_address
section.offset = elf.virtual_address_to_offset(segment.virtual_address)
section.size = segment.physical_size
section.alignment = segment.alignment
return section
def create_section_text(elf):
section = Section()
section.name = ".text"
section.type = lief.ELF.SECTION_TYPES.PROGBITS
section.flags = lief.ELF.SECTION_FLAGS.ALLOC | lief.ELF.SECTION_FLAGS.EXECINSTR
section.link = 0
section.information = 0
section.alignment = 16
section.entry_size = 0
section.size = len(elf.dynamic_entries) * section.entry_size
# TODO
segment = get_load_segment(elf, index=0)
section.virtual_address = segment.virtual_address
section.offset = elf.virtual_address_to_offset(section.virtual_address)
section.size = segment.virtual_size
return section
def create_section_shstrtab(sections):
section = Section()
section.name = ".shstrtab"
section.type = lief.ELF.SECTION_TYPES.STRTAB
section.flags = lief.ELF.SECTION_FLAGS.NONE
section.link = 0
section.information = 0
section.alignment = 1
section.offset = 0
section.entry_size = 0
section.size = 0
section.content = b''
for other_section in sections:
other_section.name_idx = len(section.content)
section.content += other_section.name.encode('ascii') + b'\x00'
section.name_idx = len(section.content)
section.content += section.name.encode('ascii') + b'\x00'
return section