lief-project/LIEF

GitHub: lief-project/LIEF

跨平台可执行文件格式解析与修改库,支持通过 C++、Python、Rust 等语言编程操作 ELF、PE、MachO 等二进制文件。

Stars: 5307 | Forks: 715



博客文档关于


# 关于 本项目的目的是提供一个跨平台库,用于解析、修改和抽象 ELF、PE 和 MachO 格式。 **主要特性**: * **解析**:LIEF 可以解析 [ELF](https://lief.re/doc/latest/formats/elf/index.html)、[PE](https://lief.re/doc/latest/formats/pe/index.html)、[MachO](https://lief.re/doc/latest/formats/macho/index.html)、[COFF](https://lief.re/doc/latest/formats/coff/index.html)、OAT、DEX、VDEX、ART,并提供用户友好的 API 来访问内部结构。 * **修改**:LIEF 可用于修改这些格式的某些部分(添加 section、更改符号名称等)。 * **抽象**:这三种格式具有共同的特征,如 sections、symbols、entry point 等。LIEF 对它们进行了归纳抽象。 * **API**:LIEF 可用于 [C++](https://lief.re/doc/latest/doxygen/)、Python、[Rust](https://lief-rs.s3.fr-par.scw.cloud/doc/latest/lief/index.html)、C 和 [Node.js](https://github.com/Piebald-AI/node-lief)(非官方,AI 生成) **扩展功能**: * [**DWARF/PDB** 支持](https://lief.re/doc/latest/extended/debug_info/index.html) * [**Objective-C** 元数据](https://lief.re/doc/latest/extended/objc/index.html) * [**Dyld Shared Cache**](https://lief.re/doc/latest/extended/dsc/index.html),支持提取 Dylib * [**反汇编器**](https://lief.re/doc/latest/extended/disassembler/index.html):AArch64、x86/x86-64、ARM、RISC-V、Mips、PowerPC、eBPF * [**汇编器**](https://lief.re/doc/latest/extended/assembler/index.html):AArch64、x86/x86-64 **插件**: * [**Ghidra**](https://lief.re/doc/latest/plugins/ghidra/index.html) * [**BinaryNinja**](https://lief.re/doc/latest/plugins/binaryninja/index.html) # 目录 - [关于](#about) - [下载 / 安装](#downloads--install) - [快速入门](#getting-started) - [博客](https://lief.re/blog/) - [文档](#documentation) - [Rust](https://lief.re/doc/stable/rust/lief/) - [Sphinx](https://lief.re/doc/latest/index.html) - [Doxygen](https://lief.re/doc/latest/doxygen/index.html) - 教程: - [解析和操作格式](https://lief.re/doc/latest/tutorials/01_play_with_formats.html) - [玩转 ELF 符号](https://lief.re/doc/latest/tutorials/03_elf_change_symbols.html) - [PE 资源](https://lief.re/doc/latest/tutorials/07_pe_resource.html) - [将 ELF 可执行文件转换为库](https://lief.re/doc/latest/tutorials/08_elf_bin2lib.html) - [如何在非 Root 设备上使用 Frida](https://lief.re/doc/latest/tutorials/09_frida_lief.html) - [Android 格式](https://lief.re/doc/latest/tutorials/10_android_formats.html) - [Mach-O 修改](https://lief.re/doc/latest/tutorials/11_macho_modification.html) - [ ELF Coredump](https://lief.re/doc/latest/tutorials/12_elf_coredump.html) - [PE Authenticode](https://lief.re/doc/latest/tutorials/13_pe_authenticode.html) - [联系](#contact) - [关于](#about) - [作者](#authors) - [许可证](#license) - [Bibtex](#bibtex) ## 下载 / 安装 ## C++ ``` find_package(LIEF REQUIRED) target_link_libraries(my-project LIEF::LIEF) ``` ## Rust ``` [package] name = "my-awesome-project" version = "0.0.1" edition = "2021" [dependencies] lief = "0.17.4" ``` ## Python 安装最新**版本**(发布版): ``` pip install lief ``` 安装每日构建版(nightly): ``` pip install [--user] --force-reinstall --index-url https://lief.s3-website.fr-par.scw.cloud/latest lief==1.0.0.dev0 ``` ### 软件包 - LIEF Extended: https://extended.lief.re (GitHub OAuth) - **Nightly**: * SDK: https://lief.s3-website.fr-par.scw.cloud/latest/sdk * Python Wheels: https://lief.s3-website.fr-par.scw.cloud/latest/lief - **v0.17.4**: https://github.com/lief-project/LIEF/releases/tag/0.17.4 以下是安装或集成 LIEF 的指南: * [Python](https://lief.re/doc/latest/installation.html#python) * [Visual Studio](https://lief.re/doc/latest/installation.html#visual-studio-integration) * [XCode](https://lief.re/doc/latest/installation.html#xcode-integration) * [CMake](https://lief.re/doc/latest/installation.html#cmake-integration) ## 快速入门 ### Python ``` import lief # ELF binary = lief.parse("/usr/bin/ls") for section in binary.sections: print(section.name, section.virtual_address) # PE binary = lief.parse("C:\\Windows\\explorer.exe") if rheader := pe.rich_header: print(rheader.key) # Mach-O binary = lief.parse("/usr/bin/ls") for fixup in binary.dyld_chained_fixups: print(fixup) ``` ### Rust ``` use lief::Binary; use lief::pe::debug::Entries::CodeViewPDB; if let Some(Binary::PE(pe)) = Binary::parse(path.as_str()) { for entry in pe.debug() { if let CodeViewPDB(pdb_view) = entry { println!("{}", pdb_view.filename()); } } } ``` ### C++ ``` #include int main(int argc, char** argv) { // ELF if (std::unique_ptr elf = LIEF::ELF::Parser::parse("/bin/ls")) { for (const LIEF::ELF::Section& section : elf->sections()) { std::cout << section->name() << ' ' << section->virtual_address() << '\n'; } } // PE if (std::unique_ptr pe = LIEF::PE::Parser::parse("C:\\Windows\\explorer.exe")) { if (const LIEF::PE::RichHeader* rheader : pe->rich_header()) { std::cout << rheader->key() << '\n'; } } // Mach-O if (std::unique_ptr macho = LIEF::MachO::Parser::parse("/bin/ls")) { for (const LIEF::MachO::DyldChainedFixups& fixup : macho->dyld_chained_fixups()) { std::cout << fixup << '\n'; } } return 0; } ``` ### C (受限 API) ``` #include int main(int argc, char** argv) { Elf_Binary_t* elf = elf_parse("/usr/bin/ls"); Elf_Section_t** sections = elf->sections; for (size_t i = 0; sections[i] != NULL; ++i) { printf("%s\n", sections[i]->name); } elf_binary_destroy(elf); return 0; } ``` ## 文档 * [主要文档](https://lief.re/doc/latest/index.html) * [Doxygen](https://lief.re/doc/latest/doxygen/index.html) * [Rust](https://lief.re/doc/stable/rust/lief/) ## 联系 * **邮箱**: contact at lief re * **Discord**: [LIEF](https://discord.gg/7hRFGWYedu) ## 关于 ### 作者 Romain Thomas ([@rh0main](https://www.romainthomas.fr/)) - 前任职于 [Quarkslab](https://www.quarkslab.com) ### 许可证 LIEF 根据 [Apache 2.0 许可证](https://github.com/lief-project/LIEF/blob/0.17.4/LICENSE) 提供。 ### Bibtex ``` @MISC {LIEF, author = "Romain Thomas", title = "LIEF - Library to Instrument Executable Formats", howpublished = "https://lief.quarkslab.com/", month = "apr", year = "2017" } ```
标签:Android, API, API接口, Bash脚本, Binary Ninja, C++, DAST, DEX, DNS 反向解析, DNS 解析, DSL, DWARF, ELF, Findomain, Ghidra, Mach-O, MITM代理, OAT, PDB, PE, Python, Rust, TLS抓取, TLS配置检查, VDEX, Wayback Machine, 二进制修改, 二进制分析, 二进制抽象, 云安全监控, 云安全运维, 云资产清单, 动态链接库, 反汇编, 可执行文件格式, 可视化界面, 库, 应急响应, 恶意软件分析, 插桩, 数据擦除, 无后门, 汇编, 编程库, 编译器, 网络安全, 网络流量审计, 解析器, 调试信息, 软件安全, 逆向工具, 逆向工程, 隐私保护, 静态分析