#filesystem #deku #squashfs #linux

bin+lib backhand

Library for the reading, creating, and modification of SquashFS file systems

8 releases (breaking)

0.7.0 Jan 24, 2023
0.6.0 Jan 11, 2023
0.5.0 Jan 9, 2023
0.4.0 Jan 4, 2023
0.1.0 Jan 1, 2023

#196 in Filesystem

Download history 54/week @ 2022-12-28 99/week @ 2023-01-04 45/week @ 2023-01-11 28/week @ 2023-01-18 8/week @ 2023-01-25

217 downloads per month

MIT/Apache

105KB
2.5K SLoC

backhand

github crates.io docs.rs build status

Library and binaries for the reading, creating, and modification of SquashFS file systems.

⚠️ WARNING
The API for this library isn't complete. I will most likely break this for improvements

Library

Add the following to your Cargo.toml file:

[dependencies]
backhand = "0.7.0"

Reading/Writing/Modifying Firmware

use std::fs::File;
use backhand::{Filesystem, FilesystemHeader};

// read
let file = File::open("file.squashfs").unwrap();
let mut filesystem = Filesystem::from_reader(file).unwrap();

// add file with data from slice
let d = FilesystemHeader::default();
let bytes = &mut b"Fear is the mind-killer.".as_slice();
filesystem.push_file(bytes, "a/d/e/new_file", d);

// add file with data from file
let mut new_file = File::open("dune").unwrap();
filesystem.push_file(&mut new_file, "/root/dune", d);

// modify file
let file = filesystem.mut_file("/a/b/c/d/e/first_file").unwrap();
file.bytes = b"The sleeper must awaken.\n".to_vec();

// write
let bytes = filesystem.to_bytes().unwrap();

Testing

This library is tested with unpacking and packing SquashFS firmwares and testing that result with unsquashfs. openwrt binaries are primarily being tested.

Binaries

These are currently under development and are missing features, MR's welcome!

To install, run cargo install backhand.

unsquashfs

tool to uncompress, extract and list squashfs filesystems

Usage: unsquashfs [OPTIONS] <FILESYSTEM>

Arguments:
  <FILESYSTEM>  Squashfs file

Options:
  -o, --offset <BYTES>   Skip BYTES at the start of FILESYSTEM [default: 0]
  -l, --list             List filesystem, do not write to DEST
  -d, --dest <PATHNAME>  Extract to [PATHNAME] [default: squashfs-root]
  -h, --help             Print help information
  -V, --version          Print version information

add

tool to add files to squashfs filesystems

Usage: add <FILESYSTEM> <FILE> <FILE_PATH>

Arguments:
  <FILESYSTEM>  Squashfs file
  <FILE>
  <FILE_PATH>

Options:
  -h, --help     Print help information
  -V, --version  Print version information

Dependencies

~9MB
~176K SLoC