From 27eb641366819cbdd2c02228b884e8673bc37c2b Mon Sep 17 00:00:00 2001 From: devttys0 Date: Sat, 30 Nov 2024 12:14:06 -0500 Subject: [PATCH] Updated tests --- src/binwalk.rs | 6 ++++-- src/common.rs | 2 +- tests/common/mod.rs | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/binwalk.rs b/src/binwalk.rs index ac6bd5935..0e991e00f 100644 --- a/src/binwalk.rs +++ b/src/binwalk.rs @@ -675,7 +675,7 @@ impl Binwalk { /// /// ``` /// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_binwalk_rs_624_0() -> Result { - /// use binwalk::Binwalk; + /// use binwalk::{Binwalk, common}; /// /// let target_path = std::path::Path::new("tests") /// .join("inputs") @@ -688,6 +688,8 @@ impl Binwalk { /// .display() /// .to_string(); /// + /// let file_data = common::read_file(&target_path, false).expect("Failed to read file data"); + /// /// # std::fs::remove_dir_all(&extraction_directory); /// let binwalker = Binwalk::configure(Some(target_path), /// Some(extraction_directory.clone()), @@ -696,7 +698,7 @@ impl Binwalk { /// None, /// false)?; /// - /// let analysis_results = binwalker.analyze(&binwalker.base_target_file, true); + /// let analysis_results = binwalker.analyze(&file_data, &binwalker.base_target_file, true); /// /// assert_eq!(analysis_results.file_map.len(), 1); /// assert_eq!(analysis_results.extractions.len(), 1); diff --git a/src/common.rs b/src/common.rs index 0dce84b4f..3e919b18d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,7 +12,7 @@ use std::io::Read; /// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_common_rs_11_0() -> Result<(), Box> { /// use binwalk::common::read_file; /// -/// let file_data = read_file("/etc/passwd")?; +/// let file_data = read_file("/etc/passwd", false)?; /// assert!(file_data.len() > 0); /// # Ok(()) /// # } _doctest_main_src_common_rs_11_0(); } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0ff9a99a9..861771c72 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,4 +1,4 @@ -use binwalk::{AnalysisResults, Binwalk}; +use binwalk::{common, AnalysisResults, Binwalk}; /// Convenience function for running an integration test against the specified file, with the provided signature filter. /// Assumes that there will be one signature result and one extraction result at file offset 0. @@ -55,6 +55,9 @@ pub fn run_binwalk(signature_filter: &str, file_name: &str) -> AnalysisResults { // Delete the output directory, if it exists let _ = std::fs::remove_dir_all(&output_directory); + // Read in file data + let file_data = common::read_file(&file_path, false).expect("Failed to read test file"); + // Configure binwalk let binwalker = Binwalk::configure( Some(file_path), @@ -67,7 +70,7 @@ pub fn run_binwalk(signature_filter: &str, file_name: &str) -> AnalysisResults { .expect("Binwalk initialization failed"); // Run analysis - let results = binwalker.analyze(&binwalker.base_target_file, true); + let results = binwalker.analyze(&file_data, &binwalker.base_target_file, true); // Clean up the output directory let _ = std::fs::remove_dir_all(output_directory);