|
|
@ -47,7 +47,7 @@ fn usage() -> ! {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let prog = &arg::program_name();
|
|
|
|
let prog = &arg::program_name();
|
|
|
|
version(true);
|
|
|
|
version(true);
|
|
|
|
println!("Usage: {} [-s] [-e <exec string>] [-o <output file>] [-] <files...>", prog);
|
|
|
|
println!("Usage: {} [-s] [-e <exec string>] [-o <output file>] [-u] [-] <files...>", prog);
|
|
|
|
println!("Usage: {} -h", prog);
|
|
|
|
println!("Usage: {} -h", prog);
|
|
|
|
println!("Usage: {} -v|-V", prog);
|
|
|
|
println!("Usage: {} -v|-V", prog);
|
|
|
|
println!();
|
|
|
|
println!();
|
|
|
@ -58,6 +58,10 @@ fn usage() -> ! {
|
|
|
|
println!(" -s\t\tSilent mode.");
|
|
|
|
println!(" -s\t\tSilent mode.");
|
|
|
|
println!(" -e <exec>\tScript to run after extraction.");
|
|
|
|
println!(" -e <exec>\tScript to run after extraction.");
|
|
|
|
println!(" -o <file>\tOutput filename.");
|
|
|
|
println!(" -o <file>\tOutput filename.");
|
|
|
|
|
|
|
|
#[cfg(feature = "hash")]
|
|
|
|
|
|
|
|
println!(" -u\t\tUnchecked mode. Do not compute hashes of inputs.");
|
|
|
|
|
|
|
|
#[cfg(not(feature = "hash"))]
|
|
|
|
|
|
|
|
println!(" -u\t\tUnchecked mode. (default as generator is not compiled with `hash` feature).");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::process::exit(1)
|
|
|
|
std::process::exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -67,7 +71,11 @@ type Sha256Hash = [u8; 32];
|
|
|
|
#[cfg(not(feature = "hash"))]
|
|
|
|
#[cfg(not(feature = "hash"))]
|
|
|
|
type Sha256Hash = ();
|
|
|
|
type Sha256Hash = ();
|
|
|
|
|
|
|
|
|
|
|
|
fn write_file<From, To>(from: From, to: &mut To) -> io::Result<(Sha256Hash, usize)>
|
|
|
|
const WF_BUFFER_SIZE: usize = 1024;
|
|
|
|
|
|
|
|
const WF_GROUP_SIZE: usize = 16;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
|
|
|
|
fn write_file<From, To>(from: From, to: &mut To, hash: bool) -> io::Result<(Sha256Hash, usize)>
|
|
|
|
where From: Read,
|
|
|
|
where From: Read,
|
|
|
|
To: Write + ?Sized
|
|
|
|
To: Write + ?Sized
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -78,25 +86,32 @@ where From: Read,
|
|
|
|
let mut hash_output = [0u8; 32];
|
|
|
|
let mut hash_output = [0u8; 32];
|
|
|
|
let mut count =0;
|
|
|
|
let mut count =0;
|
|
|
|
let mut digest = Sha256::new();
|
|
|
|
let mut digest = Sha256::new();
|
|
|
|
for buf in from.into_iter(8)
|
|
|
|
let lambda: Box<dyn FnMut(u8) -> String> = if hash {
|
|
|
|
.map(|byte| (digest.input(&[byte]), format!("0x{:02x},", byte)).1)
|
|
|
|
Box::new(|byte| (digest.input(&[byte]), format!("0x{:02x},", byte)).1)
|
|
|
|
.group_at(8)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Box::new(|byte| format!("0x{:02x},", byte))
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
for buf in from.into_iter(WF_BUFFER_SIZE)
|
|
|
|
|
|
|
|
.map(lambda)
|
|
|
|
|
|
|
|
.group_at(WF_GROUP_SIZE)
|
|
|
|
.map(|bytes| (count += bytes.len(), bytes).1)
|
|
|
|
.map(|bytes| (count += bytes.len(), bytes).1)
|
|
|
|
.map(|strs| format!("\t{}", strs.join(" ")))
|
|
|
|
.map(|strs| format!("\t{}", strs.join(" ")))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
writeln!(to, "{}", buf)?;
|
|
|
|
writeln!(to, "{}", buf)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
copy_slice(&mut hash_output[..], &digest.result()[..]);
|
|
|
|
if hash {
|
|
|
|
|
|
|
|
copy_slice(&mut hash_output[..], &digest.result()[..]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok((hash_output, count))
|
|
|
|
Ok((hash_output, count))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "hash"))]
|
|
|
|
#[cfg(not(feature = "hash"))]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut count =0;
|
|
|
|
let mut count =0;
|
|
|
|
for buf in from.into_iter(8)
|
|
|
|
for buf in from.into_iter(WF_BUFFER_SIZE)
|
|
|
|
.map(|byte| format!("0x{:02x},", byte))
|
|
|
|
.map(|byte| format!("0x{:02x},", byte))
|
|
|
|
.group_at(8)
|
|
|
|
.group_at(WF_GROUP_SIZE)
|
|
|
|
.map(|bytes| (count += bytes.len(), bytes).1)
|
|
|
|
.map(|bytes| (count += bytes.len(), bytes).1)
|
|
|
|
.map(|strs| format!("\t{}", strs.join(" ")))
|
|
|
|
.map(|strs| format!("\t{}", strs.join(" ")))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -152,6 +167,7 @@ fn main() -> Result<(), Box<dyn Error>>
|
|
|
|
_ => None
|
|
|
|
_ => None
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let silent = options.has_tag(&Opt::Silent);
|
|
|
|
let silent = options.has_tag(&Opt::Silent);
|
|
|
|
|
|
|
|
let no_hash = options.has_tag(&Opt::NoHash);
|
|
|
|
|
|
|
|
|
|
|
|
println!("Writing to {}...", output);
|
|
|
|
println!("Writing to {}...", output);
|
|
|
|
let mut fp = OpenOptions::new()
|
|
|
|
let mut fp = OpenOptions::new()
|
|
|
@ -187,7 +203,7 @@ fn main() -> Result<(), Box<dyn Error>>
|
|
|
|
.read(true)
|
|
|
|
.read(true)
|
|
|
|
.open(file)?;
|
|
|
|
.open(file)?;
|
|
|
|
|
|
|
|
|
|
|
|
sizes.push(match write_file(file, &mut fp) {
|
|
|
|
sizes.push(match write_file(file, &mut fp, !no_hash) {
|
|
|
|
Ok((hash, size)) => {
|
|
|
|
Ok((hash, size)) => {
|
|
|
|
hashes.push(hash);
|
|
|
|
hashes.push(hash);
|
|
|
|
println!(" OK");
|
|
|
|
println!(" OK");
|
|
|
@ -211,6 +227,7 @@ fn main() -> Result<(), Box<dyn Error>>
|
|
|
|
writeln!(fp, "\n}};")?;
|
|
|
|
writeln!(fp, "\n}};")?;
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature="hash")]
|
|
|
|
#[cfg(feature="hash")]
|
|
|
|
|
|
|
|
if !no_hash
|
|
|
|
{
|
|
|
|
{
|
|
|
|
println!("Adding hashes...");
|
|
|
|
println!("Adding hashes...");
|
|
|
|
writeln!(fp, "#define DATA_HASHED")?;
|
|
|
|
writeln!(fp, "#define DATA_HASHED")?;
|
|
|
@ -237,7 +254,7 @@ fn main() -> Result<(), Box<dyn Error>>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
match write!(fp, "\t\"{}\",", translate::c_escape(file)) {
|
|
|
|
match writeln!(fp, "\t\"{}\",", translate::c_escape(file)) {
|
|
|
|
Err(error) => {
|
|
|
|
Err(error) => {
|
|
|
|
println!(" FAILED: write: {}", error);
|
|
|
|
println!(" FAILED: write: {}", error);
|
|
|
|
|
|
|
|
|
|
|
@ -247,7 +264,7 @@ fn main() -> Result<(), Box<dyn Error>>
|
|
|
|
};
|
|
|
|
};
|
|
|
|
println!(" OK");
|
|
|
|
println!(" OK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeln!(fp, "\n}};")?;
|
|
|
|
writeln!(fp, "}};")?;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
arg::OperationMode::Help => {
|
|
|
|
arg::OperationMode::Help => {
|
|
|
|
usage();
|
|
|
|
usage();
|
|
|
|