How to use the lief.ELF.SEGMENT_TYPES function in lief

To help you get started, we’ve selected a few lief examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ledger-Donjon / rainbow / rainbow / loaders / elfloader.py View on Github external
def elfloader(elf_file, emu, verbose=False):
    """ Load an .elf file into emu's memory using LIEF """
    elffile = lief.parse(elf_file)
    if verbose:
        print(f"[x] Loading .elf ...")

    if len(list(elffile.segments)) > 0:
        for segment in elffile.segments:
            if segment.type == lief.ELF.SEGMENT_TYPES.LOAD:
                for section in segment.sections:
                    if verbose:
                        print(
                            f"[=] Writing {section.name} on {section.virtual_address:x} - {section.virtual_address+section.size:x}"
                        )
                    emu.map_space(
                        section.virtual_address, section.virtual_address + section.size
                    )
                    emu.emu.mem_write(section.virtual_address, bytes(section.content))
    else:
        # if there are no segments, still attempt to map .text area
        section = elffile.get_section(".text")
        if verbose:
            print(
                f"[=] Writing {section.name} on {section.virtual_address:x} - {section.virtual_address+section.size:x}"
            )
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
lief.ELF.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}

ELF_ETYPE = {
    lief.ELF.E_TYPE.CORE        :   "CORE", 
    lief.ELF.E_TYPE.DYNAMIC     :   "DYNAMIC",
    lief.ELF.E_TYPE.EXECUTABLE  :   "EXECUTABLE",
    lief.ELF.E_TYPE.HIPROC      :   "HIPROC",
    lief.ELF.E_TYPE.LOPROC      :   "LOPROC",
    lief.ELF.E_TYPE.NONE        :   "NONE",
    lief.ELF.E_TYPE.RELOCATABLE :   "RELOCATABLE"
}

ELF_SYMBOL_VISIBILITY = {
    lief.ELF.SYMBOL_VISIBILITY.DEFAULT      :   "DEFAULT",
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
lief.ELF.SEGMENT_FLAGS.NONE :   "None"
}

ELF_SEGMENT_TYPES = {
    lief.ELF.SEGMENT_TYPES.NULL             :   "NULL",
    lief.ELF.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}

ELF_ETYPE = {
    lief.ELF.E_TYPE.CORE        :   "CORE", 
    lief.ELF.E_TYPE.DYNAMIC     :   "DYNAMIC",
    lief.ELF.E_TYPE.EXECUTABLE  :   "EXECUTABLE",
    lief.ELF.E_TYPE.HIPROC      :   "HIPROC",
    lief.ELF.E_TYPE.LOPROC      :   "LOPROC",
    lief.ELF.E_TYPE.NONE        :   "NONE",
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
ELF_SEGMENT_TYPES = {
    lief.ELF.SEGMENT_TYPES.NULL             :   "NULL",
    lief.ELF.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}

ELF_ETYPE = {
    lief.ELF.E_TYPE.CORE        :   "CORE", 
    lief.ELF.E_TYPE.DYNAMIC     :   "DYNAMIC",
    lief.ELF.E_TYPE.EXECUTABLE  :   "EXECUTABLE",
    lief.ELF.E_TYPE.HIPROC      :   "HIPROC",
    lief.ELF.E_TYPE.LOPROC      :   "LOPROC",
    lief.ELF.E_TYPE.NONE        :   "NONE",
    lief.ELF.E_TYPE.RELOCATABLE :   "RELOCATABLE"
}
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
lief.ELF.SEGMENT_TYPES.NULL             :   "NULL",
    lief.ELF.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}

ELF_ETYPE = {
    lief.ELF.E_TYPE.CORE        :   "CORE", 
    lief.ELF.E_TYPE.DYNAMIC     :   "DYNAMIC",
    lief.ELF.E_TYPE.EXECUTABLE  :   "EXECUTABLE",
    lief.ELF.E_TYPE.HIPROC      :   "HIPROC",
    lief.ELF.E_TYPE.LOPROC      :   "LOPROC",
    lief.ELF.E_TYPE.NONE        :   "NONE",
    lief.ELF.E_TYPE.RELOCATABLE :   "RELOCATABLE"
}

ELF_SYMBOL_VISIBILITY = {
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
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.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}

ELF_ETYPE = {
    lief.ELF.E_TYPE.CORE        :   "CORE", 
    lief.ELF.E_TYPE.DYNAMIC     :   "DYNAMIC",
    lief.ELF.E_TYPE.EXECUTABLE  :   "EXECUTABLE",
    lief.ELF.E_TYPE.HIPROC      :   "HIPROC",
github lief-project / tutorials / 05_ELF_infect_plt-got / hook_pltgot.py View on Github external
my_memcmp_addr = segment_added.virtual_address + my_memcmp.value

crackme.patch_pltgot('memcmp', my_memcmp_addr)

# Remove bind now if present
if lief.ELF.DYNAMIC_TAGS.FLAGS in crackme:
    flags = crackme[lief.ELF.DYNAMIC_TAGS.FLAGS]
    flags.remove(lief.ELF.DYNAMIC_FLAGS.BIND_NOW)

if lief.ELF.DYNAMIC_TAGS.FLAGS_1 in crackme:
    flags = crackme[lief.ELF.DYNAMIC_TAGS.FLAGS_1]
    flags.remove(lief.ELF.DYNAMIC_FLAGS_1.NOW)

# Remove RELRO
if lief.ELF.SEGMENT_TYPES.GNU_RELRO in crackme:
    crackme[lief.ELF.SEGMENT_TYPES.GNU_RELRO].type = lief.ELF.SEGMENT_TYPES.NULL


crackme.write("crackme.hooked")
github AlexAltea / orbital / tools / patch-sections-1xx.py View on Github external
def get_load_segment(elf, index=0):
    for segment in elf.segments:
        if segment.type != lief.ELF.SEGMENT_TYPES.LOAD:
            continue
        if index == 0:
            return segment
        index -= 1
    raise Exception("Segment not found")
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
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.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}
github viper-framework / viper / viper / modules / lief_imports / elf.py View on Github external
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.SEGMENT_TYPES.LOAD             :   "LOAD",
    lief.ELF.SEGMENT_TYPES.DYNAMIC          :   "DYNAMIC",
    lief.ELF.SEGMENT_TYPES.INTERP           :   "INTERP",
    lief.ELF.SEGMENT_TYPES.NOTE             :   "NOTE",
    lief.ELF.SEGMENT_TYPES.SHLIB            :   "SHLIB",
    lief.ELF.SEGMENT_TYPES.PHDR             :   "PHDR",
    lief.ELF.SEGMENT_TYPES.TLS              :   "TLS",
    lief.ELF.SEGMENT_TYPES.LOOS             :   "LOOS",
    lief.ELF.SEGMENT_TYPES.HIOS             :   "HIOS",
    lief.ELF.SEGMENT_TYPES.LOPROC           :   "LOPROC",
    lief.ELF.SEGMENT_TYPES.HIPROC           :   "HIPROC",
    lief.ELF.SEGMENT_TYPES.GNU_EH_FRAME     :   "GNU_EH_FRAME",
    lief.ELF.SEGMENT_TYPES.SUNW_UNWIND      :   "SUNW_UNWIND",
    lief.ELF.SEGMENT_TYPES.GNU_STACK        :   "GNU_STACK",
    lief.ELF.SEGMENT_TYPES.GNU_RELRO        :   "GNU_RELRO",
    lief.ELF.SEGMENT_TYPES.ARM_EXIDX        :   "ARM_EXIDX",
    lief.ELF.SEGMENT_TYPES.MIPS_ABIFLAGS    :   "MIPS_ABIFLAGS",
    lief.ELF.SEGMENT_TYPES.MIPS_OPTIONS     :   "MIPS_OPTIONS",
}