From f851e9c42470385ab2540dbb82fac3be45bba509 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 1 Nov 2023 13:29:30 +0100 Subject: [PATCH] Add optional OSB alternative password parameter --- src/cli.rs | 10 +++++++++- src/main.rs | 8 ++++++-- src/unzip_osb.rs | 10 ++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 932bc3a..cbdfd2d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, + }, } diff --git a/src/main.rs b/src/main.rs index e3a4dbb..21194e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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> { }; } #[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()), + } } }; diff --git a/src/unzip_osb.rs b/src/unzip_osb.rs index 676fea1..334517b 100644 --- a/src/unzip_osb.rs +++ b/src/unzip_osb.rs @@ -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()); +}