Skip to content

Commit

Permalink
Added extractor definition tests for l-s
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed Nov 1, 2024
1 parent 92f7a13 commit eaf8780
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/extractors/linux.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/lz4.rs
Original file line number Diff line number Diff line change
@@ -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()),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/lzfse.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
21 changes: 21 additions & 0 deletions src/extractors/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/lzop.rs
Original file line number Diff line number Diff line change
@@ -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()),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/mbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/pcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 42 additions & 0 deletions src/extractors/pem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/rar.rs
Original file line number Diff line number Diff line change
@@ -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()),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/riff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/romfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 21 additions & 0 deletions src/extractors/sevenzip.rs
Original file line number Diff line number Diff line change
@@ -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()),
Expand Down
Loading

0 comments on commit eaf8780

Please sign in to comment.