HexSpell: The Executable Rust Parser
Table of Contents
Description
HexSpell is an open source library created in Rust, designed to parse and manipulate various types of executable files, including PE (Portable Executable), ELF (Executable and Linkable Format), and Mach-O binaries. The library is built without dependencies, with the aim of providing an easy-to-use and flexible tool for developers to analyse and modify executables.
Features
- No Dependency: The library is built entirely without dependencies, making it lightweight and easy to maintain.
- Multi-format Support: Parses and manipulates PE (Windows), ELF (Linux), and Mach-O (macOS) formats, including FAT Mach-O binaries
- Automatic Endianness Handling: Detects and respects ELF and Mach-O endianness during parsing
- Executable Manipulation: Modify executable attributes such as entry points, inject sections, update headers, and write changes back to disk using
write_file - Checksum Calculation: Validate or update checksums of parsed files
- Cross-platform Support: Provides consistent parsing and manipulation tools across multiple platforms
Installation
To include HexSpell in your Rust project, add it to your dependencies with Cargo:
Or manually add this line to your Cargo.toml:
[]
= "0.1.x"
Examples of use
Parsing PE Files
HexSpell allows you to parse and display important information from PE files.
use PE;
OUTPUT
╔════════════════════════════════════════╗
║ File: tests/samples/sample1.exe ║
╠════════════════════════════════════════╣
║ PE Checksum: 0x00007106 ║
║ Architecture: x86 ║
║ PE Type: PE32 ║
║ Number of sections: 0x00000008 ║
║ Size of image: 0x0000C000 ║
╚════════════════════════════════════════╝
Parsing ELF Files
You can also easily parse ELF binaries (Linux executables) with HexSpell.
use ELF;
OUTPUT
╔════════════════════════════════════════╗
║ File: tests/samples/linux ║
╠════════════════════════════════════════╣
║ Entry point: 0x00001060 ║
║ Program headers: 13 ║
║ Section headers: 31 ║
║ Endianness: Little ║
╚════════════════════════════════════════╝
Parsing Mach-O Files
Mach-O files, commonly used in macOS, can also be parsed and inspected.
use MachO;
OUTPUT
╔════════════════════════════════════════╗
║ File: tests/samples/machO-OSX-x86-ls ║
╠════════════════════════════════════════╣
║ Number of load commands: 16 ║
║ File type: 2 ║
║ Endianness: Little ║
║ First segment name: __PAGEZERO ║
╚════════════════════════════════════════╝
Modify PE Attributes
HexSpell provides utilities to modify executables, such as changing the entry point of a PE file.
use PE;
Create new section and injecting a shellcode
Adding code in a section with its own header
use PE;
const SHELLCODE: =
Support or Contact
Having trouble with HexSpell? Please submit an issue on GitHub.
License
HexSpell is distributed under the terms of the MIT License. See LICENSE for details.