ReagentX/crabstep
GitHub: ReagentX/crabstep
一个纯 Rust 实现的 Apple/NeXTSTEP typedstream 二进制序列化格式反序列化库,支持跨平台解析且零依赖。
Stars: 23 | Forks: 4
# crabstep
`crabstep` 是一个 Rust 库,用于将 Apple 的 `typedstream` 数据反序列化为跨平台的数据结构。
## 概述
`typedstream` 格式是一种二进制序列化协议,专为 `C` 和 `Objective-C` 数据结构设计。它主要用于 Apple 的 `Foundation` 框架,特别是 `NSArchiver` 和 `NSUnarchiver` 类。
## 安装说明
该库可在 [crates.io](https://crates.io/crates/crabstep) 上获取。
## 文档
文档可在 [docs.rs](https://docs.rs/crabstep) 上查阅。
### 快速入门
```
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))
```
### 详细示例
此 crate 被 [`imessage-database`](https://crates.io/crates/imessage-database) 的 [`body`](https://github.com/ReagentX/imessage-exporter/blob/develop/imessage-database/src/tables/messages/body.rs) 模块大量使用。
## 起源
`typedstream` 格式源自 `NeXTSTEP` 的 `NXTypedStream` API 所使用的数据结构。
## 功能
- 纯 Rust 实现,用于高效且安全的反序列化
- 不依赖 Apple 框架
- 对格式错误或不完整的 `typedstream` 数据提供稳健的错误处理
- 实用的 `TypedStreamDeserializer`,带有 `resolve_properties` 迭代器,方便探索对象图
## Feature 标志
`crabstep` 默认为 `no_std` 且不需要任何依赖。以下可选功能均为纯增量功能:
- `std`:启用仅限 `std` 的便捷功能,例如用于调试对象图的 `print_resolved`。
- `foundation`:在 `Property` 上为常见的 Apple [Foundation](https://developer.apple.com/documentation/foundation) 类(`as_string`、`as_data`、`as_array`、`as_dictionary`、`as_date`、`as_url` 等)添加类型化的访问器,这样使用者就不必手动实现类名匹配。请参阅 `deserializer::foundation` 模块。
在你的 `Cargo.toml` 中启用功能:
```
crabstep = { version = "0", features = ["foundation"] }
```
## 逆向工程
一篇描述 `typedstream` 逆向工程的博客文章可作为[深入解析文章](https://chrissardegna.com/blog/reverse-engineering-apples-typedstream-format/)阅读。
## Ferris

标签:Apple生态, Rust, 反序列化, 可视化界面, 开发库, 数据解析, 网络流量审计, 通知系统