SecurityRonin/xpress-huffman

GitHub: SecurityRonin/xpress-huffman

纯 Rust 实现的跨平台 Xpress-Huffman 解压缩库,让开发者无需依赖 Windows API 即可在任意平台上解码 Windows 预取文件、SMB3 和注册表等使用的压缩格式。

Stars: 0 | Forks: 0

# xpress-huffman [![Crates.io](https://img.shields.io/crates/v/xpress-huffman.svg)](https://crates.io/crates/xpress-huffman) [![Docs.rs](https://docs.rs/xpress-huffman/badge.svg)](https://docs.rs/xpress-huffman) [![Rust 1.85+](https://img.shields.io/badge/rust-1.85%2B-orange.svg)](https://www.rust-lang.org) [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) [![赞助](https://img.shields.io/badge/sponsor-h4x0r-ea4aaa.svg)](https://github.com/sponsors/h4x0r) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/91b22d5d67194509.svg)](https://github.com/SecurityRonin/xpress-huffman/actions/workflows/ci.yml) [![禁用 unsafe](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) [![安全公告](https://img.shields.io/badge/security-cargo--deny-success.svg)](deny.toml) **在任何地方解压 Microsoft Xpress-Huffman ([MS-XCA] §2.2.4) —— 这是 Win10+ prefetch、`hiberfil.sys`、SMB3 和注册表配置单元压缩背后的编解码器 —— 采用纯 Rust 编写,无 panic,且无需 Windows API。** ``` // `compressed` is an LZXPRESS_HUFFMAN stream (e.g. a prefetch MAM payload after // the 8-byte header); `size` is the decompressed length the container records. let plain = xpress_huffman::decompress(compressed, size)?; ``` 这就是全部接口:一个函数,无需设置,兼容 `#![no_std]`。 ## 为什么选择此 crate 现代 Windows 大量使用 Xpress-Huffman(`COMPRESSION_FORMAT_XPRESS_HUFF`,值为 4)进行压缩:Win8.1+ **Prefetch**(`MAM` 包装器)、**`hiberfil.sys`**、**SMB3** 传输压缩、**注册表配置单元**压缩以及 Windows Update 负载。在非 Windows 环境下解码通常意味着要调用 `RtlDecompressBufferEx` —— 而该 API 仅在 Windows 上存在。 | | 算法 | 支持 Xpress-**Huffman**? | 支持非 Windows 解码? | |---|---|---|---| | **`xpress-huffman`(此 crate)** | Xpress-**Huffman** ([MS-XCA] §2.2.4) | ✅ | ✅ 纯 Rust,支持任何平台 | | `rust-lzxpress`, `xpress_rs` | 普通 LZXpress (`COMPRESSION_FORMAT_XPRESS` = 3) | ❌ 仅限格式 3 | ✅ | | `RtlDecompressBufferEx` (Windows API) | 两者皆有 | ✅ | ❌ 仅限 Windows | 现有的 Rust crate 实现的是*普通* LZXpress(`LZNT` 风格的 LZ77 格式,值为 3)。此 crate 实现的是上述工件实际使用的 **Huffman 编码**变体(值为 4)。 ## 信任,但需验证 - **`#![forbid(unsafe_code)]`**,在生产代码路径中没有 `unwrap`/`expect`/panic —— 每次从(不受信任的)输入中读取的长度和偏移量都经过了边界检查。损坏的数据流只会产生 `Err`,绝不会引发 panic 或越界读取。 - **`#![no_std]`**(使用 `alloc`);启用 `std` feature 以获取 `std::error::Error` 实现。 - **已通过独立解压器验证。** 该解码器是 [MS-XCA] 算法的净室实现;其输出已针对 Fox-IT 独立的 `dissect.util` 解压器在真实的 Windows 工件上确认是**逐字节**一致的。请参阅 [`docs/validation.md`](docs/validation.md)。 ## 安装 ``` [dependencies] xpress-huffman = "0.1" ``` ## 解码 Windows prefetch 负载 ``` // A Win8.1+ prefetch file: `MAM\x04` + u32 decompressed size + the stream. let size = u32::from_le_bytes(mam[4..8].try_into().unwrap()) as usize; let scca = xpress_huffman::decompress(&mam[8..], size)?; assert_eq!(&scca[4..8], b"SCCA"); ``` (如需完整的 prefetch 解析 —— 运行次数、最后运行时间、已加载文件 —— 请参阅 [`prefetch-forensic`](https://github.com/SecurityRonin/prefetch-forensic) crate,该 crate 基于本项目构建。) [隐私政策](https://securityronin.github.io/xpress-huffman/privacy/) · [服务条款](https://securityronin.github.io/xpress-huffman/terms/) · © 2026 Security Ronin Ltd
标签:Rust, Xpress-Huffman, 可视化界面, 数据解压, 网络流量审计, 通知系统