Overview of LIEF - Patchelf
mainpatchelf utility, built using the LIEF library. It is designed to provide advanced binary patching capabilities.repository·main·Indexed 26 days ago
https://github.com/lief-project/liefA cross-platform library to parse, modify, and abstract executable formats including ELF, PE, MachO, COFF, OAT, DEX, and VDEX. LIEF provides a unified API for manipulating binary internals across C++, Python, and Rust, and includes tools like LIEF-Patchelf and plugins for Binary Ninja.
patchelf utility, built using the LIEF library. It is designed to provide advanced binary patching capabilities.LIEF is a cross-platform library designed to parse, modify, and abstract various executable formats, including:
It provides a C++11 public interface with idiomatic bindings for Python and Rust.
LIEF is used by various open-source projects across different domains such as static analysis, malware analysis, machine learning, and binary loading. Below is a list of notable projects that leverage LIEF:
The LIEF Runtime Memory interface provides an API to allocate, inspect, and manipulate memory within the current process. Key capabilities include:
When used in conjunction with lief-runtime-assemble, it enables lightweight JIT (Just-In-Time) code generation. It can also be paired with lief-runtime-disassemble to disassemble code directly from memory.
LIEF provides plugins for Binary Ninja to leverage its binary analysis capabilities within the Binary Ninja environment. For detailed documentation, installation instructions, and advanced usage, refer to the official LIEF documentation.
https://lief.re/doc/latest/plugins/binaryninja/index.htmlA basic (non-FAT) Mach-O binary consists of four main parts:
lief.MachO.Binary.header.lief.MachO.Binary.load_commands. These commands define segments, shared libraries, and entry points.codesign adds LC_CODE_SIGNATURE or LC_DYLIB_CODE_SIGN_DRS here).Modifying the binary often involves adding or replacing load commands (like lief.MachO.UUIDCommand or lief.MachO.CodeSignature) within the padding area or by shifting the raw data section to create space.
Android applications use several formats for code execution. Understanding the relationship between them is key for analysis:
classes.dex..odex or .oat extensions, they can sometimes appear with a .dex extension.dex2oat optimizes a DEX file, it produces a classes.odex (the ELF/OAT file with native code) and a classes.vdex file. The VDEX file contains a copy of the original DEX files and is not an ELF file.Warning: Do not rely on file extensions. A .dex file might actually be an OAT/ELF file. Use tools like file to verify the actual format.
LIEF's Rust bindings are organized into several crates:
lief: The high-level, idiomatic Rust API for end-users.lief-ffi: The low-level FFI API based on cxx.lief-build: A build-script helper used by lief-ffi to fetch pre-compiled artifacts and emit cargo link directives.lief-ffigen: A standalone CLI used to generate the C++ side of the cxx bridge from #[cxx::bridge] modules in lief-ffi.lief.objc module provides Python bindings for interacting with Objective-C metadata within binaries. It allows you to inspect and manipulate Objective-C structures such as classes, methods, properties, and protocols.set_resources() function. This allows you to copy all resources from a source binary into a target binary.