How to use the lief.ELF.parse 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 lief-project / LIEF / tests / elf / test_parser.py View on Github external
def setUp(self):
        self.logger = logging.getLogger(__name__)

        self.sectionless = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_rvs.bin'), lief.ELF.DYNSYM_COUNT_METHODS.HASH)
github lief-project / LIEF / tests / elf / test_parser.py View on Github external
def test_symbol_count(self):

        gcc1 = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_gcc.bin'), lief.ELF.DYNSYM_COUNT_METHODS.HASH)
        gcc2 = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_gcc.bin'), lief.ELF.DYNSYM_COUNT_METHODS.SECTION)
        gcc3 = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_gcc.bin'), lief.ELF.DYNSYM_COUNT_METHODS.RELOCATIONS)

        self.assertEqual(len(gcc1.symbols), 158)
        self.assertEqual(len(gcc2.symbols), 158)
        self.assertEqual(len(gcc3.symbols), 158)
github 0xcpu / RElieve / elfie.py View on Github external
def run():
    if len(sys.argv) < 2:
        print("[USAGE]: {0} ".format(sys.argv[0]))
        sys.exit(1)

    try:
        binary = lief.ELF.parse(sys.argv[1])
    except lief.bad_file as err:
        print("Error: {0}".format(err))
        sys.exit(1)

    show_name(binary)
    enum_header(binary.header)
    enum_dyn_entries(binary)
    enum_dyn_relocs(binary)
    enum_exp_funcs(binary)
    enum_exp_symbols(binary)
    enum_imp_functions(binary)
    enum_imp_symbols(binary)
    enum_libraries(binary)
    show_notes(binary)
    show_interpreter(binary)
    enum_sections(binary)
github target / strelka / src / python / strelka / scanners / scan_elf.py View on Github external
def scan(self, data, file, options, expire_at):
        elf = ELF.parse(raw=data)

        self.event['total'] = {
            'libraries': len(elf.libraries),
            'relocations': len(elf.relocations),
            'sections': elf.header.numberof_sections,
            'segments': elf.header.numberof_segments,
            'symbols': len(elf.symbols),
        }

        self.event['nx'] = elf.has_nx
        self.event['pie'] = elf.is_pie

        self.event['header'] = {
            'endianness': str(elf.header.identity_data).split('.')[1],
            'entry_point': elf.header.entrypoint,
            'file': {
github lief-project / LIEF / examples / python / elf_reader.py View on Github external
optparser.add_option('--strings',
            action='store_true', dest='show_strings',
            help='Strings present in the current ELF')

    optparser.add_option('--functions',
            action='store_true', dest='show_functions',
            help='List all function addresses found')

    options, args = optparser.parse_args()

    if options.help or len(args) == 0:
        optparser.print_help()
        sys.exit(0)


    binary = ELF.parse(args[0])
    print_information(binary)
    if options.show_all:
        do_file_header = do_section_header = do_program_header = True

    if options.show_all_headers:
        do_file_header = do_section_header = do_program_header = True
    else:
        do_file_header    = options.show_file_header
        do_section_header = options.show_section_header
        do_program_header = options.show_program_header

    if do_file_header or options.show_all:
        print_header(binary)

    if do_section_header or options.show_all:
        print_sections(binary)
github malware-revealer / extractor / mrextractor / features / elf.py View on Github external
def can_extract(self, raw_exe):
        b_list = list(raw_exe)
        elf_binary = lief.ELF.parse(raw=b_list)
        if elf_binary:
            return True
        else:
            return False
github lief-project / LIEF / examples / python / elf_unstrip.py View on Github external
# -*- coding: utf-8 -*-

# Description
# -----------
# In this example, we assume that we found
# the ``main`` function at address 0x402A00
# and we add a static symbol to the binary
# so that we can do:
#
# (gdb) break main
# Breakpoint 1 at 0x402a00

from lief import ELF
import sys

binary = ELF.parse(sys.argv[1])

symtab_section             = ELF.Section()
symtab_section.name        = ""
symtab_section.type        = ELF.SECTION_TYPES.SYMTAB
symtab_section.entry_size  = 0x18
symtab_section.alignment   = 8
symtab_section.link        = len(binary.sections) + 1
symtab_section.content     = [0] * 100

symstr_section            = ELF.Section()
symstr_section.name       = ""
symstr_section.type       = ELF.SECTION_TYPES.STRTAB
symstr_section.entry_size = 1
symstr_section.alignment  = 1
symstr_section.content    = [0] * 100
github securisec / glorifiedgrep / glorifiedgrep / android / modules / utils.py View on Github external
def __init__(self, elf_path: str):
        self._core = _AndroidCore(None)
        self.elf_path = elf_path
        self._binary = lief.ELF.parse(self.elf_path)
        self._core.log_debug(self.__class__)