CasualX/pelite
关于
用于读取和遍历 PE 二进制文件的轻量级内存安全库,不进行内存分配。
开发工具实测星标增长
- 24小时
- 0
- 7天
- +2
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文PeLite
Lightweight, memory-safe, zero-allocation library for reading and navigating PE binaries.
Design
The purpose of this library is inspecting PE binaries (whether on disk or already loaded in memory).
A trade-off was made to not unify the 32-bit (PE32) and 64-bit (PE32+) formats for two reasons:
There are small but incompatible differences, which would add overhead by requiring constant matching even if at source code level the match arms look identical.
Most of the time you know (at build time) what format you're working with anyway.
This makes it rather awkward to work with both formats together transparently.
Note that while the correct name is PE32+, the name PE64 is used as it is a valid identifier; they are otherwise synonymous.
Tools
The workspace includes pelite-cli for inspecting PE binaries
from the command line. Its README covers the commands, getting started, and output
formats. The sample project provides the 32-bit sample.dll
and 64-bit sample64.dll with C++ RTTI and a range of PE structures. The
demos have more examples.
Library
This library is available on crates.io.
Documentation can be found on docs.rs.
In your Cargo.toml, put
[dependencies]
pelite = "0.10"
For efficient file loading, we recommend enabling mmap, which provides FileMap
and ImageMap. Memory mapping lets the operating system load file pages on demand.
[dependencies]
pelite = { version = "0.10", features = ["mmap"] }
Examples
Try this example: cargo run --example readme.
use pelite::PeMemory;
use pelite::pe64::{Pe, PeFile};
fn main() {
// Load the desired file into memory
let memory = PeMemory::open("demo/Demo64.dll").unwrap();
// Process the image file
dll_deps(memory.as_ref()).unwrap();
}
fn dll_deps(image: &[u8]) -> pelite::Result<()> {
// Interpret the bytes as a PE32+ executable
let file = PeFile::from_bytes(image)?;
// Let's read the DLL dependencies
let imports = file.imports()?;
for desc in imports {
// Get the DLL name being imported from
let dll_name = desc.dll_name()?;
// Get the number of imports for this dll
let iat = desc.iat()?;
println!("imported {} functions from {}", iat.len(), dll_name);
}
Ok(())
}
Coverage
Coverage uses Rust's LLVM source-based instrumentation through cargo-llvm-cov.
To generate and open a local HTML report:
rustup component add llvm-tools-preview
cargo install cargo-llvm-cov --locked
cargo llvm-cov --package pelite --all-features --html --open
License
Licensed under MIT License, see license.txt.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.
探索相关项目
加载中…