Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ features = [
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]

[dev-dependencies]
tempfile = "3.20"

[profile.release]
lto = true
34 changes: 31 additions & 3 deletions src/extractors/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ impl Chroot {
/// ```
/// use binwalk::extractors::common::Chroot;
///
/// let chroot_dir = std::path::Path::new(&std::env::temp_dir())
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -156,8 +158,10 @@ impl Chroot {
/// use binwalk::extractors::common::Chroot;
/// use std::path::MAIN_SEPARATOR;
///
/// let chroot_dir = std::path::Path::new(&std::env::temp_dir())
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -221,8 +225,10 @@ impl Chroot {
/// ```
/// use binwalk::extractors::common::Chroot;
///
/// let chroot_dir = std::path::Path::new(&std::env::temp_dir())
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand All @@ -249,8 +255,10 @@ impl Chroot {
///
/// let file_name = "created_file.txt";
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -296,8 +304,10 @@ impl Chroot {
///
/// let file_name = "carved_file.txt";
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -355,8 +365,10 @@ impl Chroot {
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_extractors_common_rs_312_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -392,8 +404,10 @@ impl Chroot {
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_extractors_common_rs_345_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -429,8 +443,10 @@ impl Chroot {
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_extractors_common_rs_377_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -459,8 +475,10 @@ impl Chroot {
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_extractors_common_rs_401_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -489,8 +507,10 @@ impl Chroot {
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_extractors_common_rs_426_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -543,8 +563,10 @@ impl Chroot {
/// ```
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -581,8 +603,10 @@ impl Chroot {
/// ```
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -626,8 +650,10 @@ impl Chroot {
/// ```
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down Expand Up @@ -688,8 +714,10 @@ impl Chroot {
/// # fn main() { #[allow(non_snake_case)] fn _doctest_main_src_extractors_common_rs_571_0() -> Result<(), Box<dyn std::error::Error>> {
/// use binwalk::extractors::common::Chroot;
///
/// # let tempdir = tempfile::tempdir().unwrap();
/// let chroot_dir = std::path::Path::new("tests")
/// .join("binwalk_unit_tests")
/// # .join(tempdir.path())
/// .display()
/// .to_string();
///
Expand Down
13 changes: 2 additions & 11 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,12 @@ pub fn run_binwalk(signature_filter: &str, file_name: &str) -> AnalysisResults {
.to_string();

// Build the path to the output directory
let output_directory = std::path::Path::new("tests")
.join("binwalk_integration_test_extractions")
.display()
.to_string();

// Delete the output directory, if it exists
let _ = std::fs::remove_dir_all(&output_directory);
let output_directory = tempfile::tempdir().unwrap();

// Configure binwalk
let binwalker = Binwalk::configure(
Some(file_path),
Some(output_directory.clone()),
Some(output_directory.path().display().to_string()),
Some(vec![signature_filter.to_string()]),
None,
None,
Expand All @@ -69,8 +63,5 @@ pub fn run_binwalk(signature_filter: &str, file_name: &str) -> AnalysisResults {
// Run analysis
let results = binwalker.analyze(&binwalker.base_target_file, true);

// Clean up the output directory
let _ = std::fs::remove_dir_all(output_directory);

results
}