-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/issues-41
- Loading branch information
Showing
9 changed files
with
430 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "cfb" | ||
version = "0.8.1" | ||
version = "0.10.0" | ||
authors = ["Matthew D. Steele <[email protected]>"] | ||
description = "Read/write Compound File Binary (structured storage) files" | ||
repository = "https://github.com/mdsteele/rust-cfb" | ||
|
@@ -11,11 +11,11 @@ edition = "2018" | |
|
||
[dependencies] | ||
byteorder = "1" | ||
fnv = "1.0.7" | ||
fnv = "1.0" | ||
uuid = "1" | ||
|
||
[dev-dependencies] | ||
clap = "2.27" | ||
clap = { version = "4.4", features = ["derive"] } | ||
rand = "0.8" | ||
rand_pcg = "0.3" | ||
time = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
use clap::{App, Arg, SubCommand}; | ||
use std::io; | ||
use std::path::PathBuf; | ||
|
||
use clap::{Parser, Subcommand}; | ||
use time::OffsetDateTime; | ||
use uuid::Uuid; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(author, about, long_about = None)] | ||
struct Cli { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
enum Command { | ||
/// Concatenates and prints streams | ||
Cat { path: Vec<String> }, | ||
|
||
/// Changes storage CLSIDs | ||
Chcls { clsid: Uuid, path: Vec<String> }, | ||
|
||
/// Lists storage contents | ||
Ls { | ||
#[clap(short, long)] | ||
/// Lists in long format | ||
long: bool, | ||
|
||
#[clap(short, long)] | ||
/// Includes . in output | ||
all: bool, | ||
|
||
path: Vec<String>, | ||
}, | ||
} | ||
|
||
fn split(path: &str) -> (PathBuf, PathBuf) { | ||
let mut pieces = path.splitn(2, ':'); | ||
if let Some(piece1) = pieces.next() { | ||
|
@@ -51,68 +81,33 @@ fn list_entry(name: &str, entry: &cfb::Entry, long: bool) { | |
} | ||
|
||
fn main() { | ||
let matches = App::new("cfbtool") | ||
.version("0.1") | ||
.author("Matthew D. Steele <[email protected]>") | ||
.about("Inspects and modifies CFB files") | ||
.subcommand( | ||
SubCommand::with_name("cat") | ||
.about("Concatenates and prints streams") | ||
.arg(Arg::with_name("path").multiple(true)), | ||
) | ||
.subcommand( | ||
SubCommand::with_name("chcls") | ||
.about("Changes storage CLSIDs") | ||
.arg(Arg::with_name("clsid").required(true)) | ||
.arg(Arg::with_name("path").multiple(true)), | ||
) | ||
.subcommand( | ||
SubCommand::with_name("ls") | ||
.about("Lists storage contents") | ||
.arg( | ||
Arg::with_name("all") | ||
.short("a") | ||
.help("Includes . in output"), | ||
) | ||
.arg( | ||
Arg::with_name("long") | ||
.short("l") | ||
.help("Lists in long format"), | ||
) | ||
.arg(Arg::with_name("path").multiple(true)), | ||
) | ||
.get_matches(); | ||
if let Some(submatches) = matches.subcommand_matches("cat") { | ||
if let Some(paths) = submatches.values_of("path") { | ||
for path in paths { | ||
let (comp_path, inner_path) = split(path); | ||
let cli = Cli::parse(); | ||
match cli.command { | ||
Command::Cat { path } => { | ||
for path in path { | ||
let (comp_path, inner_path) = split(&path); | ||
let mut comp = cfb::open(&comp_path).unwrap(); | ||
let mut stream = comp.open_stream(inner_path).unwrap(); | ||
io::copy(&mut stream, &mut io::stdout()).unwrap(); | ||
} | ||
} | ||
} else if let Some(submatches) = matches.subcommand_matches("chcls") { | ||
let clsid = | ||
Uuid::parse_str(submatches.value_of("clsid").unwrap()).unwrap(); | ||
if let Some(paths) = submatches.values_of("path") { | ||
for path in paths { | ||
let (comp_path, inner_path) = split(path); | ||
Command::Chcls { clsid, path } => { | ||
for path in path { | ||
let (comp_path, inner_path) = split(&path); | ||
let mut comp = cfb::open(&comp_path).unwrap(); | ||
comp.set_storage_clsid(inner_path, clsid).unwrap(); | ||
comp.flush().unwrap(); | ||
} | ||
} | ||
} else if let Some(submatches) = matches.subcommand_matches("ls") { | ||
if let Some(paths) = submatches.values_of("path") { | ||
let long = submatches.is_present("long"); | ||
for path in paths { | ||
let (comp_path, inner_path) = split(path); | ||
Command::Ls { long, all, path } => { | ||
for path in path { | ||
let (comp_path, inner_path) = split(&path); | ||
let comp = cfb::open(&comp_path).unwrap(); | ||
let entry = comp.entry(&inner_path).unwrap(); | ||
if entry.is_stream() { | ||
list_entry(entry.name(), &entry, long); | ||
} else { | ||
if submatches.is_present("all") { | ||
if all { | ||
list_entry(".", &entry, long); | ||
} | ||
for subentry in comp.read_storage(&inner_path).unwrap() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.