Exhume Partitions as a library
info
If you notice something that doesn't work anymore, notify us on the discord server in the dedicated channel !
Install as a library​
Here is a quick example of how you could use exhume partitions as a library.
Create a project:
cargo new partition_test
cd partition_test/src
Open the Cargo.toml
file and add the exhume_body
and exhume_partitions
as dependencies:
[dependencies]
exhume_body = "=0.1.1"
exhume_partitions = "=0.2.0"
# Required crates to log events
log = "0.4.25"
env_logger = "0.11.6"
Simple example​
Let's look at a simple code example to display the discover partitions to the screen.
// main.rs
// Importing the exhume dependencies
use exhume_body::Body; // To read a disk image in multiple formats
use exhume_partitions::Partitions; // To parse partitions
fn main() {
// Connect our log env
env_logger::Builder::new().filter_level(log::LevelFilter::Info).init();
// We create an exhume body object to fetch our image.
let mut body = Body::new("/path/to/your/image.img".to_string(), "auto");
match Partitions::new(&mut body) {
Ok(partitions) => {
let partition_info = partitions.print_info();
println!("{}", partition_info)
}
Err(err) => {
println!("Could not discover partitions: {:?}", err);
}
}
}
After building and running here is a sample output bellow.
cargo build
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
Running `/partitions_test/target/debug/partitions_test`
cargo run
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Signature | EFI PART |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Revision | 0x10000 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Header size | 0x5c |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CRC32 | 0x3a8a95bf |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Current LBA | 0x1 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Backup LBA | 0x3c007ff |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| First Usable LBA | 0x22 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Disk GUID | d052de8c-3b65-4c63-84a4-c2488a6783ad |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Partition Entry LBA | 0x2 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Number Of Entries | 0x80 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Size of one Entry | 0x80 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Partition Array CRC32 | 0xf1a018ef |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Partition tables entries | +--------------------------------------+--------------------------------------+----------------------------+---------------------+-------------------+------------+--------------------------------------+ |
| | | Partition GUID | Partition Type GUID | Partition Type Description | Start address (LBA) | End address (LBA) | Attributes | Partition Name | |
| | +--------------------------------------+--------------------------------------+----------------------------+---------------------+-------------------+------------+--------------------------------------+ |
| | | 6cfbbd1d-66ee-4912-82fe-4173570d3098 | 0fc63daf-8483-4772-8e79-3d69d8477de4 | Linux filesystem data | 0x37800 | 0x3c007de | 0 | | |
| | +--------------------------------------+--------------------------------------+----------------------------+---------------------+-------------------+------------+--------------------------------------+ |
| | | 09cef2e7-e009-49f4-9cab-5ae73e63d77b | 21686148-6449-6e6f-744e-656564454649 | BIOS boot partition | 0x800 | 0x27ff | 0 | | |
| | +--------------------------------------+--------------------------------------+----------------------------+---------------------+-------------------+------------+--------------------------------------+ |
| | | 9c5f01b2-1c29-4828-ac89-0f8c4a7759a2 | c12a7328-f81f-11d2-ba4b-00a0c93ec93b | EFI System partition | 0x2800 | 0x377ff | 0 | | |
| | +--------------------------------------+--------------------------------------+----------------------------+---------------------+-------------------+------------+--------------------------------------+ |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Accessing Attributes​
You can manipulate the partition attributes to use them later in other tools. The example bellow is showing you how to access some of them:
fn main() {
// Connect our log env
env_logger::Builder::new().filter_level(log::LevelFilter::Info).init();
// We create an exhume body object to fetch our image.
let mut body = Body::new("/path/to/your/image.img".to_string(), "auto");
match Partitions::new(&mut body) {
Ok(partitions) => {
match partitions.gpt {
Some(gpt) => {
println!("{:?}", &format!(
"{}",
String::from_utf8_lossy(&gpt.header.signature) // Display the gpt header signature
));
},
None => (),
};
}
Err(err) => {
println!("Could not discover partitions: {:?}", err);
}
}
}
Result:
[2025-04-14T12:15:18Z INFO exhume_body] Detected RAW Data
[2025-04-14T12:15:18Z INFO exhume_partitions] Detected an MBR partition scheme.
[2025-04-14T12:15:18Z INFO exhume_partitions] Detected a Protective MBR. GPT scheme is strongly suspected.
[2025-04-14T12:15:18Z INFO exhume_partitions] Discovered a GPT partition scheme
"EFI PART"