LIEF (Library to Instrument Executable Formats) is a robust, cross-platform library designed to parse, modify, and abstract various executable formats, including ELF, PE, Mach-O, OAT, DEX, VDEX, and ART. It provides a comprehensive, user-friendly API for C++, Python, Rust, and C, enabling detailed analysis, manipulation, and reconstruction of binaries without relying on disassemblers. Currently at version 0.17.6, LIEF maintains an active development and release cadence, with frequent updates addressing new features and bug fixes.
pip install liefVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `lief.parse()` to automatically detect and parse an executable file (ELF on Linux/macOS, PE on Windows). It then prints basic information about the binary, showcasing format-specific attributes like ELF machine type or number of PE imported libraries. Replace the default paths with your target binaries.
Review the 'PE Changelog for LIEF 0.17.0' documentation for specific API changes and migration guidance. Functions returning references that previously threw exceptions now return pointers (or Python `None`) on failure.
Use `lief.PE.ParserConfig` to enable desired parsing options. For example, `config = lief.PE.ParserConfig(); config.parse_exports = True; binary = lief.PE.parse('path/to/pe.exe', config)`. Review `lief.PE.ParserConfig` for available flags.Avoid using the `create_pe_from_scratch` functionality. Focus on modifying existing binaries, which has seen improvements in the builder engine.
Upgrade to LIEF 0.17.0 or newer, as the builder engine for PE files has been refactored to address these limitations and provide a more conservative approach to modifications.
Projects that compile LIEF from source or have custom build setups should review their build configurations, especially regarding `setuptools` and `scikit-build-core` as mentioned in the v0.14.0 changelog.
Ensure LIEF is properly installed by running `pip install lief`. If using a specific Python version or virtual environment, activate it first. For installation issues like 'couldn't build wheel for lief', consider installing from a specific URL for nightly builds or tagged releases if PyPI wheels are not available for your platform or Python version.
Update your code to use `lief.Binary.FORMATS.ELF`, `lief.Binary.FORMATS.PE`, or the specific format's `FORMATS` attribute (e.g., `lief.ELF.FORMATS.ELF`) instead of `lief.EXE_FORMATS`. Alternatively, for `lief.PE.get_type`, the result is now a `lief.PE.PE_TYPE` enum.
Replace `binary.has_signature` with `binary.has_signatures` in your code to reflect the API update.
Consult the LIEF documentation for your installed version to find the correct path for `DYNAMIC_TAGS` within the `lief.ELF` module. It might be directly under `lief.ELF.DYNAMIC_TAGS` or a similar path. Consider pinning your `lief` version if compatibility is critical.
Store the result of `lief.parse()` in a variable before accessing its attributes, like `p = lief.parse('/bin/ls'); list(p.sections)`. This ensures the `Binary` object's lifetime is managed correctly.No dependency data recorded yet.