Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
XenorInspire committed Sep 14, 2024
2 parents e360268 + fd614d9 commit 363e2e9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 68 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "worgen_x"
version = "1.2.0"
version = "1.2.1"
edition = "2021"
authors = ["Xen0rInspire"]
license = "GNU General Public License v3.0"
Expand All @@ -16,11 +16,11 @@ gui = []

[dependencies]
rand = { version = "0.8.5", features = ["getrandom"], default-features = false }
thiserror = "1.0.61"
thiserror = "1.0.63"
num_cpus = "1.16.0"
serde_json = { version = "1.0.120", optional = true, features = ["std"], default-features = false }
serde_json = { version = "1.0.128", optional = true, features = ["std"], default-features = false }
indicatif = { version = "0.17.8", default-features = false }
clap = { version = "4.5.9", optional = true, features = ["std"], default-features = false }
clap = { version = "4.5.17", optional = true, features = ["std"], default-features = false }
md-5 = "0.10.6"
sha-1 = "0.10.1"
sha2 = "0.10.8"
Expand Down
26 changes: 10 additions & 16 deletions src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,18 @@ pub fn load_cpu_benchmark(nb_of_threads: u8) -> Result<u64, WorgenXError> {
shared_signal.store(false, Ordering::SeqCst); // Stop the stress test
drop(tx_progress_bar); // Drop the channel to stop the progress bar thread

match progress_bar_thread.join() {
Ok(_) => {}
Err(_) => {
return Err(WorgenXError::SystemError(SystemError::ThreadError(
"Something went wrong with the progress bar thread".to_string(),
)))
}
}
let _ = progress_bar_thread.join().map_err(|_| {
WorgenXError::SystemError(SystemError::ThreadError(
"Something went wrong with the progress bar thread".to_string(),
))
})?;

for thread in threads {
match thread.join() {
Ok(_) => {}
Err(_) => {
return Err(WorgenXError::SystemError(SystemError::ThreadError(
"CPU Benchmark feature".to_string(),
)))
}
}
thread.join().map_err(|_| {
WorgenXError::SystemError(SystemError::ThreadError(
"CPU Benchmark feature".to_string(),
))
})?;
}

let nb_of_passwd: u64 = match shared_passwd_counter.lock() {
Expand Down
37 changes: 18 additions & 19 deletions src/system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Internal crates
use crate::error::{SystemError, WorgenXError};

// Extern crates
// External crates
use blake2::{Blake2b512, Blake2s256};
use digest::Digest;
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -66,9 +66,10 @@ pub fn get_user_choice_yn() -> String {
#[cfg(feature = "gui")]
pub fn get_user_choice() -> String {
let mut buffer: String = String::new();
match stdin().read_line(&mut buffer) {
Ok(_) => buffer.trim().to_string(),
Err(_) => String::new(),
if stdin().read_line(&mut buffer).is_ok() {
buffer.trim().to_string()
} else {
String::new()
}
}

Expand Down Expand Up @@ -278,22 +279,20 @@ pub fn get_elapsed_time(start_time: Instant) -> String {
/// Ok if the passwords have been written to the file, WorgenXError otherwise.
///
pub fn save_passwd_to_file(file: Arc<Mutex<File>>, passwords: String) -> Result<(), WorgenXError> {
let mut file = match file.lock() {
Ok(file) => file,
Err(_) => {
return Err(WorgenXError::SystemError(SystemError::UnableToWriteToFile(
"output file".to_string(),
"Please check the path, the permissions and try again".to_string(),
)))
}
};
match file.write_all(format!("{}\n", passwords).as_bytes()) {
Ok(_) => Ok(()),
Err(_) => Err(WorgenXError::SystemError(SystemError::UnableToWriteToFile(
let mut file = file.lock().map_err(|_| {
WorgenXError::SystemError(SystemError::UnableToWriteToFile(
"output file".to_string(),
"Please check the path, the permissions and try again".to_string(),
))),
}
))
})?;

file.write_all(format!("{}\n", passwords).as_bytes())
.map_err(|_| {
WorgenXError::SystemError(SystemError::UnableToWriteToFile(
"output file".to_string(),
"Please check the path, the permissions and try again".to_string(),
))
})
}

/// This function is charged to return the progress used by the program.
Expand Down Expand Up @@ -510,7 +509,7 @@ mod tests {
assert_eq!(manage_hash(password.clone(), "sha3-512").unwrap(), "e9a75486736a550af4fea861e2378305c4a555a05094dee1dca2f68afea49cc3a50e8de6ea131ea521311f4d6fb054a146e8282f8e35ff2e6368c1a62e909716");
assert_eq!(manage_hash(password.clone(), "blake2s-256").unwrap(), "4c81099df884bd6e14a639d648bccd808512e48af211ae4f44d545ea6d5e5f2b");
assert_eq!(manage_hash(password.clone(), "blake2b-512").unwrap(), "7c863950ac93c93692995e4732ce1e1466ad74a775352ffbaaf2a4a4ce9b549d0b414a1f3150452be6c7c72c694a7cb46f76452917298d33e67611f0a42addb8");
assert_eq!(manage_hash(password.clone(), "whirlpool").unwrap(), "74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae");
assert_eq!(manage_hash(password.clone(), "whirlpool").unwrap(), "74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae");
assert!(manage_hash(password, "sha999").is_err());
}
}
46 changes: 17 additions & 29 deletions src/wordlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const BUFFER_SIZE: usize = 100000;
///
static GLOBAL_COUNTER: Mutex<u64> = Mutex::new(0);

/// This struct is built from the user's choices will be used to generate the wordlist.
/// This struct is built from the user's choices and will be used to generate the wordlist.
///
#[derive(Debug)]
pub struct WordlistValues {
Expand Down Expand Up @@ -113,7 +113,7 @@ fn format_mask_to_indexes(mask: &str) -> (Vec<char>, Vec<usize>) {
formated_mask.push(c);
} else {
mask_indexes.push(idx_formated_mask);
formated_mask.push(0 as char);
formated_mask.push(0u8 as char);
}
}
_ => {
Expand Down Expand Up @@ -171,6 +171,7 @@ pub fn wordlist_generation_scheduler(
let pb: Arc<Mutex<indicatif::ProgressBar>> = Arc::new(Mutex::new(system::get_progress_bar()));
let pb_clone: Arc<Mutex<indicatif::ProgressBar>> = Arc::clone(&pb);
let start: Instant = Instant::now();

let main_thread: JoinHandle<Result<(), WorgenXError>> = thread::spawn(move || {
let mut current_value: u64 = 0;
while current_value < nb_of_passwords {
Expand All @@ -185,28 +186,18 @@ pub fn wordlist_generation_scheduler(
Ok(())
});

match run_wordlist_generation(wordlist_config, nb_of_passwords, nb_of_threads, file_path) {
Ok(_) => (),
Err(e) => {
return Err(e);
}
};
match main_thread.join() {
Ok(_) => (),
Err(e) => {
if let Some(err) = e.downcast_ref::<WorgenXError>() {
return Err(err.clone());
} else {
return Err(WorgenXError::SystemError(SystemError::ThreadError(
format!("{:?}", e),
)));
}
run_wordlist_generation(wordlist_config, nb_of_passwords, nb_of_threads, file_path)?;
if let Err(e) = main_thread.join() {
if let Some(err) = e.downcast_ref::<WorgenXError>() {
return Err(err.clone());
} else {
return Err(WorgenXError::SystemError(SystemError::ThreadError(
format!("{:?}", e),
)));
}
}
println!(
"\nWordlist generated in {}",
system::get_elapsed_time(start)
);

println!("\nWordlist generated in {}", system::get_elapsed_time(start));
Ok(())
}

Expand Down Expand Up @@ -287,13 +278,10 @@ fn run_wordlist_generation(
}

for thread in threads {
match thread.join() {
Ok(_) => {}
Err(_) => {
return Err(WorgenXError::SystemError(SystemError::ThreadError(
"wordlist generation".to_string(),
)))
}
if thread.join().is_err() {
return Err(WorgenXError::SystemError(SystemError::ThreadError(
"wordlist generation".to_string(),
)))
}
}

Expand Down

0 comments on commit 363e2e9

Please sign in to comment.