diff --git a/Cargo.lock b/Cargo.lock index 1c4660a..2968468 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -28,6 +28,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "ar" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d67af77d68a931ecd5cbd8a3b5987d63a1d1d1278f7f6a60ae33db485cdebb69" + [[package]] name = "autocfg" version = "1.1.0" @@ -832,8 +838,9 @@ dependencies = [ [[package]] name = "sk_extract" -version = "0.9.0" +version = "1.0.2" dependencies = [ + "ar", "bzip2", "data-encoding", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 9306fad..33e34f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +ar = "0.9.0" bzip2 = "0.4.4" data-encoding = "2.4.0" flate2 = "1.0.27" diff --git a/src/lib/extractors.rs b/src/lib/extractors.rs index f47e497..1602a28 100644 --- a/src/lib/extractors.rs +++ b/src/lib/extractors.rs @@ -3,6 +3,7 @@ use lzma::reader::LzmaReader; use flate2::read::GzDecoder; use bzip2::read::BzDecoder; use unrar::Archive; +use ar; /// Extracts files from a ZIP archive. /// @@ -366,3 +367,21 @@ pub fn extract_txz(input_path: &Path, output_directory: &Path) -> Result<(), io: } Ok(()) } + +pub fn extract_deb(input_path: &Path,) -> Result<(),io::Error>{ + let input_file =File::open(&input_path).unwrap(); + // Read an archive from the file foo.a: + let mut archive = ar::Archive::new(&input_file); + // Iterate over all entries in the archive: + while let Some(entry_result) = archive.next_entry() { + let mut entry = entry_result.unwrap(); + // Create a new file with the same name as the archive entry: + let mut file = File::create( + str::from_utf8(entry.header().identifier()).unwrap(), + ).unwrap(); + // The Entry object also acts as an io::Read, so we can easily copy the + // contents of the archive entry into the file: + io::copy(&mut entry, &mut file).unwrap(); + } + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 1244242..6222681 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use sk_extract::extractors::{ // extract_arj, // extract_cab, // extract_chm, - // extract_deb, + extract_deb, // extract_dmg, // extract_iso, // extract_lzh, @@ -186,6 +186,17 @@ fn run() -> i32 { return 1; } } + "deb" => { + let output_directory = Path::new("output_directory"); // Change this to your desired output directory + if let Err(err) = fs::create_dir_all(&output_directory) { + println!("Error creating output directory: {}", err); + return 1; + } + if let Err(err) = extract_deb(&fname) { + println!("Error extracting DEB: {}", err); + return 1; + } + } /* "arj" => { @@ -206,12 +217,7 @@ fn run() -> i32 { return 1; } } - "deb" => { - if let Err(err) = extract_deb(&fname) { - println!("Error extracting DEB: {}", err); - return 1; - } - } + "dmg" => { if let Err(err) = extract_dmg(&fname) { println!("Error extracting DMG: {}", err); diff --git a/test_data/busybox_1.35.0-4+b3_amd64.deb b/test_data/busybox_1.35.0-4+b3_amd64.deb new file mode 100644 index 0000000..80302a8 Binary files /dev/null and b/test_data/busybox_1.35.0-4+b3_amd64.deb differ