From 4b4458797d79ba8a6c05c38bd395f7072fd5cee8 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Fri, 1 Nov 2024 10:39:58 -0400 Subject: [PATCH] Added extractor definition tests for m-z --- src/extractors/tarball.rs | 21 +++++++++++++++++++++ src/extractors/trx.rs | 21 +++++++++++++++++++++ src/extractors/ubi.rs | 21 +++++++++++++++++++++ src/extractors/uefi.rs | 23 ++++++++++++++++++++++- src/extractors/uimage.rs | 22 ++++++++++++++++++++++ src/extractors/vxworks.rs | 21 +++++++++++++++++++++ src/extractors/wince.rs | 21 +++++++++++++++++++++ src/extractors/yaffs2.rs | 21 +++++++++++++++++++++ src/extractors/zlib.rs | 21 +++++++++++++++++++++ src/extractors/zstd.rs | 21 +++++++++++++++++++++ 10 files changed, 212 insertions(+), 1 deletion(-) diff --git a/src/extractors/tarball.rs b/src/extractors/tarball.rs index 96ae07fba..f482b77de 100644 --- a/src/extractors/tarball.rs +++ b/src/extractors/tarball.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the tar utility to extract tarball archives +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::tarball::tarball_extractor; +/// +/// match tarball_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 tarball_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("tar".to_string()), diff --git a/src/extractors/trx.rs b/src/extractors/trx.rs index 36bb89b0e..11d627824 100644 --- a/src/extractors/trx.rs +++ b/src/extractors/trx.rs @@ -3,6 +3,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::trx::parse_trx_header; /// Defines the internal TRX extractor +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::trx::trx_extractor; +/// +/// match trx_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 trx_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_trx_partitions), diff --git a/src/extractors/ubi.rs b/src/extractors/ubi.rs index 7aa7893f1..fcad0861d 100644 --- a/src/extractors/ubi.rs +++ b/src/extractors/ubi.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the ubireader_extract_images utility to extract UBI images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::ubi::ubi_extractor; +/// +/// match ubi_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 ubi_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External( diff --git a/src/extractors/uefi.rs b/src/extractors/uefi.rs index 0c901a8e3..90c517653 100644 --- a/src/extractors/uefi.rs +++ b/src/extractors/uefi.rs @@ -1,6 +1,27 @@ use crate::extractors; -/* Describes how to run the uefi-firmware-parser utility to extract UEFI images */ +/// Describes how to run the uefi-firmware-parser utility to extract UEFI images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::uefi::uefi_extractor; +/// +/// match uefi_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 uefi_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("uefi-firmware-parser".to_string()), diff --git a/src/extractors/uimage.rs b/src/extractors/uimage.rs index 35a1195ed..56e54680b 100644 --- a/src/extractors/uimage.rs +++ b/src/extractors/uimage.rs @@ -2,6 +2,28 @@ use crate::common::crc32; use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorType}; use crate::structures::uimage::parse_uimage_header; +/// Describes the internal extractor for carving uImage files to disk +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::uimage::uimage_extractor; +/// +/// match uimage_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 uimage_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_uimage), diff --git a/src/extractors/vxworks.rs b/src/extractors/vxworks.rs index 072714504..6b8dbe9b6 100644 --- a/src/extractors/vxworks.rs +++ b/src/extractors/vxworks.rs @@ -6,6 +6,27 @@ use crate::structures::vxworks::{ use serde_json; /// Describes the VxWorks symbol table extractor +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::vxworks::vxworks_symtab_extractor; +/// +/// match vxworks_symtab_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 vxworks_symtab_extractor() -> Extractor { Extractor { do_not_recurse: true, diff --git a/src/extractors/wince.rs b/src/extractors/wince.rs index 243661409..509db92bf 100644 --- a/src/extractors/wince.rs +++ b/src/extractors/wince.rs @@ -3,6 +3,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::wince::{parse_wince_block_header, parse_wince_header}; /// Defines the internal extractor function for extracting Windows CE images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::wince::wince_extractor; +/// +/// match wince_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 wince_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(wince_dump), diff --git a/src/extractors/yaffs2.rs b/src/extractors/yaffs2.rs index 4e514fbae..d8b1f6316 100644 --- a/src/extractors/yaffs2.rs +++ b/src/extractors/yaffs2.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the unyaffs utility to extract YAFFS2 file systems +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::yaffs2::yaffs2_extractor; +/// +/// match yaffs2_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 yaffs2_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("unyaffs".to_string()), diff --git a/src/extractors/zlib.rs b/src/extractors/zlib.rs index 513ade44a..e6d99bd95 100644 --- a/src/extractors/zlib.rs +++ b/src/extractors/zlib.rs @@ -5,6 +5,27 @@ use crate::extractors::inflate; pub const CHECKSUM_SIZE: usize = 4; /// Defines the internal extractor function for decompressing zlib data +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::zlib::zlib_extractor; +/// +/// match zlib_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 zlib_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(zlib_decompress), diff --git a/src/extractors/zstd.rs b/src/extractors/zstd.rs index c7632a617..8cf1fec9f 100644 --- a/src/extractors/zstd.rs +++ b/src/extractors/zstd.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the zstd utility to extract ZSTD compressed files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::zstd::zstd_extractor; +/// +/// match zstd_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 zstd_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("zstd".to_string()),