From 40111215a8adc39f2018a832a91d3ba6e5b9c491 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Fri, 1 Nov 2024 10:10:46 -0400 Subject: [PATCH 1/4] Added extraction utility existence tests for extractors a-c --- src/extractors/androidsparse.rs | 23 ++++++++++++++++++++++- src/extractors/apfs.rs | 21 +++++++++++++++++++++ src/extractors/arcadyan.rs | 21 +++++++++++++++++++++ src/extractors/autel.rs | 21 +++++++++++++++++++++ src/extractors/bzip2.rs | 21 +++++++++++++++++++++ src/extractors/cab.rs | 21 +++++++++++++++++++++ src/extractors/dtb.rs | 21 +++++++++++++++++++++ 7 files changed, 148 insertions(+), 1 deletion(-) diff --git a/src/extractors/androidsparse.rs b/src/extractors/androidsparse.rs index cd98e189f..755ccceb8 100644 --- a/src/extractors/androidsparse.rs +++ b/src/extractors/androidsparse.rs @@ -2,7 +2,28 @@ use crate::common::is_offset_safe; use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorType}; use crate::structures::androidsparse; -/// Defines the internal extractor function for decompressing zlib data +/// Defines the internal extractor function for extracting Android Sparse files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::androidsparse::android_sparse_extractor; +/// +/// match android_sparse_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 android_sparse_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_android_sparse), diff --git a/src/extractors/apfs.rs b/src/extractors/apfs.rs index 3445162e9..cc6b2771a 100644 --- a/src/extractors/apfs.rs +++ b/src/extractors/apfs.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the 7zzs utility to extract APFS images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::apfs::apfs_extractor; +/// +/// match apfs_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 apfs_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("7zzs".to_string()), diff --git a/src/extractors/arcadyan.rs b/src/extractors/arcadyan.rs index 456616030..dec1f7474 100644 --- a/src/extractors/arcadyan.rs +++ b/src/extractors/arcadyan.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{ExtractionResult, Extractor, ExtractorType}; use crate::extractors::lzma::lzma_decompress; /// Defines the internal extractor for Arcadyn Obfuscated LZMA +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::arcadyan::obfuscated_lzma_extractor; +/// +/// match obfuscated_lzma_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 obfuscated_lzma_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_obfuscated_lzma), diff --git a/src/extractors/autel.rs b/src/extractors/autel.rs index f18e34f67..05f681a56 100644 --- a/src/extractors/autel.rs +++ b/src/extractors/autel.rs @@ -4,6 +4,27 @@ use crate::structures::autel::parse_autel_header; const BLOCK_SIZE: usize = 256; /// Defines the internal extractor function for deobfuscating Autel firmware +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::autel::autel_extractor; +/// +/// match autel_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 autel_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(autel_deobfuscate), diff --git a/src/extractors/bzip2.rs b/src/extractors/bzip2.rs index 1aa861c47..15b68856e 100644 --- a/src/extractors/bzip2.rs +++ b/src/extractors/bzip2.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use bzip2::{Decompress, Status}; /// Defines the internal extractor function for decompressing BZIP2 files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::bzip2::bzip2_extractor; +/// +/// match bzip2_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 bzip2_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(bzip2_decompressor), diff --git a/src/extractors/cab.rs b/src/extractors/cab.rs index 4e800dcf2..bdddda932 100644 --- a/src/extractors/cab.rs +++ b/src/extractors/cab.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the cabextract utility to extract MS CAB archives +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::cab::cab_extractor; +/// +/// match cab_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 cab_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("cabextract".to_string()), diff --git a/src/extractors/dtb.rs b/src/extractors/dtb.rs index 364ff5287..1753ca0ab 100644 --- a/src/extractors/dtb.rs +++ b/src/extractors/dtb.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the dtc utility to extract DTB files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::dtb::dtb_extractor; +/// +/// match dtb_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 dtb_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("dtc".to_string()), From 92f7a13590760702168a0989d8aa8f7b348ffdd7 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Fri, 1 Nov 2024 10:20:07 -0400 Subject: [PATCH 2/4] Added extractor definition tests for d-j --- src/extractors/dmg.rs | 21 +++++++++++++++++++++ src/extractors/dumpifs.rs | 21 +++++++++++++++++++++ src/extractors/gif.rs | 21 +++++++++++++++++++++ src/extractors/gzip.rs | 21 +++++++++++++++++++++ src/extractors/jboot.rs | 21 +++++++++++++++++++++ src/extractors/jffs2.rs | 21 +++++++++++++++++++++ src/extractors/jpeg.rs | 21 +++++++++++++++++++++ 7 files changed, 147 insertions(+) diff --git a/src/extractors/dmg.rs b/src/extractors/dmg.rs index d75e091c0..c1bf54614 100644 --- a/src/extractors/dmg.rs +++ b/src/extractors/dmg.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the dmg2img utility to convert DMG images to MBR +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::dmg::dmg_extractor; +/// +/// match dmg_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 dmg_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("dmg2img".to_string()), diff --git a/src/extractors/dumpifs.rs b/src/extractors/dumpifs.rs index 9f6de0c19..90df3f457 100644 --- a/src/extractors/dumpifs.rs +++ b/src/extractors/dumpifs.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the dumpifs utility to extract QNX IFS images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::dumpifs::dumpifs_extractor; +/// +/// match dumpifs_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 dumpifs_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("dumpifs".to_string()), diff --git a/src/extractors/gif.rs b/src/extractors/gif.rs index d9a0253ec..0ec4beaa8 100644 --- a/src/extractors/gif.rs +++ b/src/extractors/gif.rs @@ -4,6 +4,27 @@ use crate::structures::common::StructureError; use crate::structures::gif::{parse_gif_extension, parse_gif_header, parse_gif_image_descriptor}; /// Defines the internal extractor function for carving out JPEG images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::gif::gif_extractor; +/// +/// match gif_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 gif_extractor() -> Extractor { Extractor { do_not_recurse: true, diff --git a/src/extractors/gzip.rs b/src/extractors/gzip.rs index 4ec01ecf5..b7a3004c0 100644 --- a/src/extractors/gzip.rs +++ b/src/extractors/gzip.rs @@ -3,6 +3,27 @@ use crate::extractors::inflate; use crate::structures::gzip::parse_gzip_header; /// Defines the internal extractor function for decompressing gzip data +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::gzip::gzip_extractor; +/// +/// match gzip_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 gzip_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(gzip_decompress), diff --git a/src/extractors/jboot.rs b/src/extractors/jboot.rs index 148188ade..77a6ed154 100644 --- a/src/extractors/jboot.rs +++ b/src/extractors/jboot.rs @@ -3,6 +3,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::jboot::parse_jboot_sch2_header; /// Defines the internal extractor function for carving out JBOOT SCH2 kernels +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::jboot::sch2_extractor; +/// +/// match sch2_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 sch2_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_jboot_sch2_kernel), diff --git a/src/extractors/jffs2.rs b/src/extractors/jffs2.rs index 9c8185e97..e0875fe5b 100644 --- a/src/extractors/jffs2.rs +++ b/src/extractors/jffs2.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the jefferson utility to extract JFFS file systems +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::jffs2::jffs2_extractor; +/// +/// match jffs2_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 jffs2_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("jefferson".to_string()), diff --git a/src/extractors/jpeg.rs b/src/extractors/jpeg.rs index 6458d7406..99c5d6e0c 100644 --- a/src/extractors/jpeg.rs +++ b/src/extractors/jpeg.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use aho_corasick::AhoCorasick; /// Defines the internal extractor function for carving out JPEG images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::jpeg::jpeg_extractor; +/// +/// match jpeg_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 jpeg_extractor() -> Extractor { Extractor { do_not_recurse: true, From eaf87808d42acb3fbad897eda8d6a2e257687484 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Fri, 1 Nov 2024 10:35:38 -0400 Subject: [PATCH 3/4] Added extractor definition tests for l-s --- src/extractors/linux.rs | 21 +++++++++++++++++++ src/extractors/lz4.rs | 21 +++++++++++++++++++ src/extractors/lzfse.rs | 21 +++++++++++++++++++ src/extractors/lzma.rs | 21 +++++++++++++++++++ src/extractors/lzop.rs | 21 +++++++++++++++++++ src/extractors/mbr.rs | 21 +++++++++++++++++++ src/extractors/pcap.rs | 21 +++++++++++++++++++ src/extractors/pem.rs | 42 ++++++++++++++++++++++++++++++++++++++ src/extractors/png.rs | 21 +++++++++++++++++++ src/extractors/rar.rs | 21 +++++++++++++++++++ src/extractors/riff.rs | 21 +++++++++++++++++++ src/extractors/romfs.rs | 21 +++++++++++++++++++ src/extractors/sevenzip.rs | 21 +++++++++++++++++++ src/extractors/squashfs.rs | 42 ++++++++++++++++++++++++++++++++++++++ src/extractors/srec.rs | 21 +++++++++++++++++++ src/extractors/svg.rs | 21 +++++++++++++++++++ 16 files changed, 378 insertions(+) diff --git a/src/extractors/linux.rs b/src/extractors/linux.rs index c939fb6b0..bf6020fe6 100644 --- a/src/extractors/linux.rs +++ b/src/extractors/linux.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the vmlinux-to-elf utility to convert raw kernel images to ELF files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::linux::linux_kernel_extractor; +/// +/// match linux_kernel_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 linux_kernel_extractor() -> extractors::common::Extractor { extractors::common::Extractor { do_not_recurse: true, diff --git a/src/extractors/lz4.rs b/src/extractors/lz4.rs index 8d6992982..f45aaacd2 100644 --- a/src/extractors/lz4.rs +++ b/src/extractors/lz4.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the lz4 utility to extract LZ4 compressed files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::lz4::lz4_extractor; +/// +/// match lz4_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 lz4_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("lz4".to_string()), diff --git a/src/extractors/lzfse.rs b/src/extractors/lzfse.rs index ca553aba0..2eb2d4b7c 100644 --- a/src/extractors/lzfse.rs +++ b/src/extractors/lzfse.rs @@ -1,6 +1,27 @@ use crate::extractors::common::{Extractor, ExtractorType, SOURCE_FILE_PLACEHOLDER}; /// Describes how to run the lzfse utility to decompress LZFSE files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::lzfse::lzfse_extractor; +/// +/// match lzfse_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 lzfse_extractor() -> Extractor { const OUTPUT_FILE_NAME: &str = "decompressed.bin"; diff --git a/src/extractors/lzma.rs b/src/extractors/lzma.rs index d19531e35..3796bd559 100644 --- a/src/extractors/lzma.rs +++ b/src/extractors/lzma.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use xz2::stream::{Action, Status, Stream}; /// Defines the internal extractor function for decompressing LZMA/XZ data +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::lzma::lzma_extractor; +/// +/// match lzma_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 lzma_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(lzma_decompress), diff --git a/src/extractors/lzop.rs b/src/extractors/lzop.rs index 6fd0487e5..b5cb6b788 100644 --- a/src/extractors/lzop.rs +++ b/src/extractors/lzop.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the lzop utility to extract LZO compressed files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::lzop::lzop_extractor; +/// +/// match lzop_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 lzop_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("lzop".to_string()), diff --git a/src/extractors/mbr.rs b/src/extractors/mbr.rs index 6d47086da..99527a7c9 100644 --- a/src/extractors/mbr.rs +++ b/src/extractors/mbr.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::mbr::parse_mbr_image; /// Defines the internal extractor function for MBR partitions +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::mbr::mbr_extractor; +/// +/// match mbr_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 mbr_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_mbr_partitions), diff --git a/src/extractors/pcap.rs b/src/extractors/pcap.rs index c0c899db9..01a9eb954 100644 --- a/src/extractors/pcap.rs +++ b/src/extractors/pcap.rs @@ -3,6 +3,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::pcap::{parse_pcapng_block, parse_pcapng_section_block}; /// Defines the internal extractor function for extracting pcap-ng files +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::pcap::pcapng_extractor; +/// +/// match pcapng_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 pcapng_extractor() -> Extractor { Extractor { do_not_recurse: true, diff --git a/src/extractors/pem.rs b/src/extractors/pem.rs index 7857bd24d..e58ad70bc 100644 --- a/src/extractors/pem.rs +++ b/src/extractors/pem.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use aho_corasick::AhoCorasick; /// Defines the internal extractor function for carving out PEM keys +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::pem::pem_key_extractor; +/// +/// match pem_key_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 pem_key_extractor() -> Extractor { Extractor { do_not_recurse: true, @@ -11,6 +32,27 @@ pub fn pem_key_extractor() -> Extractor { } /// Internal extractor function for carving out PEM certs +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::pem::pem_certificate_extractor; +/// +/// match pem_certificate_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 pem_certificate_extractor() -> Extractor { Extractor { do_not_recurse: true, diff --git a/src/extractors/png.rs b/src/extractors/png.rs index 06e5531ea..5f7a3fc6b 100644 --- a/src/extractors/png.rs +++ b/src/extractors/png.rs @@ -3,6 +3,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::png::parse_png_chunk_header; /// Defines the internal extractor function for carving out PNG images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::png::png_extractor; +/// +/// match png_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 png_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_png_image), diff --git a/src/extractors/rar.rs b/src/extractors/rar.rs index 8441807c7..a2bd47d78 100644 --- a/src/extractors/rar.rs +++ b/src/extractors/rar.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the unrar utility to extract RAR archives +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::rar::rar_extractor; +/// +/// match rar_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 rar_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("unrar".to_string()), diff --git a/src/extractors/riff.rs b/src/extractors/riff.rs index 0fe6be828..52ecee5c5 100644 --- a/src/extractors/riff.rs +++ b/src/extractors/riff.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::riff::parse_riff_header; /// Describes the internal RIFF image extactor +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::riff::riff_extractor; +/// +/// match riff_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 riff_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_riff_image), diff --git a/src/extractors/romfs.rs b/src/extractors/romfs.rs index 58e879fa1..a7a9116b5 100644 --- a/src/extractors/romfs.rs +++ b/src/extractors/romfs.rs @@ -27,6 +27,27 @@ struct RomFSEntry { } /// Defines the internal extractor function for extracting RomFS file systems */ +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::romfs::romfs_extractor; +/// +/// match romfs_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 romfs_extractor() -> Extractor { Extractor { utility: ExtractorType::Internal(extract_romfs), diff --git a/src/extractors/sevenzip.rs b/src/extractors/sevenzip.rs index 3de64dccd..a67509eeb 100644 --- a/src/extractors/sevenzip.rs +++ b/src/extractors/sevenzip.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the 7z utility, supports multiple file formats +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::sevenzip::sevenzip_extractor; +/// +/// match sevenzip_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 sevenzip_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("7z".to_string()), diff --git a/src/extractors/squashfs.rs b/src/extractors/squashfs.rs index 4f8c871a6..4747d541f 100644 --- a/src/extractors/squashfs.rs +++ b/src/extractors/squashfs.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the sasquatch utility to extract SquashFS images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::squashfs::squashfs_extractor; +/// +/// match squashfs_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 squashfs_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("sasquatch".to_string()), @@ -13,6 +34,27 @@ pub fn squashfs_extractor() -> extractors::common::Extractor { } /// Describes how to run the sasquatch-v4be utility to extract big endian SquashFSv4 images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::squashfs::squashfs_v4_be_extractor; +/// +/// match squashfs_v4_be_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 squashfs_v4_be_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("sasquatch-v4be".to_string()), diff --git a/src/extractors/srec.rs b/src/extractors/srec.rs index 0bc049d30..392833c0d 100644 --- a/src/extractors/srec.rs +++ b/src/extractors/srec.rs @@ -1,6 +1,27 @@ use crate::extractors; /// Describes how to run the srec2bin utility to convert Motorola S-records to binary +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::srec::srec_extractor; +/// +/// match srec_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 srec_extractor() -> extractors::common::Extractor { extractors::common::Extractor { utility: extractors::common::ExtractorType::External("srec2bin".to_string()), diff --git a/src/extractors/svg.rs b/src/extractors/svg.rs index d7846e2a5..287788d83 100644 --- a/src/extractors/svg.rs +++ b/src/extractors/svg.rs @@ -2,6 +2,27 @@ use crate::extractors::common::{Chroot, ExtractionResult, Extractor, ExtractorTy use crate::structures::svg::parse_svg_image; /// Defines the internal extractor function for carving out SVG images +/// +/// ``` +/// use std::io::ErrorKind; +/// use std::process::Command; +/// use binwalk::extractors::common::ExtractorType; +/// use binwalk::extractors::svg::svg_extractor; +/// +/// match svg_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 svg_extractor() -> Extractor { Extractor { do_not_recurse: true, From 4b4458797d79ba8a6c05c38bd395f7072fd5cee8 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Fri, 1 Nov 2024 10:39:58 -0400 Subject: [PATCH 4/4] 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()),