Library and binaries for the reading, creating, and modification of SquashFS file systems.
unsquashfs)
only needs to include code to extract one type of image.Kind struct.
This allows changing the magic bytes, custom compression algorithms, and the Endian-ness of either the Data or Metadata fields.Minimum supported rust version: 1.65.0
Add the following to your Cargo.toml file:
toml
[dependencies]
backhand = "0.13.0"
```rust,no_run use std::fs::File; use std::io::{Cursor, BufReader}; use backhand::{FilesystemReader, FilesystemWriter, NodeHeader};
// read let file = BufReader::new(File::open("file.squashfs").unwrap()); let readfilesystem = FilesystemReader::fromreader(file).unwrap();
// convert to writer let mut writefilesystem = FilesystemWriter::fromfsreader(&readfilesystem).unwrap();
// add file with data from slice let d = NodeHeader::default(); let bytes = Cursor::new(b"Fear is the mind-killer."); writefilesystem.pushfile(bytes, "a/d/e/new_file", d);
// add file with data from file let newfile = File::open("dune").unwrap(); writefilesystem.pushfile(newfile, "/root/dune", d);
// modify file let bytes = Cursor::new(b"The sleeper must awaken.\n"); writefilesystem.replacefile("/a/b/c/d/e/first_file", bytes).unwrap();
// write into a new file let mut output = File::create("modified.squashfs").unwrap(); write_filesystem.write(&mut output).unwrap(); ```
These are currently under development and are missing features, MR's welcome!
To install, run cargo install backhand --locked, or download from the
latest github release.
See --help for more information.
```no_test tool to uncompress, extract and list squashfs filesystems
Usage: unsquashfs [OPTIONS] [FILESYSTEM]
Arguments: [FILESYSTEM] Squashfs file
Options:
-o, --offset
```no_test tool to add a file or directory to squashfs filesystems
Usage: add [OPTIONS]
Arguments:
Options:
-d, --dir Create empty directory
-f, --file
```no_test tool to replace files in squashfs filesystems
Usage: replace [OPTIONS]
Arguments:
Options:
-o, --out
See ./benches using cargo bench to benchmark the library, or run ./bench.bash to benchmark against system squashfs-tools/unsquashfs.
While there is still work to do, in most cases our speed is comparable to single-threaded squashfs-tools/unsquashfs.
Comparing memory usage, our unsquashfs beats squashfs-tools by using 18.1MB instead of 74.8MB in the case of test_re815_xev160/870D97.squashfs.
This library is extensively tested with all library features and images from openwrt and extracted from manufacturers devices.
To run tests, use cargo test --release.
To start fuzzing, run cargo fuzz list then pick one! Then start with cargo fuzz run [NAME].