1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 19:56:50 +00:00

Add optional OSB alternative password parameter

This commit is contained in:
Paul-Christian Volkmer 2023-11-01 13:29:30 +01:00
parent 7ef1638b58
commit f851e9c424
3 changed files with 21 additions and 7 deletions

View File

@ -103,5 +103,13 @@ pub enum SubCommand {
},
#[cfg(feature = "unzip-osb")]
#[command(about = "Entpackt eine OSB-Datei")]
UnzipOsb { file: String },
UnzipOsb {
file: String,
#[arg(
short = 'p',
long = "password",
help = "Passwort der OSB-Datei (Optional)"
)]
password: Option<String>,
},
}

View File

@ -41,6 +41,7 @@ use sha256::digest;
use crate::cli::{Cli, SubCommand};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::profile::Profile;
use crate::unzip_osb::unzip_osb_using_password;
mod cli;
mod model;
@ -258,9 +259,12 @@ fn main() -> Result<(), Box<dyn Error>> {
};
}
#[cfg(feature = "unzip-osb")]
SubCommand::UnzipOsb { file } => {
SubCommand::UnzipOsb { file, password } => {
use crate::unzip_osb::unzip_osb;
unzip_osb(file.as_str())
match password {
Some(password) => unzip_osb_using_password(file.as_str(), password.as_str()),
None => unzip_osb(file.as_str()),
}
}
};

View File

@ -48,11 +48,9 @@ macro_rules! error {
};
}
pub fn unzip_osb(path: &str) {
pub fn unzip_osb_using_password(path: &str, password: &str) {
println!("Entpacke OSB-Datei {}\n", style(path).yellow());
let pw = deobfuscate(env!("OSB_KEY").trim());
let file = match fs::File::open(path) {
Ok(file) => file,
Err(err) => {
@ -78,7 +76,7 @@ pub fn unzip_osb(path: &str) {
};
for i in 0..archive.len() {
let mut file = if let Ok(Ok(file)) = archive.by_index_decrypt(i, pw.as_bytes()) {
let mut file = if let Ok(Ok(file)) = archive.by_index_decrypt(i, password.as_bytes()) {
file
} else {
println!(
@ -130,3 +128,7 @@ pub fn unzip_osb(path: &str) {
}
}
}
pub fn unzip_osb(path: &str) {
unzip_osb_using_password(path, deobfuscate(env!("OSB_KEY").trim()).as_str());
}