crabstep
is a Rust library that deserializes Apple's typedstream
data into cross-platform data structures.
The typedstream
format is a binary serialization protocol designed for C
and Objective-C
data structures. It is primarily used in Apple's Foundation
framework, specifically within the NSArchiver
and NSUnarchiver
classes.
This library is available on crates.io.
Documentation is available on docs.rs.
use std::{env::current_dir, fs::File, io::Read};
use crabstep::TypedStreamDeserializer;
// Read the typedstream file into memory
let typedstream_path = current_dir()
.unwrap()
.as_path()
.join("path/to/typedstream/file");
let mut file = File::open(typedstream_path).unwrap();
let mut bytes = vec![];
file.read_to_end(&mut bytes).unwrap();
// Create a deserializer
let mut typedstream = TypedStreamDeserializer::new(&bytes);
// Iterate over the typedstream's properties
typedstream.iter_root()
.unwrap()
.for_each(|prop| println!("{:#?}", prop))
This crate is heavily leveraged by imessage-database
's body
module.
The typedstream
format is derived from the data structure used by NeXTSTEP
's NXTypedStream
APIs.
- Pure Rust implementation for efficient and safe deserialization
- No dependencies on Apple frameworks
- Robust error handling for malformed or incomplete
typedstream
data - Ergonomic
TypedStreamDeserializer
withresolve_properties
iterator for exploring object graphs
A blog post describing the reverse engineering of typedstream
is available as an in-depth article.