HexSpell
A lightweight, dependency-free Rust library for parsing and patching PE, ELF, and Mach-O executables.
Overview
HexSpell is a small parsing library for executable binaries. It has no runtime dependencies — only the Rust standard library — so it stays easy to embed, audit, and ship.
Parse PE, ELF, and Mach-O files (including FAT Mach-O), read headers and tables, and write changes back to disk when you need to patch an executable.
- Zero dependencies — no external crates at runtime.
- Lightweight — focused on parsing and patching; no heavy framework around the formats.
- Multi-format — PE (Windows), ELF (Linux), and Mach-O (macOS) in one crate.
- Parse and patch — read entry points, sections, imports, exports, and more; update headers and write the file back with
write_file. - Structural edits — insert sections and load segments, sync layout, apply relocations.
- Lazy parsers — imports, exports, TLS, exceptions, symbols, and other tables parsed on demand.
- Endianness-aware — ELF and Mach-O byte order handled via
ByteOrder.
See docs/coverage.md for exactly what is modeled per format.
Installation
Or add it manually to Cargo.toml:
[]
= "1.0"
Quick start
use PE;
ELF and Mach-O follow the same pattern (ELF::from_file, MachO::from_file). For big-endian
binaries, use Field::update_with with the format's byte_order().
Examples
Reading key header fields per format:
use PE;
let pe = PEfrom_file.unwrap;
println!;
println!;
println!;
println!;
use ELF;
let elf = ELFfrom_file.unwrap;
println!;
println!;
println!;
use MachO;
let macho = from_file.unwrap;
println!;
println!;
println!;
Inserting a new PE section (for example, to inject code):
use PE;
use ;
let mut pe = PEfrom_file.unwrap;
pe.insert_section
.unwrap;
// Point the entry to the start of the new section.
let new_va = pe.sections.last.unwrap.virtual_address.value;
pe.optional_header
.entry_point
.update
.unwrap;
pe.write_file.unwrap;
More runnable examples and per-format walkthroughs live in the user guide.
Documentation
- User guide — design principles, per-format examples, error handling.
- Layout accessors —
field()/field_mut()on ELF/Mach-O layout enums. - Coverage matrix — what is modeled vs not, per format.
- Changelog — notable changes per release.
Contributing
Issues and pull requests are welcome — open an issue to
report a bug or discuss a change. Contributors and agents should follow the conventions in
AGENTS.md (tests required, cargo fmt + cargo test before finishing, no runtime
dependencies).
License
Distributed under the terms of the MIT License. See LICENSE for details.