Skip to content

Commit

Permalink
Merge pull request ReFirmLabs#784 from P1tt1cus/master
Browse files Browse the repository at this point in the history
Minor changes to binwalk error handling
  • Loading branch information
devttys0 authored Nov 30, 2024
2 parents f4716ef + d5598a0 commit 20dbd10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
34 changes: 27 additions & 7 deletions src/binwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ use crate::signatures;

/// Returned on initialization error
#[derive(Debug, Default, Clone)]
pub struct BinwalkError;
pub struct BinwalkError {
pub message: String,
}

impl BinwalkError {
pub fn new(message: &str) -> Self {
BinwalkError {
message: message.to_string(),
}
}
}


/// Analysis results returned by Binwalk::analyze
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -134,8 +145,11 @@ impl Binwalk {
if let Some(target_file) = target_file_name {
// Set the target file path, make it an absolute path
match path::absolute(&target_file) {
Err(_) => {
return Err(BinwalkError);
Err(e) => {
return Err(BinwalkError::new(&format!(
"Failed to get absolute path for '{}'",
target_file
)));
}
Ok(abspath) => {
new_instance.base_target_file = abspath.display().to_string();
Expand All @@ -146,8 +160,11 @@ impl Binwalk {
if let Some(extraction_directory) = output_directory {
// Make the extraction directory an absolute path
match path::absolute(&extraction_directory) {
Err(_) => {
return Err(BinwalkError);
Err(e) => {
return Err(BinwalkError::new(&format!(
"Failed to get absolute path for '{}'",
extraction_directory
)));
}
Ok(abspath) => {
new_instance.base_output_directory = abspath.display().to_string();
Expand All @@ -161,8 +178,11 @@ impl Binwalk {
&new_instance.base_target_file,
&new_instance.base_output_directory,
) {
Err(_) => {
return Err(BinwalkError);
Err(e) => {
return Err(BinwalkError::new( &format!(
"Failed to initialize extraction directory: {}",
e
)));
}
Ok(new_target_file_path) => {
// This is the new base target path (a symlink inside the extraction directory)
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ fn main() {
cliargs.exclude,
None,
cliargs.search_all,
)
.expect("Binwalk initialization failed");
).expect("Binwalk initialization failed");

// If the user specified --threads, honor that request; else, auto-detect available parallelism
let available_workers = cliargs.threads.unwrap_or_else(|| {
Expand Down

0 comments on commit 20dbd10

Please sign in to comment.