From d0fdf9253e770686ef0495c1683664167ce2cc67 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Sun, 22 Dec 2024 13:24:58 -0500 Subject: [PATCH] Updated ISO extractor to support more ISO sub-types --- src/extractors.rs | 1 + src/extractors/iso9660.rs | 32 ++++++++++++++++++++++++++++++++ src/magic.rs | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/extractors/iso9660.rs diff --git a/src/extractors.rs b/src/extractors.rs index fa746a5ba..b9c16a761 100644 --- a/src/extractors.rs +++ b/src/extractors.rs @@ -158,6 +158,7 @@ pub mod gif; pub mod gpg; pub mod gzip; pub mod inflate; +pub mod iso9660; pub mod jboot; pub mod jffs2; pub mod jpeg; diff --git a/src/extractors/iso9660.rs b/src/extractors/iso9660.rs new file mode 100644 index 000000000..9ee18a96a --- /dev/null +++ b/src/extractors/iso9660.rs @@ -0,0 +1,32 @@ +use crate::extractors; +use crate::extractors::sevenzip::sevenzip_extractor; + +/// Describes how to run the 7z utility to extract ISO images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::iso9660::iso9660_extractor; +/// +/// match iso9660_extractor().utility { +/// ExtractorType::None => panic!("Invalid extractor type of None"), +/// ExtractorType::Internal(func) => println!("Internal extractor OK: {:?}", func), +/// ExtractorType::External(cmd) => { +/// if let Err(e) = Command::new(&cmd).output() { +/// if e.kind() == ErrorKind::NotFound { +/// panic!("External extractor '{}' not found", cmd); +/// } else { +/// panic!("Failed to execute external extractor '{}': {}", cmd, e); +/// } +/// } +/// } +/// } +/// ``` +pub fn iso9660_extractor() -> extractors::common::Extractor { + // Same as the normal 7z extractor, but give the carved file an ISO file extension. + // The file extension matters, and 7z doesn't handle some ISO sub-formats correctly if the file extension is not '.iso'. + let mut extractor = sevenzip_extractor(); + extractor.extension = "iso".to_string(); + extractor +} diff --git a/src/magic.rs b/src/magic.rs index 1861c6b96..ce06da42a 100644 --- a/src/magic.rs +++ b/src/magic.rs @@ -168,7 +168,7 @@ pub fn patterns() -> Vec { magic: signatures::iso9660::iso_magic(), parser: signatures::iso9660::iso_parser, description: signatures::iso9660::DESCRIPTION.to_string(), - extractor: Some(extractors::tsk::tsk_extractor()), + extractor: Some(extractors::iso9660::iso9660_extractor()), }, // linux kernel signatures::common::Signature {