https://github.com/wcampbell0x2a/librarium
Library and binaries for the reading, creating, and modification of cpio
https://github.com/wcampbell0x2a/librarium
cpio extraction firmware modification rust
Last synced: 7 months ago
JSON representation
Library and binaries for the reading, creating, and modification of cpio
- Host: GitHub
- URL: https://github.com/wcampbell0x2a/librarium
- Owner: wcampbell0x2a
- License: apache-2.0
- Created: 2022-05-17T04:22:50.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-29T12:18:41.000Z (over 1 year ago)
- Last Synced: 2025-02-01T22:22:30.819Z (over 1 year ago)
- Topics: cpio, extraction, firmware, modification, rust
- Language: Rust
- Homepage:
- Size: 117 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Librarium
===========
[
](https://github.com/wcampbell0x2a/librarium)
[
](https://crates.io/crates/librarium)
[
](https://docs.rs/librarium)
[
](https://github.com/wcampbell0x2a/librarium/actions?query=branch%3Amaster)
[
](https://app.codecov.io/gh/wcampbell0x2a/librarium)
Library and binaries for the reading, creating, and modification of [cpio](https://en.wikipedia.org/wiki/Cpio) archives.
## Library
*Compiler support: requires rustc 1.85+*
Add the following to your `Cargo.toml` file:
```toml
[dependencies]
librarium = "0.4.0"
```
### Read
```rust
use std::ffi::CString;
use std::io::Cursor;
use std::fs::{File, OpenOptions};
use librarium::{Header, ArchiveReader, NewcHeader, CpioReader, CpioHeader};
let mut file = File::open("archive.cpio").unwrap();
let mut archive = ArchiveReader::::from_reader_with_offset(&mut file, 0).unwrap();
// extract bytes from all in archive
for object in &archive.objects.inner {
let mut out = OpenOptions::new()
.write(true)
.create(true)
.open(object.header.as_header().name)
.unwrap();
archive.reader.extract_data(object, &mut out).unwrap();
}
```
### Write
```rust
use std::ffi::CString;
use std::io::Cursor;
use std::fs::File;
use librarium::{Header, ArchiveWriter, NewcHeader};
let file = File::create("archive.cpio").unwrap();
let mut writer = ArchiveWriter::::new(Box::new(file));
// A
let a_data = "a\n".as_bytes();
let a_header = Header { name: "a".to_string(), ..Header::default()};
writer.push_file(Cursor::new(a_data), a_header).unwrap();
// write to archive
writer.write().unwrap();
```
## Binaries
*Compiler support: requires rustc 1.85+*
These are currently under development and are missing features, MR's welcome!
To install, run `cargo install librarium-cli --locked`, or download from the
[latest github release](https://github.com/wcampbell0x2a/librarium/releases/latest).
See ``--help`` for more information.
### uncpio-librarium
```text
tool to extract and list cpio filesystems
Usage: uncpio-librarium [OPTIONS]
Arguments:
cpio path
[possible values: odc, newc]
Options:
-o, --offset Skip BYTES at the start of FILESYSTEM [default: 0]
-d, --dest Extract to [PATHNAME] [default: out]
-h, --help Print help
-V, --version Print version
```
## Development
All patches/merge requests are welcome! See the development guide for more details.
[DEVELOPMENT.md](DEVELOPMENT.md).