From 37d72d3dc1821d85fc23e12d1c4224b47f667976 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 12:03:16 -0800 Subject: [PATCH 01/79] Creating sample to unpack alz file --- CLAM-2256/Cargo.lock | 7 +++++++ CLAM-2256/Cargo.toml | 10 ++++++++++ CLAM-2256/alz_example.alz | Bin 0 -> 144 bytes CLAM-2256/run.sh | 3 +++ CLAM-2256/src/main.rs | 31 +++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 CLAM-2256/Cargo.lock create mode 100644 CLAM-2256/Cargo.toml create mode 100644 CLAM-2256/alz_example.alz create mode 100755 CLAM-2256/run.sh create mode 100644 CLAM-2256/src/main.rs diff --git a/CLAM-2256/Cargo.lock b/CLAM-2256/Cargo.lock new file mode 100644 index 0000000000..73f1ae860f --- /dev/null +++ b/CLAM-2256/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "open_alz" +version = "0.1.0" diff --git a/CLAM-2256/Cargo.toml b/CLAM-2256/Cargo.toml new file mode 100644 index 0000000000..0c960b921d --- /dev/null +++ b/CLAM-2256/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "open_alz" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[workspace] diff --git a/CLAM-2256/alz_example.alz b/CLAM-2256/alz_example.alz new file mode 100644 index 0000000000000000000000000000000000000000..f6b2a5d5d0c3faf185f5a72508241d6257c5a160 GIT binary patch literal 144 zcmZ?tiDKkpU|?_p(t->M59jQ%5@29r5RZ@e9u%9HQ>9RnT3n)#mYI{PS5i?Td-@<} zg8`4j#oZ71UNYTPT(VLuNy(S%+F$mK6~90HSbJy-V++^ZjSh3pD*osUU9Zuiw2n$9ipYVB88{i}%tqF0Yxy0@av=?YS7y#K!09wU2wEzGB literal 0 HcmV?d00001 diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh new file mode 100755 index 0000000000..d7c73929dc --- /dev/null +++ b/CLAM-2256/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cargo run alz_example.alz outDir diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs new file mode 100644 index 0000000000..9824a310e0 --- /dev/null +++ b/CLAM-2256/src/main.rs @@ -0,0 +1,31 @@ +use std::fs; +use std::io; + +/* +fn readFile(fileName: &String) ->Vec { + let bytes = fs::read(fileName); + + return bytes; +} +*/ + + +fn main() { + let args: Vec<_> = std::env::args().collect(); + if args.len() < 3 { + println!("Usage: {} ", args[0]); + } + let fileName = &args[1]; + let outDir = &args[2]; + println!("Filename = {}", fileName); + println!("Outdir = {}", outDir); + + let fname = std::path::Path::new(fileName); + let file = fs::File::open(fname).unwrap(); + let bytes: Vec = fs::read(fileName).unwrap(); + + + println!("{:02X?} {:02X?} {:02X?} {:02X?} ", bytes[0], bytes[1], bytes[2], bytes[3]); + + +} From d1a7160932f6d4e2d0d7cf09a96587cc71a8ac27 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 12:16:13 -0800 Subject: [PATCH 02/79] blah --- CLAM-2256/src/main.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 9824a310e0..189b760933 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -1,14 +1,18 @@ use std::fs; use std::io; -/* -fn readFile(fileName: &String) ->Vec { - let bytes = fs::read(fileName); +/* Check for the ALZ file header. */ +fn isAlz(fileContents: &Vec) -> bool { + if (4 >= fileContents.len()){ + return false; + } - return bytes; + return (0x41 == fileContents[0]) + && (0x4c == fileContents[1]) + && (0x5a == fileContents[2]) + && (0x01 == fileContents[3]) + ; } -*/ - fn main() { let args: Vec<_> = std::env::args().collect(); @@ -20,12 +24,20 @@ fn main() { println!("Filename = {}", fileName); println!("Outdir = {}", outDir); - let fname = std::path::Path::new(fileName); - let file = fs::File::open(fname).unwrap(); +// let fname = std::path::Path::new(fileName); +// let file = fs::File::open(fname).unwrap(); let bytes: Vec = fs::read(fileName).unwrap(); + if (!isAlz(&bytes)){ + println!("NOT ALZ, need to return an exit status here"); - println!("{:02X?} {:02X?} {:02X?} {:02X?} ", bytes[0], bytes[1], bytes[2], bytes[3]); - + /*Need an exit status for wrong file type.*/ + return; + } + println!("Is ALZ (so far), continuing"); } + + + + From a5eaef48253e7029429f466a6d56452eff810e44 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 13:36:17 -0800 Subject: [PATCH 03/79] blah --- CLAM-2256/src/main.rs | 106 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 20 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 189b760933..5e9f1cccb0 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -1,41 +1,107 @@ use std::fs; -use std::io; +//use std::io; + + +struct AlzLocalFileHeader { + file_name_length: u16, + + file_attribute: u8, + + file_time_date: u32, + + file_descriptor: u8, + + unknown: u8, +} /* Check for the ALZ file header. */ -fn isAlz(fileContents: &Vec) -> bool { - if (4 >= fileContents.len()){ +fn is_alz(file_contents: &Vec) -> bool { + if 4 >= file_contents.len(){ return false; } - return (0x41 == fileContents[0]) - && (0x4c == fileContents[1]) - && (0x5a == fileContents[2]) - && (0x01 == fileContents[3]) + return (0x41 == file_contents[0]) + && (0x4c == file_contents[1]) + && (0x5a == file_contents[2]) + && (0x01 == file_contents[3]) ; } -fn main() { - let args: Vec<_> = std::env::args().collect(); - if args.len() < 3 { - println!("Usage: {} ", args[0]); +fn is_local_file_header(file_contents: &Vec) -> bool { + if 4 >= file_contents.len(){ + return false; + } + + return (0x42 == file_contents[0]) + && (0x4c == file_contents[1]) + && (0x5a == file_contents[2]) + && (0x01 == file_contents[3]) + ; +} + +//fn parse_file_header(file_contents: &Vec) -> i32{ +fn parse_file_header(file_contents: &Vec) -> i32{ + /*TODO: Return an error, and don't have to mess with signed types.*/ + let mut idx: i32 = 0; + println!("TODO: chagne return type to not have to mess with signedness"); + + if !is_local_file_header(file_contents){ + println!("Parse ERROR: Not a local file header"); + return -1; } - let fileName = &args[1]; - let outDir = &args[2]; - println!("Filename = {}", fileName); - println!("Outdir = {}", outDir); -// let fname = std::path::Path::new(fileName); -// let file = fs::File::open(fname).unwrap(); - let bytes: Vec = fs::read(fileName).unwrap(); + return idx; +} + +fn process_file(file_name: &String, out_dir: &String){ + + println!("Outdir = {}", out_dir); - if (!isAlz(&bytes)){ + /*The first file header should start at 8, + * assuming this is actualy an alz file.*/ + let mut idx: usize = 8; + + let bytes: Vec = fs::read(file_name).unwrap(); + /*TODO: Should probably have the data passed in, since clam will likely do that.*/ + + if !is_alz(&bytes){ println!("NOT ALZ, need to return an exit status here"); /*Need an exit status for wrong file type.*/ return; } - println!("Is ALZ (so far), continuing"); + while idx < bytes.len(){ + let val: i32 = parse_file_header(&bytes[idx..].to_vec()); //TODO: Is it inefficient to do it this way? + if -1 == val{ + break; + } + idx += val as usize; + + break; + } + +// println!("bytes : {:02X} {:02x} {:02x}", sv[0], sv[1], sv[2]); + + +// println!("Is ALZ (so far), continuing"); + + /*After reading the initial header, appears to be skipping 4 bytes (maybe they are ignored) */ + + +} + +fn main() { + let args: Vec<_> = std::env::args().collect(); + + if args.len() < 3 { + println!("Usage: {} ", args[0]); + } + let file_name = &args[1]; + let out_dir = &args[2]; + + process_file(file_name, out_dir); + } From ffc2fbab0fca1ae972a3d15d1a397435078cd360 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 13:53:32 -0800 Subject: [PATCH 04/79] blah --- CLAM-2256/Cargo.lock | 16 ++++++++++++++++ CLAM-2256/Cargo.toml | 2 ++ CLAM-2256/run.sh | 2 ++ CLAM-2256/src/main.rs | 15 ++++++++------- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CLAM-2256/Cargo.lock b/CLAM-2256/Cargo.lock index 73f1ae860f..ff7e885c94 100644 --- a/CLAM-2256/Cargo.lock +++ b/CLAM-2256/Cargo.lock @@ -2,6 +2,22 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cursor" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a48749e67c8bd54d6d4b2a191afaf9bd9d656d22c0852698c990a354fb86fd2c" + [[package]] name = "open_alz" version = "0.1.0" +dependencies = [ + "byteorder", + "cursor", +] diff --git a/CLAM-2256/Cargo.toml b/CLAM-2256/Cargo.toml index 0c960b921d..daee1148ee 100644 --- a/CLAM-2256/Cargo.toml +++ b/CLAM-2256/Cargo.toml @@ -6,5 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +byteorder = "1.5.0" +cursor = "2.3.0" [workspace] diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index d7c73929dc..6614f51245 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -1,3 +1,5 @@ #!/bin/bash cargo run alz_example.alz outDir +cargo run test outDir +cargo run diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 5e9f1cccb0..cf71be8fe1 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -1,6 +1,7 @@ use std::fs; //use std::io; - +use std::io::Cursor; +use byteorder::{LittleEndian, ReadBytesExt}; struct AlzLocalFileHeader { file_name_length: u16, @@ -14,17 +15,16 @@ struct AlzLocalFileHeader { unknown: u8, } +const ALZ_FILE_HEADER: u32 = 0x015a4c41; + /* Check for the ALZ file header. */ fn is_alz(file_contents: &Vec) -> bool { - if 4 >= file_contents.len(){ + let mut cursor = Cursor::new(file_contents); + if 4 >= cursor.get_ref().len(){ return false; } - return (0x41 == file_contents[0]) - && (0x4c == file_contents[1]) - && (0x5a == file_contents[2]) - && (0x01 == file_contents[3]) - ; + return ALZ_FILE_HEADER == cursor.read_u32::().unwrap(); } fn is_local_file_header(file_contents: &Vec) -> bool { @@ -96,6 +96,7 @@ fn main() { if args.len() < 3 { println!("Usage: {} ", args[0]); + return; } let file_name = &args[1]; let out_dir = &args[2]; From 8b57432f54227fe5fe31877b5fe6752d991b8016 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 14:01:29 -0800 Subject: [PATCH 05/79] blah --- CLAM-2256/src/main.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index cf71be8fe1..a1660a9d09 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -18,8 +18,8 @@ struct AlzLocalFileHeader { const ALZ_FILE_HEADER: u32 = 0x015a4c41; /* Check for the ALZ file header. */ -fn is_alz(file_contents: &Vec) -> bool { - let mut cursor = Cursor::new(file_contents); +fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { + //let mut cursor = Cursor::new(file_contents); if 4 >= cursor.get_ref().len(){ return false; } @@ -53,18 +53,16 @@ fn parse_file_header(file_contents: &Vec) -> i32{ return idx; } -fn process_file(file_name: &String, out_dir: &String){ +fn process_file(bytes: &Vec, out_dir: &String){ println!("Outdir = {}", out_dir); /*The first file header should start at 8, * assuming this is actualy an alz file.*/ let mut idx: usize = 8; + let mut cursor = Cursor::new(bytes); - let bytes: Vec = fs::read(file_name).unwrap(); - /*TODO: Should probably have the data passed in, since clam will likely do that.*/ - - if !is_alz(&bytes){ + if !is_alz(&mut cursor){ println!("NOT ALZ, need to return an exit status here"); /*Need an exit status for wrong file type.*/ @@ -101,7 +99,8 @@ fn main() { let file_name = &args[1]; let out_dir = &args[2]; - process_file(file_name, out_dir); + let bytes: Vec = fs::read(file_name).unwrap(); + process_file(&bytes, out_dir); } From 8f3c4562d9cc2b64c14c747f8f2d970f1e7aaa01 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 14:11:14 -0800 Subject: [PATCH 06/79] blah --- CLAM-2256/src/main.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index a1660a9d09..f0b6c35e0c 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -16,10 +16,10 @@ struct AlzLocalFileHeader { } const ALZ_FILE_HEADER: u32 = 0x015a4c41; +const ALZ_LOCAL_FILE_HEADER: u32 = 0x015a4c42; /* Check for the ALZ file header. */ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { - //let mut cursor = Cursor::new(file_contents); if 4 >= cursor.get_ref().len(){ return false; } @@ -27,25 +27,21 @@ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { return ALZ_FILE_HEADER == cursor.read_u32::().unwrap(); } -fn is_local_file_header(file_contents: &Vec) -> bool { - if 4 >= file_contents.len(){ +fn is_alz_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { + if 4 >= cursor.get_ref().len(){ return false; } - return (0x42 == file_contents[0]) - && (0x4c == file_contents[1]) - && (0x5a == file_contents[2]) - && (0x01 == file_contents[3]) - ; + return ALZ_LOCAL_FILE_HEADER == cursor.read_u32::().unwrap(); } -//fn parse_file_header(file_contents: &Vec) -> i32{ -fn parse_file_header(file_contents: &Vec) -> i32{ + +fn parse_file_header(cursor: &mut std::io::Cursor<&Vec>) -> i32{ /*TODO: Return an error, and don't have to mess with signed types.*/ - let mut idx: i32 = 0; + let idx: i32 = 0; println!("TODO: chagne return type to not have to mess with signedness"); - if !is_local_file_header(file_contents){ + if !is_alz_local_file_header(cursor){ println!("Parse ERROR: Not a local file header"); return -1; } @@ -68,9 +64,10 @@ fn process_file(bytes: &Vec, out_dir: &String){ /*Need an exit status for wrong file type.*/ return; } + cursor.read_u32::().unwrap(); //ignore results, just doing this to skip 4 bytes. while idx < bytes.len(){ - let val: i32 = parse_file_header(&bytes[idx..].to_vec()); //TODO: Is it inefficient to do it this way? + let val: i32 = parse_file_header(&mut cursor); if -1 == val{ break; } @@ -82,7 +79,7 @@ fn process_file(bytes: &Vec, out_dir: &String){ // println!("bytes : {:02X} {:02x} {:02x}", sv[0], sv[1], sv[2]); -// println!("Is ALZ (so far), continuing"); + println!("Is ALZ (so far), continuing"); /*After reading the initial header, appears to be skipping 4 bytes (maybe they are ignored) */ From 9da7f88060964521208eaa5777168752e034fb71 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Wed, 24 Jan 2024 14:15:13 -0800 Subject: [PATCH 07/79] blah --- CLAM-2256/src/main.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index f0b6c35e0c..de6ea17040 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -36,17 +36,16 @@ fn is_alz_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { } -fn parse_file_header(cursor: &mut std::io::Cursor<&Vec>) -> i32{ - /*TODO: Return an error, and don't have to mess with signed types.*/ - let idx: i32 = 0; - println!("TODO: chagne return type to not have to mess with signedness"); +fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ if !is_alz_local_file_header(cursor){ println!("Parse ERROR: Not a local file header"); - return -1; + return false; } - return idx; + println!("HERE HERE HERE, continue parsing the headers"); + + return true; } fn process_file(bytes: &Vec, out_dir: &String){ @@ -67,11 +66,9 @@ fn process_file(bytes: &Vec, out_dir: &String){ cursor.read_u32::().unwrap(); //ignore results, just doing this to skip 4 bytes. while idx < bytes.len(){ - let val: i32 = parse_file_header(&mut cursor); - if -1 == val{ + if !parse_local_file_header(&mut cursor){ break; } - idx += val as usize; break; } From 54bbdf5a366f78b508fbc882d3f49d228fbb9e9e Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 06:22:35 -0800 Subject: [PATCH 08/79] blah --- CLAM-2256/src/main.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index de6ea17040..628e8a626e 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -6,6 +6,7 @@ use byteorder::{LittleEndian, ReadBytesExt}; struct AlzLocalFileHeader { file_name_length: u16, + /* file_attribute: u8, file_time_date: u32, @@ -13,6 +14,23 @@ struct AlzLocalFileHeader { file_descriptor: u8, unknown: u8, + */ +} + +impl AlzLocalFileHeader { + pub fn new() -> Self { + Self { + file_name_length: 0, + } + } + pub fn read(&self, cursor: &mut std::io::Cursor<&Vec>) -> bool { + + Self { + file_name_length : cursor.read_u16::().unwrap(), + }; + + return false; + } } const ALZ_FILE_HEADER: u32 = 0x015a4c41; @@ -43,6 +61,13 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ return false; } + let alfh = AlzLocalFileHeader::new(); + if !alfh.read(cursor){ + println!("Parse ERROR: Not a local file header"); + return false; + } + println!("fnl = {}", alfh.file_name_length); + println!("HERE HERE HERE, continue parsing the headers"); return true; @@ -54,7 +79,7 @@ fn process_file(bytes: &Vec, out_dir: &String){ /*The first file header should start at 8, * assuming this is actualy an alz file.*/ - let mut idx: usize = 8; + let idx: usize = 8; let mut cursor = Cursor::new(bytes); if !is_alz(&mut cursor){ From f5148a477f549d65ec7ac0f6b3a7c2ebad82da79 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:14:30 -0800 Subject: [PATCH 09/79] blah --- CLAM-2256/src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 628e8a626e..7064c7d2bd 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -3,6 +3,9 @@ use std::fs; use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; +struct ALZParseError { +} + struct AlzLocalFileHeader { file_name_length: u16, @@ -17,12 +20,27 @@ struct AlzLocalFileHeader { */ } + impl AlzLocalFileHeader { pub fn new() -> Self { Self { file_name_length: 0, } } + + pub fn readinit( cursor: &mut std::io::Cursor<&Vec> ) -> Result { + + if std::mem::size_of::() >= cursor.get_ref().len(){ + return Err(ALZParseError{}); + } + + Ok( + Self { + file_name_length : cursor.read_u16::().unwrap(), + } + ) + } + pub fn read(&self, cursor: &mut std::io::Cursor<&Vec>) -> bool { Self { @@ -68,6 +86,8 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ } println!("fnl = {}", alfh.file_name_length); + //let val = std::mem::size_of::; + println!("HERE HERE HERE, continue parsing the headers"); return true; From fb89fe47b31fadd17a4061775ba296c12cf737d2 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:18:31 -0800 Subject: [PATCH 10/79] blah --- CLAM-2256/src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 7064c7d2bd..8f8c219a0b 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -3,6 +3,7 @@ use std::fs; use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; +#[derive(Debug)] struct ALZParseError { } @@ -22,13 +23,15 @@ struct AlzLocalFileHeader { impl AlzLocalFileHeader { + /* pub fn new() -> Self { Self { file_name_length: 0, } } + */ - pub fn readinit( cursor: &mut std::io::Cursor<&Vec> ) -> Result { + pub fn new( cursor: &mut std::io::Cursor<&Vec> ) -> Result { if std::mem::size_of::() >= cursor.get_ref().len(){ return Err(ALZParseError{}); @@ -41,6 +44,7 @@ impl AlzLocalFileHeader { ) } + /* pub fn read(&self, cursor: &mut std::io::Cursor<&Vec>) -> bool { Self { @@ -49,6 +53,7 @@ impl AlzLocalFileHeader { return false; } + */ } const ALZ_FILE_HEADER: u32 = 0x015a4c41; @@ -79,11 +84,13 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ return false; } - let alfh = AlzLocalFileHeader::new(); + let alfh = AlzLocalFileHeader::new(cursor).unwrap(); + /* if !alfh.read(cursor){ println!("Parse ERROR: Not a local file header"); return false; } + */ println!("fnl = {}", alfh.file_name_length); //let val = std::mem::size_of::; From c32be72244371178039091b3bf72767d943eff0d Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:24:18 -0800 Subject: [PATCH 11/79] blah --- CLAM-2256/src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 8f8c219a0b..aa0d260be4 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -84,16 +84,14 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ return false; } - let alfh = AlzLocalFileHeader::new(cursor).unwrap(); - /* - if !alfh.read(cursor){ - println!("Parse ERROR: Not a local file header"); + let res = AlzLocalFileHeader::new(cursor); + if res.is_err(){ + println!("Parse ERROR: Not a local file header (2)"); return false; } - */ - println!("fnl = {}", alfh.file_name_length); - //let val = std::mem::size_of::; + let alfh = res.unwrap(); + println!("fnl = {}", alfh.file_name_length); println!("HERE HERE HERE, continue parsing the headers"); From 9f3d19227baca76cdd5c19e024a2165395727ffb Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:25:31 -0800 Subject: [PATCH 12/79] blah --- CLAM-2256/src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index aa0d260be4..3c87d066c9 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -61,7 +61,8 @@ const ALZ_LOCAL_FILE_HEADER: u32 = 0x015a4c42; /* Check for the ALZ file header. */ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { - if 4 >= cursor.get_ref().len(){ + + if std::mem::size_of::() >= cursor.get_ref().len(){ return false; } @@ -69,7 +70,7 @@ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { } fn is_alz_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { - if 4 >= cursor.get_ref().len(){ + if std::mem::size_of::() >= cursor.get_ref().len(){ return false; } From 1a1b3c7c0e3b323ac555b9ee870e27097dac92bf Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:29:39 -0800 Subject: [PATCH 13/79] blah --- CLAM-2256/src/main.rs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 3c87d066c9..38d51660de 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -8,11 +8,11 @@ struct ALZParseError { } struct AlzLocalFileHeader { - file_name_length: u16, + _file_name_length: u16, - /* - file_attribute: u8, + _file_attribute: u8, + /* file_time_date: u32, file_descriptor: u8, @@ -23,14 +23,6 @@ struct AlzLocalFileHeader { impl AlzLocalFileHeader { - /* - pub fn new() -> Self { - Self { - file_name_length: 0, - } - } - */ - pub fn new( cursor: &mut std::io::Cursor<&Vec> ) -> Result { if std::mem::size_of::() >= cursor.get_ref().len(){ @@ -39,21 +31,14 @@ impl AlzLocalFileHeader { Ok( Self { - file_name_length : cursor.read_u16::().unwrap(), + /*TODO: Is it safe to call unwrap here, since I already checked that there is + * enough space in the buffer? + */ + _file_name_length : cursor.read_u16::().unwrap(), + _file_attribute : cursor.read_u8::<>().unwrap(), } ) } - - /* - pub fn read(&self, cursor: &mut std::io::Cursor<&Vec>) -> bool { - - Self { - file_name_length : cursor.read_u16::().unwrap(), - }; - - return false; - } - */ } const ALZ_FILE_HEADER: u32 = 0x015a4c41; @@ -91,8 +76,9 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ return false; } + /*TODO: Is it safe to call unwrap here, since I already called 'is_err' */ let alfh = res.unwrap(); - println!("fnl = {}", alfh.file_name_length); + println!("fnl = {}", alfh._file_name_length); println!("HERE HERE HERE, continue parsing the headers"); From 1d62bf50e6842b860e66c52e27d0b9756162cecb Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:30:28 -0800 Subject: [PATCH 14/79] blah --- CLAM-2256/src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 38d51660de..3762df7913 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -12,13 +12,11 @@ struct AlzLocalFileHeader { _file_attribute: u8, - /* - file_time_date: u32, + _file_time_date: u32, - file_descriptor: u8, + _file_descriptor: u8, - unknown: u8, - */ + _unknown: u8, } @@ -36,6 +34,9 @@ impl AlzLocalFileHeader { */ _file_name_length : cursor.read_u16::().unwrap(), _file_attribute : cursor.read_u8::<>().unwrap(), + _file_time_date: cursor.read_u32::().unwrap(), + _file_descriptor : cursor.read_u8::<>().unwrap(), + _unknown : cursor.read_u8::<>().unwrap(), } ) } From 400a8dbbc74331660dda7b974b5b84f47a4c6cd8 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 07:51:44 -0800 Subject: [PATCH 15/79] blah --- CLAM-2256/src/main.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 3762df7913..b9dc2113b1 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -22,13 +22,14 @@ struct AlzLocalFileHeader { impl AlzLocalFileHeader { pub fn new( cursor: &mut std::io::Cursor<&Vec> ) -> Result { + let mut is_encrypted : bool = false; + let mut is_data_descriptor : bool = false; if std::mem::size_of::() >= cursor.get_ref().len(){ return Err(ALZParseError{}); } - Ok( - Self { + let ret = Self { /*TODO: Is it safe to call unwrap here, since I already checked that there is * enough space in the buffer? */ @@ -37,8 +38,21 @@ impl AlzLocalFileHeader { _file_time_date: cursor.read_u32::().unwrap(), _file_descriptor : cursor.read_u8::<>().unwrap(), _unknown : cursor.read_u8::<>().unwrap(), - } - ) + }; + + if 0 != (ret._file_descriptor & 0x1 ) { + is_encrypted = true; + } + + if 0 != (ret._file_descriptor & 0x8) { + is_data_descriptor = true; + } + + println!("TODO: MAY need to move these flags to the struct"); + println!("is_encrypted = {}", is_encrypted); + println!("is_data_descriptor = {}", is_data_descriptor); + + return Ok(ret); } } From 424ffddceb28dd0cd281123499f0f2e2cbc75542 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 09:19:19 -0800 Subject: [PATCH 16/79] blah --- CLAM-2256/src/main.rs | 112 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 101 insertions(+), 11 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index b9dc2113b1..230171088e 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -2,12 +2,13 @@ use std::fs; //use std::io; use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; +use std::mem::size_of; #[derive(Debug)] struct ALZParseError { } -struct AlzLocalFileHeader { +struct AlzLocalFileHeaderHead { _file_name_length: u16, _file_attribute: u8, @@ -17,6 +18,21 @@ struct AlzLocalFileHeader { _file_descriptor: u8, _unknown: u8, + + } + +struct AlzLocalFileHeader { + _head: AlzLocalFileHeaderHead, + + _compression_method: u8, + _unknown: u8, + _file_crc: u32, + + /* Can be smaller sizes, depending on _file_descriptor/0x10 .*/ + _compressed_size: u64, + _uncompressed_size: u64, + + } @@ -25,29 +41,103 @@ impl AlzLocalFileHeader { let mut is_encrypted : bool = false; let mut is_data_descriptor : bool = false; - if std::mem::size_of::() >= cursor.get_ref().len(){ + if size_of::() >= cursor.get_ref().len(){ return Err(ALZParseError{}); } - let ret = Self { + let mut ret = Self { /*TODO: Is it safe to call unwrap here, since I already checked that there is * enough space in the buffer? */ - _file_name_length : cursor.read_u16::().unwrap(), - _file_attribute : cursor.read_u8::<>().unwrap(), - _file_time_date: cursor.read_u32::().unwrap(), - _file_descriptor : cursor.read_u8::<>().unwrap(), - _unknown : cursor.read_u8::<>().unwrap(), + _head : AlzLocalFileHeaderHead { + _file_name_length : cursor.read_u16::().unwrap(), + _file_attribute : cursor.read_u8::<>().unwrap(), + _file_time_date: cursor.read_u32::().unwrap(), + _file_descriptor : cursor.read_u8::<>().unwrap(), + _unknown : cursor.read_u8::<>().unwrap(), + }, + + _compression_method : 0, + _unknown : 0, + _file_crc : 0, + _compressed_size : 0, + _uncompressed_size : 0, + }; - if 0 != (ret._file_descriptor & 0x1 ) { + if 0 != (ret._head._file_descriptor & 0x1 ) { is_encrypted = true; } - if 0 != (ret._file_descriptor & 0x8) { + if 0 != (ret._head._file_descriptor & 0x8) { is_data_descriptor = true; } + if is_encrypted { + assert!(false, "ENCRYPTION UNIMPLEMENTED"); + } + + if is_data_descriptor { + assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); + } + + let byte_len = ret._head._file_descriptor / 0x10; + println!("byte_len = {}", byte_len); + if byte_len > 0 { + + if (size_of::() + size_of::() + size_of::()) >= cursor.get_ref().len(){ + return Err(ALZParseError{}); + } + + ret._compression_method = cursor.read_u8::<>().unwrap(); + ret._unknown = cursor.read_u8::<>().unwrap(); + ret._file_crc = cursor.read_u32::().unwrap(); + + match byte_len { + 1 => { + if (size_of::() * 2) >= cursor.get_ref().len() { + return Err(ALZParseError{}); + } + ret._compressed_size = cursor.read_u8::<>().unwrap() as u64; + ret._uncompressed_size = cursor.read_u8::<>().unwrap() as u64; + }, + 2 => { + if (size_of::() * 2) >= cursor.get_ref().len() { + return Err(ALZParseError{}); + } + ret._compressed_size = cursor.read_u16::().unwrap() as u64; + ret._uncompressed_size = cursor.read_u16::().unwrap() as u64; + }, + 4 => { + if (size_of::() * 2) >= cursor.get_ref().len() { + return Err(ALZParseError{}); + } + ret._compressed_size = cursor.read_u32::().unwrap() as u64; + ret._uncompressed_size = cursor.read_u32::().unwrap() as u64; + }, + 8 => { + if (size_of::() * 2) >= cursor.get_ref().len() { + return Err(ALZParseError{}); + } + ret._compressed_size = cursor.read_u64::().unwrap() as u64; + ret._uncompressed_size = cursor.read_u64::().unwrap() as u64; + }, + _ => return Err(ALZParseError{}), + } + } else { + println!("DON'T THINK THIS IS EVER POSSIBLE, SEE IF IT COMES OUT IN TESTING!!!!!"); + assert!(false, "EXITING HERE"); + /* + * TODO: In 'unalz', (UnAlz.cpp, CUnAlz::ReadLocalFileheader), the condition where + * byte_len (byteLen) is zero is treated as a condition that can be ignored, and + * processing can continue. I think it's probably a parse error when that + * happens and it never causes an issue because the file then fails crc and an error is + * reported, rather than just stopping parsing when that happens. I would like to look + * for a file that has that condition and see if unalz (or other unpackers) are able to + * extract anything from the file. If not, we can just return here. + */ + } + println!("TODO: MAY need to move these flags to the struct"); println!("is_encrypted = {}", is_encrypted); println!("is_data_descriptor = {}", is_data_descriptor); @@ -93,7 +183,7 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ /*TODO: Is it safe to call unwrap here, since I already called 'is_err' */ let alfh = res.unwrap(); - println!("fnl = {}", alfh._file_name_length); + println!("fnl = {}", alfh._head._file_name_length); println!("HERE HERE HERE, continue parsing the headers"); From 3d57d1f46776c13cdda273914ddd4345b5ef04f3 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 10:45:27 -0800 Subject: [PATCH 17/79] blah --- CLAM-2256/src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 230171088e..c8e06e4ed7 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -4,6 +4,8 @@ use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; use std::mem::size_of; +//use std::io::Read; + #[derive(Debug)] struct ALZParseError { } @@ -32,6 +34,7 @@ struct AlzLocalFileHeader { _compressed_size: u64, _uncompressed_size: u64, + _file_name: String, } @@ -62,9 +65,15 @@ impl AlzLocalFileHeader { _file_crc : 0, _compressed_size : 0, _uncompressed_size : 0, + _file_name : "".to_string(), }; + if 0 == ret._head._file_name_length { + println!("Filename length cannot be zero"); + return Err(ALZParseError{}); + } + if 0 != (ret._head._file_descriptor & 0x1 ) { is_encrypted = true; } @@ -138,6 +147,37 @@ impl AlzLocalFileHeader { */ } + if ret._head._file_name_length as usize >= cursor.get_ref().len() { + return Err(ALZParseError{}); + } + + let mut filename = vec![0u8, 1]; + /*TODO: Figure out the correct way to allocate a vector of dynamic size and call + * cursor.read_exact, instead of having a loop of reads.*/ + for _i in 0..ret._head._file_name_length { + filename.push( cursor.read_u8::<>().unwrap()); + } + let res = String::from_utf8(filename); + if res.is_ok(){ + ret._file_name = res.unwrap(); + } else { + assert!(false, "NOT sure if other filename formats are supported here"); + } + + println!("ret._head._file_name_length = {:x}", ret._head._file_name_length); + println!("ret._head._file_attribute = {:02x}", ret._head._file_attribute); + println!("ret._head._file_time_date = {:x}", ret._head._file_time_date); + println!("ret._head._file_descriptor = {:x}", ret._head._file_descriptor); + println!("ret._head._unknown = {:x}", ret._head._unknown); + + println!("ret._compression_method = {:x}", ret._compression_method); + println!("ret._unknown = {:x}", ret._unknown); + println!("ret._file_crc = {:x}", ret._file_crc); + println!("ret._compressed_size = {:x}", ret._compressed_size); + println!("ret._uncompressed_size = {:x}", ret._uncompressed_size); + + println!("ret._file_name = {}", ret._file_name); + println!("TODO: MAY need to move these flags to the struct"); println!("is_encrypted = {}", is_encrypted); println!("is_data_descriptor = {}", is_data_descriptor); From eadd152e26dc004bfd207221cff084d2cc1cef70 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 11:49:57 -0800 Subject: [PATCH 18/79] blah --- CLAM-2256/src/main.rs | 51 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index c8e06e4ed7..38392cae38 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -4,7 +4,7 @@ use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; use std::mem::size_of; -//use std::io::Read; +use std::io::Read; #[derive(Debug)] struct ALZParseError { @@ -21,7 +21,9 @@ struct AlzLocalFileHeaderHead { _unknown: u8, - } +} + +const ALZ_ENCR_HEADER_LEN: u32 = 12; struct AlzLocalFileHeader { _head: AlzLocalFileHeaderHead, @@ -36,12 +38,14 @@ struct AlzLocalFileHeader { _file_name: String, + _enc_chk: [u8; ALZ_ENCR_HEADER_LEN as usize], + _is_encrypted: bool, + } impl AlzLocalFileHeader { pub fn new( cursor: &mut std::io::Cursor<&Vec> ) -> Result { - let mut is_encrypted : bool = false; let mut is_data_descriptor : bool = false; if size_of::() >= cursor.get_ref().len(){ @@ -66,6 +70,8 @@ impl AlzLocalFileHeader { _compressed_size : 0, _uncompressed_size : 0, _file_name : "".to_string(), + _enc_chk: [0; ALZ_ENCR_HEADER_LEN as usize], + _is_encrypted : false, }; @@ -74,17 +80,12 @@ impl AlzLocalFileHeader { return Err(ALZParseError{}); } - if 0 != (ret._head._file_descriptor & 0x1 ) { - is_encrypted = true; - } + ret._is_encrypted = 0 != (ret._head._file_descriptor & 0x1 ); if 0 != (ret._head._file_descriptor & 0x8) { is_data_descriptor = true; } - if is_encrypted { - assert!(false, "ENCRYPTION UNIMPLEMENTED"); - } if is_data_descriptor { assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); @@ -161,9 +162,25 @@ impl AlzLocalFileHeader { if res.is_ok(){ ret._file_name = res.unwrap(); } else { + /*TODO: Other formats*/ assert!(false, "NOT sure if other filename formats are supported here"); } + if ret._is_encrypted{ + if ALZ_ENCR_HEADER_LEN as usize > cursor.get_ref().len() { + return Err(ALZParseError{}); + } + + /*TODO: Is it safe to call unwrap here, since I already checked that there are enough + * bytes? + */ + cursor.read_exact(&mut ret._enc_chk).unwrap(); + assert!(false, "ENCRYPTION UNIMPLEMENTED"); + } + + + + println!("ret._head._file_name_length = {:x}", ret._head._file_name_length); println!("ret._head._file_attribute = {:02x}", ret._head._file_attribute); println!("ret._head._file_time_date = {:x}", ret._head._file_time_date); @@ -178,8 +195,22 @@ impl AlzLocalFileHeader { println!("ret._file_name = {}", ret._file_name); + print!("ret._enc_chk = "); + for i in 0..ALZ_ENCR_HEADER_LEN { + if 0 != i { + print!(" "); + } + print!("{}", ret._enc_chk[i as usize]); + } + println!(""); + + + + + + println!("TODO: MAY need to move these flags to the struct"); - println!("is_encrypted = {}", is_encrypted); + println!("is_encrypted = {}", ret._is_encrypted); println!("is_data_descriptor = {}", is_data_descriptor); return Ok(ret); From 9b32c780c7ea3791324113b168df543261961821 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 12:02:05 -0800 Subject: [PATCH 19/79] blah --- CLAM-2256/src/main.rs | 45 ++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 38392cae38..6fab15fb9b 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -39,14 +39,21 @@ struct AlzLocalFileHeader { _file_name: String, _enc_chk: [u8; ALZ_ENCR_HEADER_LEN as usize], - _is_encrypted: bool, } impl AlzLocalFileHeader { + fn is_encrypted(&mut self) -> bool { + return 0 != (self._head._file_descriptor & 0x1 ); + } + + fn is_data_descriptor(&mut self) -> bool { + return 0 != (self._head._file_descriptor & 0x8 ); + } + pub fn new( cursor: &mut std::io::Cursor<&Vec> ) -> Result { - let mut is_data_descriptor : bool = false; + //let mut is_data_descriptor : bool = false; if size_of::() >= cursor.get_ref().len(){ return Err(ALZParseError{}); @@ -71,8 +78,6 @@ impl AlzLocalFileHeader { _uncompressed_size : 0, _file_name : "".to_string(), _enc_chk: [0; ALZ_ENCR_HEADER_LEN as usize], - _is_encrypted : false, - }; if 0 == ret._head._file_name_length { @@ -80,16 +85,14 @@ impl AlzLocalFileHeader { return Err(ALZParseError{}); } - ret._is_encrypted = 0 != (ret._head._file_descriptor & 0x1 ); + //if 0 != (ret._head._file_descriptor & 0x8) { + //is_data_descriptor = true; + //} - if 0 != (ret._head._file_descriptor & 0x8) { - is_data_descriptor = true; - } - - if is_data_descriptor { - assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); - } + //if is_data_descriptor { + //assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); + //} let byte_len = ret._head._file_descriptor / 0x10; println!("byte_len = {}", byte_len); @@ -166,7 +169,7 @@ impl AlzLocalFileHeader { assert!(false, "NOT sure if other filename formats are supported here"); } - if ret._is_encrypted{ + if ret.is_encrypted() { if ALZ_ENCR_HEADER_LEN as usize > cursor.get_ref().len() { return Err(ALZParseError{}); } @@ -175,7 +178,6 @@ impl AlzLocalFileHeader { * bytes? */ cursor.read_exact(&mut ret._enc_chk).unwrap(); - assert!(false, "ENCRYPTION UNIMPLEMENTED"); } @@ -210,8 +212,19 @@ impl AlzLocalFileHeader { println!("TODO: MAY need to move these flags to the struct"); - println!("is_encrypted = {}", ret._is_encrypted); - println!("is_data_descriptor = {}", is_data_descriptor); + println!("is_encrypted = {}", ret.is_encrypted()); + println!("is_data_descriptor = {}", ret.is_data_descriptor()); + + + if ret.is_encrypted() { + assert!(false, "ENCRYPTION UNIMPLEMENTED"); + } + + if ret.is_data_descriptor() { + assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); + } + + return Ok(ret); } From c3c663877897d1342eb3c906d7375549ca53aec6 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 12:07:42 -0800 Subject: [PATCH 20/79] blah --- CLAM-2256/src/main.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 6fab15fb9b..0ebd52f7a3 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -198,17 +198,13 @@ impl AlzLocalFileHeader { println!("ret._file_name = {}", ret._file_name); print!("ret._enc_chk = "); - for i in 0..ALZ_ENCR_HEADER_LEN { - if 0 != i { - print!(" "); - } - print!("{}", ret._enc_chk[i as usize]); + for i in 0..ALZ_ENCR_HEADER_LEN { + if 0 != i { + print!(" "); } - println!(""); - - - - + print!("{}", ret._enc_chk[i as usize]); + } + println!(""); println!("TODO: MAY need to move these flags to the struct"); From b7832a4a260c8d3b73d1764f9ef63b1d8d607ceb Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 12:08:13 -0800 Subject: [PATCH 21/79] blah --- CLAM-2256/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 0ebd52f7a3..5cc53124a5 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -207,7 +207,6 @@ impl AlzLocalFileHeader { println!(""); - println!("TODO: MAY need to move these flags to the struct"); println!("is_encrypted = {}", ret.is_encrypted()); println!("is_data_descriptor = {}", ret.is_data_descriptor()); From acc8c56b99be1c37664cb0a29394203a6bb92e22 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 12:36:41 -0800 Subject: [PATCH 22/79] blah --- CLAM-2256/src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 5cc53124a5..66f1e69504 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -40,6 +40,7 @@ struct AlzLocalFileHeader { _enc_chk: [u8; ALZ_ENCR_HEADER_LEN as usize], + _start_of_compressed_data: u64, } @@ -78,6 +79,7 @@ impl AlzLocalFileHeader { _uncompressed_size : 0, _file_name : "".to_string(), _enc_chk: [0; ALZ_ENCR_HEADER_LEN as usize], + _start_of_compressed_data: 0, }; if 0 == ret._head._file_name_length { @@ -180,8 +182,8 @@ impl AlzLocalFileHeader { cursor.read_exact(&mut ret._enc_chk).unwrap(); } - - + ret._start_of_compressed_data = cursor.position(); + cursor.set_position(ret._start_of_compressed_data + ret._compressed_size); println!("ret._head._file_name_length = {:x}", ret._head._file_name_length); println!("ret._head._file_attribute = {:02x}", ret._head._file_attribute); @@ -210,6 +212,9 @@ impl AlzLocalFileHeader { println!("is_encrypted = {}", ret.is_encrypted()); println!("is_data_descriptor = {}", ret.is_data_descriptor()); + println!("ret._start_of_compressed_data = {}", ret._start_of_compressed_data); + + if ret.is_encrypted() { assert!(false, "ENCRYPTION UNIMPLEMENTED"); @@ -219,8 +224,6 @@ impl AlzLocalFileHeader { assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); } - - return Ok(ret); } } From 6562e5753c45d9fc6217065499636c63398d3151 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 13:30:16 -0800 Subject: [PATCH 23/79] blah --- CLAM-2256/src/main.rs | 100 +++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 15 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 66f1e69504..9ef36229a3 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -10,6 +10,12 @@ use std::io::Read; struct ALZParseError { } +const ALZ_FILE_HEADER: u32 = 0x015a4c41; +const ALZ_LOCAL_FILE_HEADER: u32 = 0x015a4c42; +const ALZ_CENTRAL_DIRECTORY_HEADER: u32 = 0x015a4c43; +const ALZ_END_OF_CENTRAL_DIRECTORY_HEADER : u32 = 0x025a4c43; + + struct AlzLocalFileHeaderHead { _file_name_length: u16, @@ -183,7 +189,11 @@ impl AlzLocalFileHeader { } ret._start_of_compressed_data = cursor.position(); + println!("ret._start_of_compressed_data = {}", ret._start_of_compressed_data ); + println!("ret._compressed_size = {}", ret._compressed_size ); + cursor.set_position(ret._start_of_compressed_data + ret._compressed_size); + println!("cursor.position() = {}", cursor.position() ); println!("ret._head._file_name_length = {:x}", ret._head._file_name_length); println!("ret._head._file_attribute = {:02x}", ret._head._file_attribute); @@ -214,8 +224,6 @@ impl AlzLocalFileHeader { println!("ret._start_of_compressed_data = {}", ret._start_of_compressed_data); - - if ret.is_encrypted() { assert!(false, "ENCRYPTION UNIMPLEMENTED"); } @@ -228,9 +236,6 @@ impl AlzLocalFileHeader { } } -const ALZ_FILE_HEADER: u32 = 0x015a4c41; -const ALZ_LOCAL_FILE_HEADER: u32 = 0x015a4c42; - /* Check for the ALZ file header. */ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { @@ -264,37 +269,101 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ } /*TODO: Is it safe to call unwrap here, since I already called 'is_err' */ - let alfh = res.unwrap(); - println!("fnl = {}", alfh._head._file_name_length); + let local_file_header = res.unwrap(); - println!("HERE HERE HERE, continue parsing the headers"); + println!("HERE HERE HERE, continue parsing the headers {}", local_file_header._start_of_compressed_data); + println!("cursor.position() = {}", cursor.position() ); return true; } -fn process_file(bytes: &Vec, out_dir: &String){ + +fn is_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { + if std::mem::size_of::() >= cursor.get_ref().len(){ + return false; + } + + //return ALZ_CENTRAL_DIRECTORY_HEADER == cursor.read_u32::().unwrap(); + + println!("cursor.position = {}", cursor.position()); + let tmp = cursor.read_u32::().unwrap(); + println!("tmp = {}", tmp); + return ALZ_CENTRAL_DIRECTORY_HEADER == tmp; +} + +fn parse_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ + println!("cursor.position() = {}", cursor.position() ); + if !is_central_directory_header(cursor) { + println!("Parse ERROR: Not a central directory header"); + return false; + } + + if 8 >= cursor.get_ref().len(){ + return false; + } + + /* + * This is ignored in unalz (UnAlz.cpp ReadCentralDirectoryStructure). + * + * It actually reads 12 bytes, and I think it happens to work because EOF is hit on the next + * read, which it does not consider an error. + */ + cursor.read_u64::().unwrap(); + + return true; +} + +fn is_end_of_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { + if std::mem::size_of::() >= cursor.get_ref().len(){ + return false; + } + + return ALZ_END_OF_CENTRAL_DIRECTORY_HEADER == cursor.read_u32::().unwrap(); +} + +fn parse_end_of_central_directory_record(cursor: &mut std::io::Cursor<&Vec>) -> bool{ + if !is_end_of_central_directory_header(cursor) { + println!("Parse ERROR: Not an end of central directory header"); + return false; + } + + return true; +} + +fn process_file(bytes: &Vec, out_dir: &String) -> bool { println!("Outdir = {}", out_dir); /*The first file header should start at 8, * assuming this is actualy an alz file.*/ - let idx: usize = 8; +// let idx: usize = 8; let mut cursor = Cursor::new(bytes); if !is_alz(&mut cursor){ println!("NOT ALZ, need to return an exit status here"); /*Need an exit status for wrong file type.*/ - return; + return false; } cursor.read_u32::().unwrap(); //ignore results, just doing this to skip 4 bytes. - while idx < bytes.len(){ - if !parse_local_file_header(&mut cursor){ - break; + while 0 < cursor.get_ref().len() { + if parse_local_file_header(&mut cursor){ + println!("Found a local file header\n"); + continue; + } + if parse_central_directory_header(&mut cursor){ + println!("Found a central directory header\n"); + continue; + } + if parse_end_of_central_directory_record(&mut cursor){ + println!("Found an end of central directory header\n"); + continue; } - break; + println!("NOT A VALID FILE"); + assert!(false, "NOT A VALID FILE"); + return false; } // println!("bytes : {:02X} {:02x} {:02x}", sv[0], sv[1], sv[2]); @@ -304,6 +373,7 @@ fn process_file(bytes: &Vec, out_dir: &String){ /*After reading the initial header, appears to be skipping 4 bytes (maybe they are ignored) */ + return true; } From 20aa85882713d1f5beae27729b8191d2005b1560 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 13:48:18 -0800 Subject: [PATCH 24/79] blah --- CLAM-2256/src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 9ef36229a3..0cda48b3a0 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -246,6 +246,7 @@ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { return ALZ_FILE_HEADER == cursor.read_u32::().unwrap(); } +/* fn is_alz_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { if std::mem::size_of::() >= cursor.get_ref().len(){ return false; @@ -253,14 +254,17 @@ fn is_alz_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { return ALZ_LOCAL_FILE_HEADER == cursor.read_u32::().unwrap(); } +*/ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ + /* if !is_alz_local_file_header(cursor){ println!("Parse ERROR: Not a local file header"); return false; } + */ let res = AlzLocalFileHeader::new(cursor); if res.is_err(){ @@ -278,6 +282,7 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ } +/* fn is_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { if std::mem::size_of::() >= cursor.get_ref().len(){ return false; @@ -290,13 +295,16 @@ fn is_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { println!("tmp = {}", tmp); return ALZ_CENTRAL_DIRECTORY_HEADER == tmp; } +*/ fn parse_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ + /* println!("cursor.position() = {}", cursor.position() ); if !is_central_directory_header(cursor) { println!("Parse ERROR: Not a central directory header"); return false; } + */ if 8 >= cursor.get_ref().len(){ return false; @@ -313,6 +321,7 @@ fn parse_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> boo return true; } +/* fn is_end_of_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { if std::mem::size_of::() >= cursor.get_ref().len(){ return false; @@ -329,6 +338,7 @@ fn parse_end_of_central_directory_record(cursor: &mut std::io::Cursor<&Vec>) return true; } +*/ fn process_file(bytes: &Vec, out_dir: &String) -> bool { @@ -348,6 +358,44 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { cursor.read_u32::().unwrap(); //ignore results, just doing this to skip 4 bytes. while 0 < cursor.get_ref().len() { + + println!("number of bytes left = {}", cursor.get_ref().len() ); + + if std::mem::size_of::() >= cursor.get_ref().len(){ + println!("Error reading directory signature"); + return false; + } + let ret = cursor.read_u32::(); + if ret.is_err(){ + break; + } + let sig = ret.unwrap(); + + match sig { + ALZ_LOCAL_FILE_HEADER=>{ + if parse_local_file_header(&mut cursor){ + println!("Found a local file header\n"); + continue; + } + } + ALZ_CENTRAL_DIRECTORY_HEADER=>{ + if parse_central_directory_header(&mut cursor){ + println!("Found a central directory header\n"); + continue; + } + } + ALZ_END_OF_CENTRAL_DIRECTORY_HEADER=>{ + /*This is the end, nothing really to do here.*/ + println!("Found an end of central directory header\n"); + } + _ => { + /*Parse error, maybe try and extract what is there???*/ + assert!(false, "NOT A VALID FILE IN MATCH"); + } + } + + + /* if parse_local_file_header(&mut cursor){ println!("Found a local file header\n"); continue; @@ -364,6 +412,7 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { println!("NOT A VALID FILE"); assert!(false, "NOT A VALID FILE"); return false; + */ } // println!("bytes : {:02X} {:02x} {:02x}", sv[0], sv[1], sv[2]); From d97b6757a8c8a9147f3ea523d545b16e5fd02567 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 13:54:07 -0800 Subject: [PATCH 25/79] blah --- CLAM-2256/src/main.rs | 111 ++++-------------------------------------- 1 file changed, 9 insertions(+), 102 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 0cda48b3a0..56ca41c75a 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -239,33 +239,22 @@ impl AlzLocalFileHeader { /* Check for the ALZ file header. */ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { + /* if std::mem::size_of::() >= cursor.get_ref().len(){ return false; } return ALZ_FILE_HEADER == cursor.read_u32::().unwrap(); -} - -/* -fn is_alz_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { - if std::mem::size_of::() >= cursor.get_ref().len(){ - return false; + */ + let ret = cursor.read_u32::(); + if ret.is_ok() { + return ALZ_FILE_HEADER == ret.unwrap(); } - - return ALZ_LOCAL_FILE_HEADER == cursor.read_u32::().unwrap(); + return false; } -*/ - fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ - /* - if !is_alz_local_file_header(cursor){ - println!("Parse ERROR: Not a local file header"); - return false; - } - */ - let res = AlzLocalFileHeader::new(cursor); if res.is_err(){ println!("Parse ERROR: Not a local file header (2)"); @@ -276,77 +265,26 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ let local_file_header = res.unwrap(); println!("HERE HERE HERE, continue parsing the headers {}", local_file_header._start_of_compressed_data); - println!("cursor.position() = {}", cursor.position() ); return true; } -/* -fn is_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { - if std::mem::size_of::() >= cursor.get_ref().len(){ - return false; - } - - //return ALZ_CENTRAL_DIRECTORY_HEADER == cursor.read_u32::().unwrap(); - - println!("cursor.position = {}", cursor.position()); - let tmp = cursor.read_u32::().unwrap(); - println!("tmp = {}", tmp); - return ALZ_CENTRAL_DIRECTORY_HEADER == tmp; -} -*/ - fn parse_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ - /* - println!("cursor.position() = {}", cursor.position() ); - if !is_central_directory_header(cursor) { - println!("Parse ERROR: Not a central directory header"); - return false; - } - */ - - if 8 >= cursor.get_ref().len(){ - return false; - } - /* * This is ignored in unalz (UnAlz.cpp ReadCentralDirectoryStructure). * * It actually reads 12 bytes, and I think it happens to work because EOF is hit on the next * read, which it does not consider an error. */ - cursor.read_u64::().unwrap(); - - return true; -} - -/* -fn is_end_of_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> bool { - if std::mem::size_of::() >= cursor.get_ref().len(){ - return false; - } - - return ALZ_END_OF_CENTRAL_DIRECTORY_HEADER == cursor.read_u32::().unwrap(); + let ret = cursor.read_u64::(); + return ret.is_ok(); } -fn parse_end_of_central_directory_record(cursor: &mut std::io::Cursor<&Vec>) -> bool{ - if !is_end_of_central_directory_header(cursor) { - println!("Parse ERROR: Not an end of central directory header"); - return false; - } - - return true; -} -*/ - fn process_file(bytes: &Vec, out_dir: &String) -> bool { println!("Outdir = {}", out_dir); - /*The first file header should start at 8, - * assuming this is actualy an alz file.*/ -// let idx: usize = 8; let mut cursor = Cursor::new(bytes); if !is_alz(&mut cursor){ @@ -359,12 +297,6 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { while 0 < cursor.get_ref().len() { - println!("number of bytes left = {}", cursor.get_ref().len() ); - - if std::mem::size_of::() >= cursor.get_ref().len(){ - println!("Error reading directory signature"); - return false; - } let ret = cursor.read_u32::(); if ret.is_err(){ break; @@ -393,34 +325,9 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { assert!(false, "NOT A VALID FILE IN MATCH"); } } - - - /* - if parse_local_file_header(&mut cursor){ - println!("Found a local file header\n"); - continue; - } - if parse_central_directory_header(&mut cursor){ - println!("Found a central directory header\n"); - continue; - } - if parse_end_of_central_directory_record(&mut cursor){ - println!("Found an end of central directory header\n"); - continue; - } - - println!("NOT A VALID FILE"); - assert!(false, "NOT A VALID FILE"); - return false; - */ } -// println!("bytes : {:02X} {:02x} {:02x}", sv[0], sv[1], sv[2]); - - - println!("Is ALZ (so far), continuing"); - - /*After reading the initial header, appears to be skipping 4 bytes (maybe they are ignored) */ + println!("Is ALZ (so far), need to decompress/decrypt the file and check the crc."); return true; From ef27375b237e9bd6d4768231fda934443412537b Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 14:00:25 -0800 Subject: [PATCH 26/79] blah --- CLAM-2256/src/main.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 56ca41c75a..ce7da23166 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -238,14 +238,6 @@ impl AlzLocalFileHeader { /* Check for the ALZ file header. */ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { - - /* - if std::mem::size_of::() >= cursor.get_ref().len(){ - return false; - } - - return ALZ_FILE_HEADER == cursor.read_u32::().unwrap(); - */ let ret = cursor.read_u32::(); if ret.is_ok() { return ALZ_FILE_HEADER == ret.unwrap(); @@ -295,7 +287,7 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { } cursor.read_u32::().unwrap(); //ignore results, just doing this to skip 4 bytes. - while 0 < cursor.get_ref().len() { + loop { let ret = cursor.read_u32::(); if ret.is_err(){ From eb6eea54227ffa7907e1a94de7adfbf115dc1f26 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 14:09:48 -0800 Subject: [PATCH 27/79] blah --- CLAM-2256/src/main.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index ce7da23166..7c15bdf563 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -59,7 +59,29 @@ impl AlzLocalFileHeader { return 0 != (self._head._file_descriptor & 0x8 ); } - pub fn new( cursor: &mut std::io::Cursor<&Vec> ) -> Result { + pub fn new() -> Self { + + Self { + _head : AlzLocalFileHeaderHead { + _file_name_length : 0, + _file_attribute : 0, + _file_time_date: 0, + _file_descriptor : 0, + _unknown : 0, + }, + + _compression_method : 0, + _unknown : 0, + _file_crc : 0, + _compressed_size : 0, + _uncompressed_size : 0, + _file_name : "".to_string(), + _enc_chk: [0; ALZ_ENCR_HEADER_LEN as usize], + _start_of_compressed_data: 0, + } + } + + pub fn parse( &mut self, cursor: &mut std::io::Cursor<&Vec> ) -> Result<(), ALZParseError> { //let mut is_data_descriptor : bool = false; if size_of::() >= cursor.get_ref().len(){ @@ -232,7 +254,7 @@ impl AlzLocalFileHeader { assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); } - return Ok(ret); + return Ok(()); } } @@ -247,14 +269,16 @@ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ - let res = AlzLocalFileHeader::new(cursor); + let mut local_file_header = AlzLocalFileHeader::new(); + + let res = local_file_header.parse(cursor); if res.is_err(){ println!("Parse ERROR: Not a local file header (2)"); return false; } /*TODO: Is it safe to call unwrap here, since I already called 'is_err' */ - let local_file_header = res.unwrap(); + //let local_file_header = res.unwrap(); println!("HERE HERE HERE, continue parsing the headers {}", local_file_header._start_of_compressed_data); From 57a99efeb176034cd79d836331c2b128c2601d34 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 14:30:26 -0800 Subject: [PATCH 28/79] blah --- CLAM-2256/src/main.rs | 157 ++++++++++++++++++++++++++++++++---------- 1 file changed, 122 insertions(+), 35 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 7c15bdf563..7ad38d2323 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -84,10 +84,44 @@ impl AlzLocalFileHeader { pub fn parse( &mut self, cursor: &mut std::io::Cursor<&Vec> ) -> Result<(), ALZParseError> { //let mut is_data_descriptor : bool = false; + /* if size_of::() >= cursor.get_ref().len(){ return Err(ALZParseError{}); } + */ + let mut tu16 = cursor.read_u16::(); + if tu16.is_err(){ + return Err(ALZParseError{}); + } + self._head._file_name_length = tu16.unwrap(); + + let mut tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._head._file_attribute = tu8.unwrap(); + + let mut tu32 = cursor.read_u32::(); + if tu32.is_err() { + return Err(ALZParseError{}); + } + self._head._file_time_date = tu32.unwrap(); + + tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._head._file_descriptor = tu8.unwrap(); + + tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._head._unknown = tu8.unwrap(); + + + /* let mut ret = Self { /*TODO: Is it safe to call unwrap here, since I already checked that there is * enough space in the buffer? @@ -109,8 +143,9 @@ impl AlzLocalFileHeader { _enc_chk: [0; ALZ_ENCR_HEADER_LEN as usize], _start_of_compressed_data: 0, }; + */ - if 0 == ret._head._file_name_length { + if 0 == self._head._file_name_length { println!("Filename length cannot be zero"); return Err(ALZParseError{}); } @@ -124,7 +159,7 @@ impl AlzLocalFileHeader { //assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); //} - let byte_len = ret._head._file_descriptor / 0x10; + let byte_len = self._head._file_descriptor / 0x10; println!("byte_len = {}", byte_len); if byte_len > 0 { @@ -132,38 +167,93 @@ impl AlzLocalFileHeader { return Err(ALZParseError{}); } - ret._compression_method = cursor.read_u8::<>().unwrap(); - ret._unknown = cursor.read_u8::<>().unwrap(); - ret._file_crc = cursor.read_u32::().unwrap(); + self._compression_method = cursor.read_u8::<>().unwrap(); + self._unknown = cursor.read_u8::<>().unwrap(); + self._file_crc = cursor.read_u32::().unwrap(); match byte_len { 1 => { + /* if (size_of::() * 2) >= cursor.get_ref().len() { return Err(ALZParseError{}); } ret._compressed_size = cursor.read_u8::<>().unwrap() as u64; ret._uncompressed_size = cursor.read_u8::<>().unwrap() as u64; + */ + + tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._compressed_size = tu8.unwrap() as u64; + + tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._uncompressed_size = tu8.unwrap() as u64; }, 2 => { + /* if (size_of::() * 2) >= cursor.get_ref().len() { return Err(ALZParseError{}); } ret._compressed_size = cursor.read_u16::().unwrap() as u64; ret._uncompressed_size = cursor.read_u16::().unwrap() as u64; + */ + tu16 = cursor.read_u16::(); + if tu16.is_err() { + return Err(ALZParseError{}); + } + self._compressed_size = tu16.unwrap() as u64; + + tu16 = cursor.read_u16::(); + if tu16.is_err() { + return Err(ALZParseError{}); + } + self._uncompressed_size = tu16.unwrap() as u64; + }, 4 => { + /* if (size_of::() * 2) >= cursor.get_ref().len() { return Err(ALZParseError{}); } ret._compressed_size = cursor.read_u32::().unwrap() as u64; ret._uncompressed_size = cursor.read_u32::().unwrap() as u64; + + */ + tu32 = cursor.read_u32::(); + if tu32.is_err() { + return Err(ALZParseError{}); + } + self._compressed_size = tu32.unwrap() as u64; + + tu32 = cursor.read_u32::(); + if tu32.is_err() { + return Err(ALZParseError{}); + } + self._uncompressed_size = tu32.unwrap() as u64; }, 8 => { + /* if (size_of::() * 2) >= cursor.get_ref().len() { return Err(ALZParseError{}); } ret._compressed_size = cursor.read_u64::().unwrap() as u64; ret._uncompressed_size = cursor.read_u64::().unwrap() as u64; + */ + let mut tu64 = cursor.read_u64::(); + if tu64.is_err() { + return Err(ALZParseError{}); + } + self._compressed_size = tu64.unwrap() as u64; + + tu64 = cursor.read_u64::(); + if tu64.is_err() { + return Err(ALZParseError{}); + } + self._uncompressed_size = tu64.unwrap() as u64; }, _ => return Err(ALZParseError{}), } @@ -181,25 +271,25 @@ impl AlzLocalFileHeader { */ } - if ret._head._file_name_length as usize >= cursor.get_ref().len() { + if self._head._file_name_length as usize >= cursor.get_ref().len() { return Err(ALZParseError{}); } let mut filename = vec![0u8, 1]; /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ - for _i in 0..ret._head._file_name_length { + for _i in 0..self._head._file_name_length { filename.push( cursor.read_u8::<>().unwrap()); } let res = String::from_utf8(filename); if res.is_ok(){ - ret._file_name = res.unwrap(); + self._file_name = res.unwrap(); } else { /*TODO: Other formats*/ assert!(false, "NOT sure if other filename formats are supported here"); } - if ret.is_encrypted() { + if self.is_encrypted() { if ALZ_ENCR_HEADER_LEN as usize > cursor.get_ref().len() { return Err(ALZParseError{}); } @@ -207,50 +297,50 @@ impl AlzLocalFileHeader { /*TODO: Is it safe to call unwrap here, since I already checked that there are enough * bytes? */ - cursor.read_exact(&mut ret._enc_chk).unwrap(); + cursor.read_exact(&mut self._enc_chk).unwrap(); } - ret._start_of_compressed_data = cursor.position(); - println!("ret._start_of_compressed_data = {}", ret._start_of_compressed_data ); - println!("ret._compressed_size = {}", ret._compressed_size ); + self._start_of_compressed_data = cursor.position(); + println!("self._start_of_compressed_data = {}", self._start_of_compressed_data ); + println!("self._compressed_size = {}", self._compressed_size ); - cursor.set_position(ret._start_of_compressed_data + ret._compressed_size); + cursor.set_position(self._start_of_compressed_data + self._compressed_size); println!("cursor.position() = {}", cursor.position() ); - println!("ret._head._file_name_length = {:x}", ret._head._file_name_length); - println!("ret._head._file_attribute = {:02x}", ret._head._file_attribute); - println!("ret._head._file_time_date = {:x}", ret._head._file_time_date); - println!("ret._head._file_descriptor = {:x}", ret._head._file_descriptor); - println!("ret._head._unknown = {:x}", ret._head._unknown); + println!("self._head._file_name_length = {:x}", self._head._file_name_length); + println!("self._head._file_attribute = {:02x}", self._head._file_attribute); + println!("self._head._file_time_date = {:x}", self._head._file_time_date); + println!("self._head._file_descriptor = {:x}", self._head._file_descriptor); + println!("self._head._unknown = {:x}", self._head._unknown); - println!("ret._compression_method = {:x}", ret._compression_method); - println!("ret._unknown = {:x}", ret._unknown); - println!("ret._file_crc = {:x}", ret._file_crc); - println!("ret._compressed_size = {:x}", ret._compressed_size); - println!("ret._uncompressed_size = {:x}", ret._uncompressed_size); + println!("self._compression_method = {:x}", self._compression_method); + println!("self._unknown = {:x}", self._unknown); + println!("self._file_crc = {:x}", self._file_crc); + println!("self._compressed_size = {:x}", self._compressed_size); + println!("self._uncompressed_size = {:x}", self._uncompressed_size); - println!("ret._file_name = {}", ret._file_name); + println!("self._file_name = {}", self._file_name); - print!("ret._enc_chk = "); + print!("self._enc_chk = "); for i in 0..ALZ_ENCR_HEADER_LEN { if 0 != i { print!(" "); } - print!("{}", ret._enc_chk[i as usize]); + print!("{}", self._enc_chk[i as usize]); } println!(""); - println!("is_encrypted = {}", ret.is_encrypted()); - println!("is_data_descriptor = {}", ret.is_data_descriptor()); + println!("is_encrypted = {}", self.is_encrypted()); + println!("is_data_descriptor = {}", self.is_data_descriptor()); - println!("ret._start_of_compressed_data = {}", ret._start_of_compressed_data); + println!("self._start_of_compressed_data = {}", self._start_of_compressed_data); - if ret.is_encrypted() { + if self.is_encrypted() { assert!(false, "ENCRYPTION UNIMPLEMENTED"); } - if ret.is_data_descriptor() { + if self.is_data_descriptor() { assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); } @@ -277,9 +367,6 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ return false; } - /*TODO: Is it safe to call unwrap here, since I already called 'is_err' */ - //let local_file_header = res.unwrap(); - println!("HERE HERE HERE, continue parsing the headers {}", local_file_header._start_of_compressed_data); return true; From 7a751bfac403e97a7d18c95935553c5f46bb3b63 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 14:35:36 -0800 Subject: [PATCH 29/79] blah --- CLAM-2256/src/main.rs | 92 ++++++++----------------------------------- 1 file changed, 17 insertions(+), 75 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 7ad38d2323..5da2291e7e 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -82,13 +82,6 @@ impl AlzLocalFileHeader { } pub fn parse( &mut self, cursor: &mut std::io::Cursor<&Vec> ) -> Result<(), ALZParseError> { - //let mut is_data_descriptor : bool = false; - - /* - if size_of::() >= cursor.get_ref().len(){ - return Err(ALZParseError{}); - } - */ let mut tu16 = cursor.read_u16::(); if tu16.is_err(){ @@ -120,67 +113,38 @@ impl AlzLocalFileHeader { } self._head._unknown = tu8.unwrap(); - - /* - let mut ret = Self { - /*TODO: Is it safe to call unwrap here, since I already checked that there is - * enough space in the buffer? - */ - _head : AlzLocalFileHeaderHead { - _file_name_length : cursor.read_u16::().unwrap(), - _file_attribute : cursor.read_u8::<>().unwrap(), - _file_time_date: cursor.read_u32::().unwrap(), - _file_descriptor : cursor.read_u8::<>().unwrap(), - _unknown : cursor.read_u8::<>().unwrap(), - }, - - _compression_method : 0, - _unknown : 0, - _file_crc : 0, - _compressed_size : 0, - _uncompressed_size : 0, - _file_name : "".to_string(), - _enc_chk: [0; ALZ_ENCR_HEADER_LEN as usize], - _start_of_compressed_data: 0, - }; - */ - if 0 == self._head._file_name_length { println!("Filename length cannot be zero"); return Err(ALZParseError{}); } - //if 0 != (ret._head._file_descriptor & 0x8) { - //is_data_descriptor = true; - //} - - - //if is_data_descriptor { - //assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); - //} - let byte_len = self._head._file_descriptor / 0x10; - println!("byte_len = {}", byte_len); if byte_len > 0 { if (size_of::() + size_of::() + size_of::()) >= cursor.get_ref().len(){ return Err(ALZParseError{}); } - self._compression_method = cursor.read_u8::<>().unwrap(); - self._unknown = cursor.read_u8::<>().unwrap(); - self._file_crc = cursor.read_u32::().unwrap(); + tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._compression_method = tu8.unwrap(); + + tu8 = cursor.read_u8::<>(); + if tu8.is_err() { + return Err(ALZParseError{}); + } + self._unknown = tu8.unwrap(); + + tu32 = cursor.read_u32::(); + if tu32.is_err() { + return Err(ALZParseError{}); + } + self._file_crc = tu32.unwrap(); match byte_len { 1 => { - /* - if (size_of::() * 2) >= cursor.get_ref().len() { - return Err(ALZParseError{}); - } - ret._compressed_size = cursor.read_u8::<>().unwrap() as u64; - ret._uncompressed_size = cursor.read_u8::<>().unwrap() as u64; - */ - tu8 = cursor.read_u8::<>(); if tu8.is_err() { return Err(ALZParseError{}); @@ -194,13 +158,6 @@ impl AlzLocalFileHeader { self._uncompressed_size = tu8.unwrap() as u64; }, 2 => { - /* - if (size_of::() * 2) >= cursor.get_ref().len() { - return Err(ALZParseError{}); - } - ret._compressed_size = cursor.read_u16::().unwrap() as u64; - ret._uncompressed_size = cursor.read_u16::().unwrap() as u64; - */ tu16 = cursor.read_u16::(); if tu16.is_err() { return Err(ALZParseError{}); @@ -215,14 +172,6 @@ impl AlzLocalFileHeader { }, 4 => { - /* - if (size_of::() * 2) >= cursor.get_ref().len() { - return Err(ALZParseError{}); - } - ret._compressed_size = cursor.read_u32::().unwrap() as u64; - ret._uncompressed_size = cursor.read_u32::().unwrap() as u64; - - */ tu32 = cursor.read_u32::(); if tu32.is_err() { return Err(ALZParseError{}); @@ -236,13 +185,6 @@ impl AlzLocalFileHeader { self._uncompressed_size = tu32.unwrap() as u64; }, 8 => { - /* - if (size_of::() * 2) >= cursor.get_ref().len() { - return Err(ALZParseError{}); - } - ret._compressed_size = cursor.read_u64::().unwrap() as u64; - ret._uncompressed_size = cursor.read_u64::().unwrap() as u64; - */ let mut tu64 = cursor.read_u64::(); if tu64.is_err() { return Err(ALZParseError{}); From 5a6bc6216ae42ad21460056b002ce60681fc31e4 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 25 Jan 2024 14:36:14 -0800 Subject: [PATCH 30/79] blah --- CLAM-2256/src/main.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 5da2291e7e..33f301927b 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -2,7 +2,7 @@ use std::fs; //use std::io; use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; -use std::mem::size_of; +//use std::mem::size_of; use std::io::Read; @@ -121,10 +121,6 @@ impl AlzLocalFileHeader { let byte_len = self._head._file_descriptor / 0x10; if byte_len > 0 { - if (size_of::() + size_of::() + size_of::()) >= cursor.get_ref().len(){ - return Err(ALZParseError{}); - } - tu8 = cursor.read_u8::<>(); if tu8.is_err() { return Err(ALZParseError{}); From e6fb42410d60445d3161974dcc60580632974b20 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Fri, 26 Jan 2024 15:36:39 -0800 Subject: [PATCH 31/79] blah --- CLAM-2256/Cargo.lock | 57 ++++++++++++++++ CLAM-2256/Cargo.toml | 2 + CLAM-2256/run.sh | 4 +- CLAM-2256/src/main.rs | 149 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 205 insertions(+), 7 deletions(-) diff --git a/CLAM-2256/Cargo.lock b/CLAM-2256/Cargo.lock index ff7e885c94..e63f97f44b 100644 --- a/CLAM-2256/Cargo.lock +++ b/CLAM-2256/Cargo.lock @@ -2,22 +2,79 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + [[package]] name = "cursor" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a48749e67c8bd54d6d4b2a191afaf9bd9d656d22c0852698c990a354fb86fd2c" +[[package]] +name = "deflate" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" +dependencies = [ + "adler32", +] + +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "open_alz" version = "0.1.0" dependencies = [ "byteorder", "cursor", + "deflate", + "flate2", ] diff --git a/CLAM-2256/Cargo.toml b/CLAM-2256/Cargo.toml index daee1148ee..55d0147bdf 100644 --- a/CLAM-2256/Cargo.toml +++ b/CLAM-2256/Cargo.toml @@ -8,5 +8,7 @@ edition = "2021" [dependencies] byteorder = "1.5.0" cursor = "2.3.0" +deflate = "1.0.0" +flate2 = "1.0.28" [workspace] diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index 6614f51245..78576e5357 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -1,5 +1,5 @@ #!/bin/bash cargo run alz_example.alz outDir -cargo run test outDir -cargo run +#cargo run test outDir +#cargo run diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 33f301927b..f226fcfe8f 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -4,12 +4,25 @@ use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; //use std::mem::size_of; +//use deflate::deflate_bytes; +//use flate2::Decompress; +//use flate2::FlushDecompress; +use flate2::read::GzDecoder; + +//use flate2::write::{GzEncoder}; +//use flate2::read::{GzDecoder}; + + use std::io::Read; #[derive(Debug)] struct ALZParseError { } +#[derive(Debug)] +struct ALZExtractError { +} + const ALZ_FILE_HEADER: u32 = 0x015a4c41; const ALZ_LOCAL_FILE_HEADER: u32 = 0x015a4c42; const ALZ_CENTRAL_DIRECTORY_HEADER: u32 = 0x015a4c43; @@ -82,6 +95,9 @@ impl AlzLocalFileHeader { } pub fn parse( &mut self, cursor: &mut std::io::Cursor<&Vec> ) -> Result<(), ALZParseError> { + /* + * TODO: Should probably rename this to parse_header or something. + */ let mut tu16 = cursor.read_u16::(); if tu16.is_err(){ @@ -213,12 +229,20 @@ impl AlzLocalFileHeader { return Err(ALZParseError{}); } - let mut filename = vec![0u8, 1]; + let mut filename: Vec = Vec::new(); /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ for _i in 0..self._head._file_name_length { - filename.push( cursor.read_u8::<>().unwrap()); + let ret = cursor.read_u8::<>(); + if ret.is_err() { + println!("Error reading contents of the file name"); + return Err(ALZParseError{}); + } + + filename.push( ret.unwrap()); } + + let res = String::from_utf8(filename); if res.is_ok(){ self._file_name = res.unwrap(); @@ -240,7 +264,6 @@ impl AlzLocalFileHeader { self._start_of_compressed_data = cursor.position(); println!("self._start_of_compressed_data = {}", self._start_of_compressed_data ); - println!("self._compressed_size = {}", self._compressed_size ); cursor.set_position(self._start_of_compressed_data + self._compressed_size); println!("cursor.position() = {}", cursor.position() ); @@ -284,6 +307,116 @@ impl AlzLocalFileHeader { return Ok(()); } + + fn extract_file_deflate(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ + println!("Outdir = {}", out_dir); + println!("start of compressed data = {}", self._start_of_compressed_data); + cursor.set_position(self._start_of_compressed_data); + + let mut contents: Vec = Vec::new(); + + +contents.push(0x1f); +contents.push(0x8b ); +contents.push(0x08 ); +contents.push(0x08 ); +contents.push(0xc6 ); +contents.push(0xa7 ); +contents.push(0x1c ); +contents.push(0x4a ); +contents.push(0x00 ); +contents.push(0x03 ); +contents.push(0x61 ); +contents.push(0x6c ); +contents.push(0x7a ); +contents.push(0x20 ); +contents.push(0x74 ); +contents.push(0x65 ); +contents.push(0x73 ); +contents.push(0x74 ); +contents.push(0x20 ); +contents.push(0x66 ); +contents.push(0x69 ); +contents.push(0x6c ); +contents.push(0x65 ); +contents.push(0x2e ); +contents.push(0x74 ); +contents.push(0x78 ); +contents.push(0x74 ); +contents.push(0x00 ); + + + + /*TODO: Figure out the correct way to allocate a vector of dynamic size and call + * cursor.read_exact, instead of having a loop of reads.*/ + for _i in 0..self._compressed_size { + let ret = cursor.read_u8::<>(); + if ret.is_err() { + println!("Cannot read full amount of data"); + return Err(ALZExtractError{}); + } + + contents.push( ret.unwrap()); + } + +contents.push(0x17 ); +contents.push(0x5f ); +contents.push(0x58 ); +contents.push(0xf7 ); +contents.push(0x5d ); +contents.push(0x00 ); +contents.push(0x00 ); +contents.push(0x00); + + //let mut data:Vec = Vec::new(); + + + + + + let mut d = GzDecoder::new(&*contents); + let mut s = String::new(); + let ret = d.read_to_string(&mut s); + if ret.is_err() { + assert!(false, "ERROR in decompress"); + } + println!("Extracted data = '{}'", s); + + + return Ok(()); + } + + fn extract_file(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ + const ALZ_COMP_NOCOMP: u8 = 0; + const ALZ_COMP_BZIP2: u8 = 1; + const ALZ_COMP_DEFLATE: u8 = 2; + + /*TODO: Consider extracting encrypted data to separate files. Maybe + * someone is interested in signaturing those files??? + */ + if self.is_encrypted(){ + println!("Figure out if we can support encryption"); + return Err(ALZExtractError{}); + } + + match self._compression_method { + ALZ_COMP_NOCOMP=>{ + assert!(false, "Nocomp Unimplemented"); + } + ALZ_COMP_BZIP2=>{ + assert!(false, "Bzip2 Unimplemented"); + } + ALZ_COMP_DEFLATE=>{ + return self.extract_file_deflate(cursor, out_dir); + } + _=>{ + println!("Unsupported compression"); + return Err(ALZExtractError{}); + } + } + + return Ok(()); + } } /* Check for the ALZ file header. */ @@ -295,7 +428,7 @@ fn is_alz(cursor: &mut std::io::Cursor<&Vec>) -> bool { return false; } -fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ +fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> bool{ let mut local_file_header = AlzLocalFileHeader::new(); @@ -305,6 +438,12 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>) -> bool{ return false; } + let res2 = local_file_header.extract_file(cursor, out_dir); + if res2.is_err() { + println!("Extract ERROR: "); + return false; + } + println!("HERE HERE HERE, continue parsing the headers {}", local_file_header._start_of_compressed_data); return true; @@ -346,7 +485,7 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { match sig { ALZ_LOCAL_FILE_HEADER=>{ - if parse_local_file_header(&mut cursor){ + if parse_local_file_header(&mut cursor, out_dir){ println!("Found a local file header\n"); continue; } From d708dacf807da0b260a7b9140bf9e71d5ce05549 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Fri, 26 Jan 2024 15:37:33 -0800 Subject: [PATCH 32/79] blah --- CLAM-2256/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index f226fcfe8f..2ec19dd323 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -382,6 +382,7 @@ contents.push(0x00); } println!("Extracted data = '{}'", s); + println!("TODO!!!!! FIGURE OUT HOW TO DECOMPRESS WITHOUT THE HEADER AND FOOTER THAT I HARDCODED"); return Ok(()); } From 9c5e9bd01658868a02ea17f85c1efb4a300b917b Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Fri, 26 Jan 2024 15:54:12 -0800 Subject: [PATCH 33/79] blah --- CLAM-2256/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 2ec19dd323..2aaa47ab53 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -315,6 +315,10 @@ impl AlzLocalFileHeader { let mut contents: Vec = Vec::new(); + //TODO: Consider putting a header on and formatting this properly, so + //we don't have to implement deflate. + //https://en.wikipedia.org/wiki/Gzip + contents.push(0x1f); contents.push(0x8b ); From a5c5e94047b13395769904f20b48f6bd61484768 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 08:06:01 -0800 Subject: [PATCH 34/79] blah --- CLAM-2256/src/main.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 2aaa47ab53..a3ec155b50 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -318,18 +318,34 @@ impl AlzLocalFileHeader { //TODO: Consider putting a header on and formatting this properly, so //we don't have to implement deflate. //https://en.wikipedia.org/wiki/Gzip + //https://www.rfc-editor.org/rfc/rfc1952.html + //magic number contents.push(0x1f); contents.push(0x8b ); + +//compression method (0x8 for deflate) contents.push(0x08 ); -contents.push(0x08 ); + +//header flags (don't know what they mean yet) +//0x8 sets the FNAME flag. May be able to get away with setting this to 0, and not putting the +//name in. Going to try that. +contents.push(0x08 ); + +//timestamp contents.push(0xc6 ); contents.push(0xa7 ); contents.push(0x1c ); contents.push(0x4a ); + +//compression flags contents.push(0x00 ); + +//operating system id contents.push(0x03 ); + +//The following is the filename followed by a zero. contents.push(0x61 ); contents.push(0x6c ); contents.push(0x7a ); @@ -363,10 +379,13 @@ contents.push(0x00 ); contents.push( ret.unwrap()); } + //checksum of the original uncompressed data. (Get it from the FILE HEADER) contents.push(0x17 ); contents.push(0x5f ); contents.push(0x58 ); contents.push(0xf7 ); + +//length of the original uncompressed data. contents.push(0x5d ); contents.push(0x00 ); contents.push(0x00 ); From 09dce5d22bb2b4416de119643a55ab07c39e0569 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 08:07:53 -0800 Subject: [PATCH 35/79] blah --- CLAM-2256/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index a3ec155b50..2821c075b6 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -331,13 +331,22 @@ contents.push(0x08 ); //header flags (don't know what they mean yet) //0x8 sets the FNAME flag. May be able to get away with setting this to 0, and not putting the //name in. Going to try that. -contents.push(0x08 ); +//contents.push(0x08 ); +contents.push(0); //timestamp +/* contents.push(0xc6 ); contents.push(0xa7 ); contents.push(0x1c ); contents.push(0x4a ); +*/ +/*Don't need an actual timestamp either.*/ +contents.push(0); +contents.push(0); +contents.push(0); +contents.push(0); + //compression flags contents.push(0x00 ); @@ -346,6 +355,7 @@ contents.push(0x00 ); contents.push(0x03 ); //The following is the filename followed by a zero. +/* contents.push(0x61 ); contents.push(0x6c ); contents.push(0x7a ); @@ -364,6 +374,7 @@ contents.push(0x74 ); contents.push(0x78 ); contents.push(0x74 ); contents.push(0x00 ); +*/ From 94e2730d63ad7c5790ff716331b72718e4925d2a Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 08:10:51 -0800 Subject: [PATCH 36/79] blah --- CLAM-2256/src/main.rs | 75 +++++++++++-------------------------------- 1 file changed, 18 insertions(+), 57 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 2821c075b6..14eba77dbb 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -319,64 +319,29 @@ impl AlzLocalFileHeader { //we don't have to implement deflate. //https://en.wikipedia.org/wiki/Gzip //https://www.rfc-editor.org/rfc/rfc1952.html - + //https://www.ietf.org/rfc/rfc1952.txt //magic number -contents.push(0x1f); -contents.push(0x8b ); - -//compression method (0x8 for deflate) -contents.push(0x08 ); - -//header flags (don't know what they mean yet) -//0x8 sets the FNAME flag. May be able to get away with setting this to 0, and not putting the -//name in. Going to try that. -//contents.push(0x08 ); -contents.push(0); - -//timestamp -/* -contents.push(0xc6 ); -contents.push(0xa7 ); -contents.push(0x1c ); -contents.push(0x4a ); -*/ -/*Don't need an actual timestamp either.*/ -contents.push(0); -contents.push(0); -contents.push(0); -contents.push(0); - - -//compression flags -contents.push(0x00 ); + contents.push(0x1f); + contents.push(0x8b ); -//operating system id -contents.push(0x03 ); - -//The following is the filename followed by a zero. -/* -contents.push(0x61 ); -contents.push(0x6c ); -contents.push(0x7a ); -contents.push(0x20 ); -contents.push(0x74 ); -contents.push(0x65 ); -contents.push(0x73 ); -contents.push(0x74 ); -contents.push(0x20 ); -contents.push(0x66 ); -contents.push(0x69 ); -contents.push(0x6c ); -contents.push(0x65 ); -contents.push(0x2e ); -contents.push(0x74 ); -contents.push(0x78 ); -contents.push(0x74 ); -contents.push(0x00 ); -*/ + //compression method (0x8 for deflate) + contents.push(0x08 ); + + //header flags + contents.push(0); + //timestamp, doesn't matter what it is. + contents.push(0); + contents.push(0); + contents.push(0); + contents.push(0); + //compression flags + contents.push(0x00 ); + + //operating system id + contents.push(0x03 ); /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ @@ -402,8 +367,6 @@ contents.push(0x00 ); contents.push(0x00 ); contents.push(0x00); - //let mut data:Vec = Vec::new(); - @@ -416,8 +379,6 @@ contents.push(0x00); } println!("Extracted data = '{}'", s); - println!("TODO!!!!! FIGURE OUT HOW TO DECOMPRESS WITHOUT THE HEADER AND FOOTER THAT I HARDCODED"); - return Ok(()); } From 966a29b92a36e51d95602ab47afc316eb5f14409 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 08:11:21 -0800 Subject: [PATCH 37/79] blah --- CLAM-2256/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 14eba77dbb..46f2962c5c 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -341,7 +341,7 @@ impl AlzLocalFileHeader { contents.push(0x00 ); //operating system id - contents.push(0x03 ); + contents.push(0); /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ From 0a26f6402f7d77f235f556d2ffe9da2b7df57ee7 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 08:46:45 -0800 Subject: [PATCH 38/79] blah --- CLAM-2256/src/main.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 46f2962c5c..a9161d449f 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -356,20 +356,18 @@ impl AlzLocalFileHeader { } //checksum of the original uncompressed data. (Get it from the FILE HEADER) -contents.push(0x17 ); -contents.push(0x5f ); -contents.push(0x58 ); -contents.push(0xf7 ); - -//length of the original uncompressed data. -contents.push(0x5d ); -contents.push(0x00 ); -contents.push(0x00 ); -contents.push(0x00); - - - + //let mut bytes = self._file_crc.to_le().to_ne_bytes(); + let mut bytes = self._file_crc.to_le_bytes(); + for i in 0..4{ + contents.push(bytes[i]); + } + //length of the original uncompressed data. + //bytes = self._uncompressed_size.to_le_bytes(); + bytes = (self._uncompressed_size as u32).to_le_bytes(); + for i in 0..4{ + contents.push(bytes[i]); + } let mut d = GzDecoder::new(&*contents); let mut s = String::new(); From 94ebac47be2ebb420466e2bf146c9dcc1d66fb05 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 09:00:57 -0800 Subject: [PATCH 39/79] blah --- CLAM-2256/src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index a9161d449f..652527c542 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -4,6 +4,9 @@ use std::io::Cursor; use byteorder::{LittleEndian, ReadBytesExt}; //use std::mem::size_of; +use std::fs::File; +use std::io::Write; + //use deflate::deflate_bytes; //use flate2::Decompress; //use flate2::FlushDecompress; @@ -370,12 +373,31 @@ impl AlzLocalFileHeader { } let mut d = GzDecoder::new(&*contents); + /* let mut s = String::new(); let ret = d.read_to_string(&mut s); + */ + let mut buffer: Vec = Vec::new(); + let ret = d.read_to_end(&mut buffer); if ret.is_err() { assert!(false, "ERROR in decompress"); } + /* println!("Extracted data = '{}'", s); + */ + + let out_ret = File::create("ftt"); + if out_ret.is_err() { + assert!(false, "Error creating output file"); + } + + let mut out = out_ret.unwrap(); + + let write_ret = out.write_all(&buffer); + if write_ret.is_err() { + assert!(false, "Error writing to file"); + } + return Ok(()); } From 6b9ed98dd5f7f7ef68415aa28e6aaa82781d8caa Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 10:11:10 -0800 Subject: [PATCH 40/79] blah --- CLAM-2256/src/main.rs | 59 +++++++++++-------------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 652527c542..b9030e060e 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -5,11 +5,14 @@ use byteorder::{LittleEndian, ReadBytesExt}; //use std::mem::size_of; use std::fs::File; +use std::fs::create_dir_all; use std::io::Write; //use deflate::deflate_bytes; //use flate2::Decompress; //use flate2::FlushDecompress; +/*There is also a MultiGzDecoder, but I think this is the one we want + * because of having to create the header manually.*/ use flate2::read::GzDecoder; //use flate2::write::{GzEncoder}; @@ -266,39 +269,8 @@ impl AlzLocalFileHeader { } self._start_of_compressed_data = cursor.position(); - println!("self._start_of_compressed_data = {}", self._start_of_compressed_data ); cursor.set_position(self._start_of_compressed_data + self._compressed_size); - println!("cursor.position() = {}", cursor.position() ); - - println!("self._head._file_name_length = {:x}", self._head._file_name_length); - println!("self._head._file_attribute = {:02x}", self._head._file_attribute); - println!("self._head._file_time_date = {:x}", self._head._file_time_date); - println!("self._head._file_descriptor = {:x}", self._head._file_descriptor); - println!("self._head._unknown = {:x}", self._head._unknown); - - println!("self._compression_method = {:x}", self._compression_method); - println!("self._unknown = {:x}", self._unknown); - println!("self._file_crc = {:x}", self._file_crc); - println!("self._compressed_size = {:x}", self._compressed_size); - println!("self._uncompressed_size = {:x}", self._uncompressed_size); - - println!("self._file_name = {}", self._file_name); - - print!("self._enc_chk = "); - for i in 0..ALZ_ENCR_HEADER_LEN { - if 0 != i { - print!(" "); - } - print!("{}", self._enc_chk[i as usize]); - } - println!(""); - - - println!("is_encrypted = {}", self.is_encrypted()); - println!("is_data_descriptor = {}", self.is_data_descriptor()); - - println!("self._start_of_compressed_data = {}", self._start_of_compressed_data); if self.is_encrypted() { assert!(false, "ENCRYPTION UNIMPLEMENTED"); @@ -313,13 +285,11 @@ impl AlzLocalFileHeader { fn extract_file_deflate(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ println!("Outdir = {}", out_dir); - println!("start of compressed data = {}", self._start_of_compressed_data); cursor.set_position(self._start_of_compressed_data); let mut contents: Vec = Vec::new(); - //TODO: Consider putting a header on and formatting this properly, so - //we don't have to implement deflate. + //Gzip file header format. //https://en.wikipedia.org/wiki/Gzip //https://www.rfc-editor.org/rfc/rfc1952.html //https://www.ietf.org/rfc/rfc1952.txt @@ -328,7 +298,7 @@ impl AlzLocalFileHeader { contents.push(0x1f); contents.push(0x8b ); - //compression method (0x8 for deflate) + //compression method (0-7 reserved, 0x8 for deflate) contents.push(0x08 ); //header flags @@ -341,7 +311,7 @@ impl AlzLocalFileHeader { contents.push(0); //compression flags - contents.push(0x00 ); + contents.push(0x00); //operating system id contents.push(0); @@ -359,7 +329,6 @@ impl AlzLocalFileHeader { } //checksum of the original uncompressed data. (Get it from the FILE HEADER) - //let mut bytes = self._file_crc.to_le().to_ne_bytes(); let mut bytes = self._file_crc.to_le_bytes(); for i in 0..4{ contents.push(bytes[i]); @@ -386,7 +355,11 @@ impl AlzLocalFileHeader { println!("Extracted data = '{}'", s); */ - let out_ret = File::create("ftt"); + //let out_ret = File::create("ftt"); + let mut temp: String = out_dir.to_owned(); + temp.push('/'); + temp.push_str(&self._file_name.to_owned()); + let out_ret = File::create(temp); if out_ret.is_err() { assert!(false, "Error creating output file"); } @@ -460,8 +433,6 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &Str return false; } - println!("HERE HERE HERE, continue parsing the headers {}", local_file_header._start_of_compressed_data); - return true; } @@ -479,8 +450,6 @@ fn parse_central_directory_header(cursor: &mut std::io::Cursor<&Vec>) -> boo fn process_file(bytes: &Vec, out_dir: &String) -> bool { - println!("Outdir = {}", out_dir); - let mut cursor = Cursor::new(bytes); if !is_alz(&mut cursor){ @@ -523,8 +492,6 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { } } - println!("Is ALZ (so far), need to decompress/decrypt the file and check the crc."); - return true; } @@ -540,6 +507,10 @@ fn main() { let out_dir = &args[2]; let bytes: Vec = fs::read(file_name).unwrap(); + let res = create_dir_all(out_dir); + if res.is_err() { + assert!(false, "Cannot create output directory {}", out_dir); + } process_file(&bytes, out_dir); } From b21d1a16520ac15c7a6aa5428cbac8b67f985d95 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 10:14:34 -0800 Subject: [PATCH 41/79] blah --- CLAM-2256/src/main.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index b9030e060e..903bb7a3d9 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -248,7 +248,6 @@ impl AlzLocalFileHeader { filename.push( ret.unwrap()); } - let res = String::from_utf8(filename); if res.is_ok(){ self._file_name = res.unwrap(); @@ -284,7 +283,6 @@ impl AlzLocalFileHeader { } fn extract_file_deflate(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ - println!("Outdir = {}", out_dir); cursor.set_position(self._start_of_compressed_data); let mut contents: Vec = Vec::new(); @@ -335,27 +333,18 @@ impl AlzLocalFileHeader { } //length of the original uncompressed data. - //bytes = self._uncompressed_size.to_le_bytes(); bytes = (self._uncompressed_size as u32).to_le_bytes(); for i in 0..4{ contents.push(bytes[i]); } let mut d = GzDecoder::new(&*contents); - /* - let mut s = String::new(); - let ret = d.read_to_string(&mut s); - */ let mut buffer: Vec = Vec::new(); let ret = d.read_to_end(&mut buffer); if ret.is_err() { assert!(false, "ERROR in decompress"); } - /* - println!("Extracted data = '{}'", s); - */ - //let out_ret = File::create("ftt"); let mut temp: String = out_dir.to_owned(); temp.push('/'); temp.push_str(&self._file_name.to_owned()); @@ -471,19 +460,16 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { match sig { ALZ_LOCAL_FILE_HEADER=>{ if parse_local_file_header(&mut cursor, out_dir){ - println!("Found a local file header\n"); continue; } } ALZ_CENTRAL_DIRECTORY_HEADER=>{ if parse_central_directory_header(&mut cursor){ - println!("Found a central directory header\n"); continue; } } ALZ_END_OF_CENTRAL_DIRECTORY_HEADER=>{ /*This is the end, nothing really to do here.*/ - println!("Found an end of central directory header\n"); } _ => { /*Parse error, maybe try and extract what is there???*/ From d17b9e21c7bb31386c55fafe933de82501d3beca Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 11:06:41 -0800 Subject: [PATCH 42/79] blah --- CLAM-2256/run.sh | 10 +++++++++- CLAM-2256/src/main.rs | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index 78576e5357..bd69cc691a 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -1,5 +1,13 @@ #!/bin/bash -cargo run alz_example.alz outDir +#cargo run alz_example.alz outDir #cargo run test outDir #cargo run + +#extracts 1 jpg, mine works the same as unalz +#cargo run samples/19d17e940e603b7fec36f147b3f8ae482cac429fdcc762f61186d4c00adce8db outDir + +cargo run samples/0abac736fb1b1dbd66901ec5258c73c543dd6b01e8d4c06970f94ff697ae1745 outDir + + + diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 903bb7a3d9..e68e7f9f12 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -218,8 +218,8 @@ impl AlzLocalFileHeader { _ => return Err(ALZParseError{}), } } else { - println!("DON'T THINK THIS IS EVER POSSIBLE, SEE IF IT COMES OUT IN TESTING!!!!!"); - assert!(false, "EXITING HERE"); +// println!("DON'T THINK THIS IS EVER POSSIBLE, SEE IF IT COMES OUT IN TESTING!!!!!"); +// assert!(false, "EXITING HERE"); /* * TODO: In 'unalz', (UnAlz.cpp, CUnAlz::ReadLocalFileheader), the condition where * byte_len (byteLen) is zero is treated as a condition that can be ignored, and @@ -228,6 +228,9 @@ impl AlzLocalFileHeader { * reported, rather than just stopping parsing when that happens. I would like to look * for a file that has that condition and see if unalz (or other unpackers) are able to * extract anything from the file. If not, we can just return here. + * + * + * NOT THE CASE */ } From 93d83f8b11d93a4c1161a3eed75a1d64e0ff3cd5 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 11:47:31 -0800 Subject: [PATCH 43/79] blah --- CLAM-2256/src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index e68e7f9f12..8038531b9b 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -69,6 +69,13 @@ struct AlzLocalFileHeader { } +enum AlzFileAttribute { + AlzFileAttributeReadonly = 0x1, + AlzFileAttributeHidden = 0x2, + AlzFileAttributeDirectory = 0x10, + AlzFileAttributeFile = 0x20, +} + impl AlzLocalFileHeader { fn is_encrypted(&mut self) -> bool { return 0 != (self._head._file_descriptor & 0x1 ); @@ -78,6 +85,10 @@ impl AlzLocalFileHeader { return 0 != (self._head._file_descriptor & 0x8 ); } + fn is_directory(&mut self) -> bool { + return 0 != ((AlzFileAttribute::AlzFileAttributeDirectory as u8) & self._head._file_attribute); + } + pub fn new() -> Self { Self { @@ -232,6 +243,13 @@ impl AlzLocalFileHeader { * * NOT THE CASE */ + + println!("I DIDN'T THINK THIS WAS POSSIBLE, CHECKING FOR DIRECTORY"); + if self.is_directory() { + println!("THIS IS A DIRECTORY"); + } else { + println!("THIS IS NOT A DIRECTORY"); + } } if self._head._file_name_length as usize >= cursor.get_ref().len() { @@ -258,6 +276,7 @@ impl AlzLocalFileHeader { /*TODO: Other formats*/ assert!(false, "NOT sure if other filename formats are supported here"); } + println!("file name = {}", self._file_name); if self.is_encrypted() { if ALZ_ENCR_HEADER_LEN as usize > cursor.get_ref().len() { From 277d7ebc2f0a0d7ea7f342b31d722a0fe0f36bba Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 11:54:00 -0800 Subject: [PATCH 44/79] blah --- CLAM-2256/src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 8038531b9b..2962ecc6bc 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -70,10 +70,10 @@ struct AlzLocalFileHeader { enum AlzFileAttribute { - AlzFileAttributeReadonly = 0x1, - AlzFileAttributeHidden = 0x2, - AlzFileAttributeDirectory = 0x10, - AlzFileAttributeFile = 0x20, + _AlzFileAttributeReadonly = 0x1, + _AlzFileAttributeHidden = 0x2, + _AlzFileAttributeDirectory = 0x10, + _AlzFileAttributeFile = 0x20, } impl AlzLocalFileHeader { @@ -86,7 +86,11 @@ impl AlzLocalFileHeader { } fn is_directory(&mut self) -> bool { - return 0 != ((AlzFileAttribute::AlzFileAttributeDirectory as u8) & self._head._file_attribute); + return 0 != ((AlzFileAttribute::_AlzFileAttributeDirectory as u8) & self._head._file_attribute); + } + + fn is_file(&mut self) -> bool { + return 0 != ((AlzFileAttribute::_AlzFileAttributeFile as u8) & self._head._file_attribute); } pub fn new() -> Self { @@ -228,6 +232,7 @@ impl AlzLocalFileHeader { }, _ => return Err(ALZParseError{}), } + assert!(self.is_file(), "NOT A FILE"); } else { // println!("DON'T THINK THIS IS EVER POSSIBLE, SEE IF IT COMES OUT IN TESTING!!!!!"); // assert!(false, "EXITING HERE"); From 2cc8ab5ee99027a3787ba88588e337541bc613d5 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 13:05:30 -0800 Subject: [PATCH 45/79] blah --- CLAM-2256/run.sh | 1 + CLAM-2256/src/main.rs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index bd69cc691a..84e347a9b0 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -9,5 +9,6 @@ cargo run samples/0abac736fb1b1dbd66901ec5258c73c543dd6b01e8d4c06970f94ff697ae1745 outDir +#cargo run samples/0e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 2962ecc6bc..fd488358b9 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -422,6 +422,17 @@ impl AlzLocalFileHeader { return Ok(()); } + + fn create_directory(&mut self, out_dir: &String) -> Result<(), ALZExtractError>{ + let mut temp: String = out_dir.to_owned(); + temp.push('/'); + temp.push_str(&self._file_name.to_owned()); + let res = create_dir_all(temp); + if res.is_err() { + return Err(ALZExtractError{}); + } + return Ok(()); + } } /* Check for the ALZ file header. */ @@ -443,10 +454,20 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &Str return false; } - let res2 = local_file_header.extract_file(cursor, out_dir); - if res2.is_err() { - println!("Extract ERROR: "); - return false; + if local_file_header.is_file() { + let res2 = local_file_header.extract_file(cursor, out_dir); + if res2.is_err() { + println!("Extract ERROR: "); + return false; + } + } else if local_file_header.is_directory() { + let res2 = local_file_header.create_directory(out_dir); + if res2.is_err() { + println!("Directory creation ERROR: "); + return false; + } + + println!("is directory"); } return true; @@ -487,15 +508,18 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { match sig { ALZ_LOCAL_FILE_HEADER=>{ if parse_local_file_header(&mut cursor, out_dir){ + println!("Found a ALZ_LOCAL_FILE_HEADER"); continue; } } ALZ_CENTRAL_DIRECTORY_HEADER=>{ if parse_central_directory_header(&mut cursor){ + println!("Found a ALZ_CENTRAL_DIRECTORY_HEADER"); continue; } } ALZ_END_OF_CENTRAL_DIRECTORY_HEADER=>{ + println!("Found a ALZ_END_OF_CENTRAL_DIRECTORY_HEADER"); /*This is the end, nothing really to do here.*/ } _ => { From 3646d1fa4e7ecbca4bbbf85c7d3a9a5118105b13 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 13:58:58 -0800 Subject: [PATCH 46/79] blah --- CLAM-2256/run.sh | 4 ++-- CLAM-2256/src/main.rs | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index 84e347a9b0..aed31b9b15 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -7,8 +7,8 @@ #extracts 1 jpg, mine works the same as unalz #cargo run samples/19d17e940e603b7fec36f147b3f8ae482cac429fdcc762f61186d4c00adce8db outDir -cargo run samples/0abac736fb1b1dbd66901ec5258c73c543dd6b01e8d4c06970f94ff697ae1745 outDir +#cargo run samples/0abac736fb1b1dbd66901ec5258c73c543dd6b01e8d4c06970f94ff697ae1745 outDir -#cargo run samples/0e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir +cargo run samples/e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index fd488358b9..ecdcf53abd 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -232,7 +232,7 @@ impl AlzLocalFileHeader { }, _ => return Err(ALZParseError{}), } - assert!(self.is_file(), "NOT A FILE"); +// assert!(self.is_file(), "NOT A FILE"); } else { // println!("DON'T THINK THIS IS EVER POSSIBLE, SEE IF IT COMES OUT IN TESTING!!!!!"); // assert!(false, "EXITING HERE"); @@ -262,6 +262,7 @@ impl AlzLocalFileHeader { } let mut filename: Vec = Vec::new(); +print!("filename = '"); /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ for _i in 0..self._head._file_name_length { @@ -271,16 +272,28 @@ impl AlzLocalFileHeader { return Err(ALZParseError{}); } - filename.push( ret.unwrap()); + let tmp = ret.unwrap(); + filename.push( tmp); + +print!("{:02x} ", tmp); + } +println!("'"); - let res = String::from_utf8(filename); +/* + //let res = String::from_utf8(&filename).into_owned(); if res.is_ok(){ self._file_name = res.unwrap(); } else { + + /*TODO: Other formats*/ assert!(false, "NOT sure if other filename formats are supported here"); } +*/ + self._file_name = String::from_utf8_lossy(&filename).into_owned(); + + //self._file_name = String::from_utf8_unchecked(filename); println!("file name = {}", self._file_name); if self.is_encrypted() { From 808b5dd1c5d93e6d5b5b1556a63b52707bd76173 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 14:00:33 -0800 Subject: [PATCH 47/79] blah --- CLAM-2256/src/main.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index ecdcf53abd..4dd0ab00c8 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -262,7 +262,6 @@ impl AlzLocalFileHeader { } let mut filename: Vec = Vec::new(); -print!("filename = '"); /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ for _i in 0..self._head._file_name_length { @@ -272,13 +271,9 @@ print!("filename = '"); return Err(ALZParseError{}); } - let tmp = ret.unwrap(); - filename.push( tmp); - -print!("{:02x} ", tmp); + filename.push(ret.unwrap()); } -println!("'"); /* //let res = String::from_utf8(&filename).into_owned(); From 51017da472b7064bf61ade22c005c4115f86b9cf Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 14:11:59 -0800 Subject: [PATCH 48/79] blah --- CLAM-2256/src/main.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 4dd0ab00c8..5a5f3ea38d 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -77,19 +77,19 @@ enum AlzFileAttribute { } impl AlzLocalFileHeader { - fn is_encrypted(&mut self) -> bool { + fn is_encrypted(&self) -> bool { return 0 != (self._head._file_descriptor & 0x1 ); } - fn is_data_descriptor(&mut self) -> bool { + fn is_data_descriptor(&self) -> bool { return 0 != (self._head._file_descriptor & 0x8 ); } - fn is_directory(&mut self) -> bool { + fn is_directory(&self) -> bool { return 0 != ((AlzFileAttribute::_AlzFileAttributeDirectory as u8) & self._head._file_attribute); } - fn is_file(&mut self) -> bool { + fn is_file(&self) -> bool { return 0 != ((AlzFileAttribute::_AlzFileAttributeFile as u8) & self._head._file_attribute); } @@ -319,6 +319,7 @@ impl AlzLocalFileHeader { fn extract_file_deflate(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ cursor.set_position(self._start_of_compressed_data); +println!("entering extract for '{}'", self._file_name); let mut contents: Vec = Vec::new(); @@ -383,7 +384,8 @@ impl AlzLocalFileHeader { let mut temp: String = out_dir.to_owned(); temp.push('/'); temp.push_str(&self._file_name.to_owned()); - let out_ret = File::create(temp); + let out_ret = File::create(&temp); +println!("trying to create file '{}'", &temp); if out_ret.is_err() { assert!(false, "Error creating output file"); } @@ -423,6 +425,7 @@ impl AlzLocalFileHeader { return self.extract_file_deflate(cursor, out_dir); } _=>{ + assert!(false, "Unsupported compression Unimplemented"); println!("Unsupported compression"); return Err(ALZExtractError{}); } @@ -462,6 +465,8 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &Str return false; } + println!("in parse_local_file_header, name '{}, is_file = {}'", local_file_header._file_name, local_file_header.is_file()); + /* if local_file_header.is_file() { let res2 = local_file_header.extract_file(cursor, out_dir); if res2.is_err() { @@ -477,6 +482,24 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &Str println!("is directory"); } + */ + if local_file_header.is_directory() { + let res2 = local_file_header.create_directory(out_dir); + if res2.is_err() { + println!("Directory creation ERROR: "); + return false; + } + + println!("is directory"); + } else { + /*the is_file flag doesn't appear to always be set, so we'll just assume it's a file if + * it's not marked as a directory.*/ + let res2 = local_file_header.extract_file(cursor, out_dir); + if res2.is_err() { + println!("Extract ERROR: "); + return false; + } + } return true; } @@ -516,7 +539,7 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { match sig { ALZ_LOCAL_FILE_HEADER=>{ if parse_local_file_header(&mut cursor, out_dir){ - println!("Found a ALZ_LOCAL_FILE_HEADER"); + //println!("Found a ALZ_LOCAL_FILE_HEADER"); continue; } } From 117475a627bbd067785ff11eff0df45201b38536 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 14:15:13 -0800 Subject: [PATCH 49/79] blah --- CLAM-2256/src/main.rs | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 5a5f3ea38d..987ca3ba1b 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -89,10 +89,18 @@ impl AlzLocalFileHeader { return 0 != ((AlzFileAttribute::_AlzFileAttributeDirectory as u8) & self._head._file_attribute); } - fn is_file(&self) -> bool { + fn _is_file(&self) -> bool { return 0 != ((AlzFileAttribute::_AlzFileAttributeFile as u8) & self._head._file_attribute); } + fn _is_readonly(&self) -> bool { + return 0 != ((AlzFileAttribute::_AlzFileAttributeReadonly as u8) & self._head._file_attribute); + } + + fn _is_hidden(&self) -> bool { + return 0 != ((AlzFileAttribute::_AlzFileAttributeHidden as u8) & self._head._file_attribute); + } + pub fn new() -> Self { Self { @@ -465,32 +473,12 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &Str return false; } - println!("in parse_local_file_header, name '{}, is_file = {}'", local_file_header._file_name, local_file_header.is_file()); - /* - if local_file_header.is_file() { - let res2 = local_file_header.extract_file(cursor, out_dir); - if res2.is_err() { - println!("Extract ERROR: "); - return false; - } - } else if local_file_header.is_directory() { - let res2 = local_file_header.create_directory(out_dir); - if res2.is_err() { - println!("Directory creation ERROR: "); - return false; - } - - println!("is directory"); - } - */ if local_file_header.is_directory() { let res2 = local_file_header.create_directory(out_dir); if res2.is_err() { println!("Directory creation ERROR: "); return false; } - - println!("is directory"); } else { /*the is_file flag doesn't appear to always be set, so we'll just assume it's a file if * it's not marked as a directory.*/ From 3fc54fb68f5fed68a90d0ca3e795689fa2c5a686 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 15:44:50 -0800 Subject: [PATCH 50/79] blah --- CLAM-2256/src/main.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 987ca3ba1b..b81a2f942d 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -7,6 +7,7 @@ use byteorder::{LittleEndian, ReadBytesExt}; use std::fs::File; use std::fs::create_dir_all; use std::io::Write; +use std::path::Path; //use deflate::deflate_bytes; //use flate2::Decompress; @@ -283,22 +284,16 @@ impl AlzLocalFileHeader { } -/* - //let res = String::from_utf8(&filename).into_owned(); - if res.is_ok(){ - self._file_name = res.unwrap(); - } else { - - - /*TODO: Other formats*/ - assert!(false, "NOT sure if other filename formats are supported here"); + /* + let ret = String::from_utf8(filename); + if ret.is_err(){ + assert!(false, "not utf8"); } -*/ + self._file_name = ret.unwrap(); + */ + println!("TODO: Figure out how to add other code pages"); self._file_name = String::from_utf8_lossy(&filename).into_owned(); - //self._file_name = String::from_utf8_unchecked(filename); - println!("file name = {}", self._file_name); - if self.is_encrypted() { if ALZ_ENCR_HEADER_LEN as usize > cursor.get_ref().len() { return Err(ALZParseError{}); @@ -389,11 +384,19 @@ println!("entering extract for '{}'", self._file_name); assert!(false, "ERROR in decompress"); } - let mut temp: String = out_dir.to_owned(); + let mut temp: String = String::from(out_dir); temp.push('/'); - temp.push_str(&self._file_name.to_owned()); + temp.push_str(&self._file_name); + temp = temp.replace("\\", "/"); + + let p = Path::new(&temp); + let ret = create_dir_all(p.parent().unwrap()); + if ret.is_err() { + assert!(false, "Cannot create directory, try and just write the file in the base directory"); + } + let out_ret = File::create(&temp); -println!("trying to create file '{}'", &temp); + if out_ret.is_err() { assert!(false, "Error creating output file"); } @@ -447,6 +450,7 @@ println!("trying to create file '{}'", &temp); temp.push('/'); temp.push_str(&self._file_name.to_owned()); let res = create_dir_all(temp); +println!("Creating directory {}/{}", out_dir, self._file_name); if res.is_err() { return Err(ALZExtractError{}); } From 84874c6ec973fe0002eb2557a0511de2255c8cae Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 15:47:46 -0800 Subject: [PATCH 51/79] blah --- CLAM-2256/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index b81a2f942d..fc86007377 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -449,8 +449,8 @@ println!("entering extract for '{}'", self._file_name); let mut temp: String = out_dir.to_owned(); temp.push('/'); temp.push_str(&self._file_name.to_owned()); + temp = temp.replace("\\", "/"); let res = create_dir_all(temp); -println!("Creating directory {}/{}", out_dir, self._file_name); if res.is_err() { return Err(ALZExtractError{}); } From 5a9ae7c0f7b5b4d4b7afa280d74c4f299bf96517 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 29 Jan 2024 15:48:30 -0800 Subject: [PATCH 52/79] blah --- CLAM-2256/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index fc86007377..a77dc1f296 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -451,6 +451,7 @@ println!("entering extract for '{}'", self._file_name); temp.push_str(&self._file_name.to_owned()); temp = temp.replace("\\", "/"); let res = create_dir_all(temp); + println!("TODO: create one function for creating directories"); if res.is_err() { return Err(ALZExtractError{}); } From f731d27295026a9cf7f7b09531841bc42dea0811 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 30 Jan 2024 08:57:26 -0800 Subject: [PATCH 53/79] blah --- CLAM-2256/run.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index aed31b9b15..da528cb210 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -9,6 +9,17 @@ #cargo run samples/0abac736fb1b1dbd66901ec5258c73c543dd6b01e8d4c06970f94ff697ae1745 outDir -cargo run samples/e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir +#cargo run samples/e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir +#7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 +#3fb2d5e820eb9358a110ff6338f9448cfbc924fff72836847498645c7f5da6ac +#ea0744f5eabd23a181799e9e1bb2059306c632fd3c4efc6a3c1f757e0cc49c78 +#58ac36b24ecdbe6726ce2bda0b308b0273f61e8bad858339409046f93d7478df +#c142f76fcfe727bf9ab71b5c2ca53672aba09c0131660d6b43f8a132cde20d48 +#83223cb0000e76589eb0f5bb72180b595576180ed5eb31fed368708bf7f72709 +#5b7fb8715ea1398f870bc4a79739628aff04ddf8e079fee2149b539d8b7894a5 +#2222dff9222e866a8a3ccd99714248ef9af74fd2a74a64a558977dca5432a688 + + +cargo run samples/7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 outDir From 16f9224a8bc65cf7f4794736752e16e2240acf62 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 30 Jan 2024 08:59:30 -0800 Subject: [PATCH 54/79] blah --- CLAM-2256/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index a77dc1f296..0df0071eb0 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -408,7 +408,6 @@ println!("entering extract for '{}'", self._file_name); assert!(false, "Error writing to file"); } - return Ok(()); } From ea183fe134157d716615b800d9e1156ea8cf94c3 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 30 Jan 2024 10:45:46 -0800 Subject: [PATCH 55/79] blah --- CLAM-2256/run.sh | 24 +++++--- CLAM-2256/src/main.rs | 125 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 136 insertions(+), 13 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index da528cb210..fe0ae063b9 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +rm -rf outDir + #cargo run alz_example.alz outDir #cargo run test outDir #cargo run @@ -11,15 +13,19 @@ #cargo run samples/e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir -#7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 -#3fb2d5e820eb9358a110ff6338f9448cfbc924fff72836847498645c7f5da6ac -#ea0744f5eabd23a181799e9e1bb2059306c632fd3c4efc6a3c1f757e0cc49c78 -#58ac36b24ecdbe6726ce2bda0b308b0273f61e8bad858339409046f93d7478df -#c142f76fcfe727bf9ab71b5c2ca53672aba09c0131660d6b43f8a132cde20d48 -#83223cb0000e76589eb0f5bb72180b595576180ed5eb31fed368708bf7f72709 -#5b7fb8715ea1398f870bc4a79739628aff04ddf8e079fee2149b539d8b7894a5 -#2222dff9222e866a8a3ccd99714248ef9af74fd2a74a64a558977dca5432a688 +FILE=7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 +FILE=3fb2d5e820eb9358a110ff6338f9448cfbc924fff72836847498645c7f5da6ac +FILE=ea0744f5eabd23a181799e9e1bb2059306c632fd3c4efc6a3c1f757e0cc49c78 +FILE=58ac36b24ecdbe6726ce2bda0b308b0273f61e8bad858339409046f93d7478df +#FILE=c142f76fcfe727bf9ab71b5c2ca53672aba09c0131660d6b43f8a132cde20d48 +#FILE=83223cb0000e76589eb0f5bb72180b595576180ed5eb31fed368708bf7f72709 +#FILE=5b7fb8715ea1398f870bc4a79739628aff04ddf8e079fee2149b539d8b7894a5 +#FILE=2222dff9222e866a8a3ccd99714248ef9af74fd2a74a64a558977dca5432a688 + + + +cargo run samples/$FILE outDir + -cargo run samples/7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 outDir diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 0df0071eb0..6fbad691bc 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -102,6 +102,40 @@ impl AlzLocalFileHeader { return 0 != ((AlzFileAttribute::_AlzFileAttributeHidden as u8) & self._head._file_attribute); } + fn _dump(&self) { + println!("self._start_of_compressed_data = {}", self._start_of_compressed_data ); + + println!("self._head._file_name_length = {:x}", self._head._file_name_length); + println!("self._head._file_attribute = {:02x}", self._head._file_attribute); + println!("self._head._file_time_date = {:x}", self._head._file_time_date); + println!("self._head._file_descriptor = {:x}", self._head._file_descriptor); + println!("self._head._unknown = {:x}", self._head._unknown); + + println!("self._compression_method = {:x}", self._compression_method); + println!("self._unknown = {:x}", self._unknown); + println!("self._file_crc = {:x}", self._file_crc); + println!("self._compressed_size = {:x}", self._compressed_size); + println!("self._uncompressed_size = {:x}", self._uncompressed_size); + + println!("self._file_name = {}", self._file_name); + + print!("self._enc_chk = "); + for i in 0..ALZ_ENCR_HEADER_LEN { + if 0 != i { + print!(" "); + } + print!("{}", self._enc_chk[i as usize]); + } + println!(""); + + + println!("is_encrypted = {}", self.is_encrypted()); + println!("is_data_descriptor = {}", self.is_data_descriptor()); + + println!("self._start_of_compressed_data = {}", self._start_of_compressed_data); + + } + pub fn new() -> Self { Self { @@ -322,7 +356,6 @@ impl AlzLocalFileHeader { fn extract_file_deflate(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ cursor.set_position(self._start_of_compressed_data); -println!("entering extract for '{}'", self._file_name); let mut contents: Vec = Vec::new(); @@ -358,7 +391,23 @@ println!("entering extract for '{}'", self._file_name); for _i in 0..self._compressed_size { let ret = cursor.read_u8::<>(); if ret.is_err() { - println!("Cannot read full amount of data"); + /* + println!("Cannot read full amount of data (deflate)"); + println!("_i = {}", _i); + println!("self._file_name = {}", self._file_name); + println!("self._compressed_size = {}", self._compressed_size); + println!("self._uncompressed_size = {}", self._uncompressed_size); + println!("cursor.position() = {}", cursor.position()); + + for j in 0..contents.len() { + print!("{:02x} ", contents[j]); + } + println!(""); + */ + + let _ = self.write_file(out_dir, &mut contents); + println!("TODO: put a note in the metadata.json file that this file is incomplete/not decrypted"); + return Err(ALZExtractError{}); } @@ -384,6 +433,10 @@ println!("entering extract for '{}'", self._file_name); assert!(false, "ERROR in decompress"); } + + + + /* let mut temp: String = String::from(out_dir); temp.push('/'); temp.push_str(&self._file_name); @@ -407,8 +460,71 @@ println!("entering extract for '{}'", self._file_name); if write_ret.is_err() { assert!(false, "Error writing to file"); } + return Ok(()); + */ + return self.write_file(out_dir, &mut buffer); + } + + + fn write_file(&mut self, out_dir: &String, buffer: &mut Vec) -> Result<(), ALZExtractError>{ + let mut temp: String = String::from(out_dir); + temp.push('/'); + temp.push_str(&self._file_name); + temp = temp.replace("\\", "/"); + + let p = Path::new(&temp); + let ret = create_dir_all(p.parent().unwrap()); + if ret.is_err() { + assert!(false, "Cannot create directory, try and just write the file in the base directory"); + return Err(ALZExtractError{}); + } + + let out_ret = File::create(&temp); + + if out_ret.is_err() { + assert!(false, "Error creating output file"); + return Err(ALZExtractError{}); + } + + let mut out = out_ret.unwrap(); + + let write_ret = out.write_all(&buffer); + if write_ret.is_err() { + assert!(false, "Error writing to file"); + return Err(ALZExtractError{}); + } + + return Ok(()); + } + + fn extract_file_nocomp(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ + let mut contents: Vec = Vec::new(); + cursor.set_position(self._start_of_compressed_data); + + if self._compressed_size != self._uncompressed_size { + assert!(false, "Consider ignoring this and just writing the minimum number of bytes"); + return Err(ALZExtractError{}); + } + + /*TODO: Figure out the correct way to allocate a vector of dynamic size and call + * cursor.read_exact, instead of having a loop of reads.*/ + for _i in 0..self._compressed_size { + let ret = cursor.read_u8::<>(); + if ret.is_err() { + println!("Cannot read full amount of data (nocomp)"); + println!("_i = {}", _i); + return Err(ALZExtractError{}); + } + + contents.push( ret.unwrap()); + } + + return self.write_file(out_dir, &mut contents); + /* + assert!(false, "finish implementing"); return Ok(()); + */ } fn extract_file(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ @@ -426,7 +542,7 @@ println!("entering extract for '{}'", self._file_name); match self._compression_method { ALZ_COMP_NOCOMP=>{ - assert!(false, "Nocomp Unimplemented"); + return self.extract_file_nocomp(cursor, out_dir); } ALZ_COMP_BZIP2=>{ assert!(false, "Bzip2 Unimplemented"); @@ -488,7 +604,7 @@ fn parse_local_file_header(cursor: &mut std::io::Cursor<&Vec>, out_dir: &Str * it's not marked as a directory.*/ let res2 = local_file_header.extract_file(cursor, out_dir); if res2.is_err() { - println!("Extract ERROR: "); + println!("Extract ERROR: (probably should consider changing this to a warning, and parse what we have"); return false; } } @@ -546,6 +662,7 @@ fn process_file(bytes: &Vec, out_dir: &String) -> bool { /*This is the end, nothing really to do here.*/ } _ => { + println!("sig = {:x}", sig); /*Parse error, maybe try and extract what is there???*/ assert!(false, "NOT A VALID FILE IN MATCH"); } From 12ded7e6c3538a18496572edff7c2b78b94f7232 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 30 Jan 2024 14:40:35 -0800 Subject: [PATCH 56/79] blah --- CLAM-2256/src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 6fbad691bc..0ab2299bd2 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -132,7 +132,7 @@ impl AlzLocalFileHeader { println!("is_encrypted = {}", self.is_encrypted()); println!("is_data_descriptor = {}", self.is_data_descriptor()); - println!("self._start_of_compressed_data = {}", self._start_of_compressed_data); + println!(""); } @@ -296,13 +296,14 @@ impl AlzLocalFileHeader { if self.is_directory() { println!("THIS IS A DIRECTORY"); } else { +// self._dump(); println!("THIS IS NOT A DIRECTORY"); } } - if self._head._file_name_length as usize >= cursor.get_ref().len() { - return Err(ALZParseError{}); - } +// if self._head._file_name_length as usize >= cursor.get_ref().len() { +// return Err(ALZParseError{}); +// } let mut filename: Vec = Vec::new(); /*TODO: Figure out the correct way to allocate a vector of dynamic size and call @@ -351,8 +352,11 @@ impl AlzLocalFileHeader { assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); } + self._dump(); + return Ok(()); } + //31456954 fn extract_file_deflate(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ cursor.set_position(self._start_of_compressed_data); From c6fb11db548dfb7696cb7a0c5aae20298015229d Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 30 Jan 2024 14:45:38 -0800 Subject: [PATCH 57/79] blah --- CLAM-2256/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 0ab2299bd2..b2ced4c50a 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -409,6 +409,7 @@ impl AlzLocalFileHeader { println!(""); */ +println!("TODO: Figure out how to not write the beginning of 'contents' without doing a copy"); let _ = self.write_file(out_dir, &mut contents); println!("TODO: put a note in the metadata.json file that this file is incomplete/not decrypted"); From 107d668dcd157fbbaa8ee3fd131ab681a6950579 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 30 Jan 2024 15:05:14 -0800 Subject: [PATCH 58/79] blah --- CLAM-2256/run.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index fe0ae063b9..9c1182192f 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -13,14 +13,27 @@ rm -rf outDir #cargo run samples/e81e2bb0fa7c00c849465e10329c01f5b40ef66c48a5fa12bee24279411aa297 outDir -FILE=7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 -FILE=3fb2d5e820eb9358a110ff6338f9448cfbc924fff72836847498645c7f5da6ac -FILE=ea0744f5eabd23a181799e9e1bb2059306c632fd3c4efc6a3c1f757e0cc49c78 -FILE=58ac36b24ecdbe6726ce2bda0b308b0273f61e8bad858339409046f93d7478df -#FILE=c142f76fcfe727bf9ab71b5c2ca53672aba09c0131660d6b43f8a132cde20d48 -#FILE=83223cb0000e76589eb0f5bb72180b595576180ed5eb31fed368708bf7f72709 -#FILE=5b7fb8715ea1398f870bc4a79739628aff04ddf8e079fee2149b539d8b7894a5 -#FILE=2222dff9222e866a8a3ccd99714248ef9af74fd2a74a64a558977dca5432a688 + +#FILE=5d21b3f56ed5e349631024ac08006622fa989cfb7bec4ad13c946d331bbffe47 corrupted +#FILE=7b1f0ecdbf1d10e6ee78510901f418c9ec7787b4caf13ac87b5da542d9a26383 corrupted +#FILE=b6461509e990d556579688a758d4018919b0087435f9147a48ef813c865e0b3d corrupted +#FILE=b47d5aa5a024f841b77f20d0d2d8410d1b411aaddd54624e94667e610c1ceabe corrupted +#FILE=e8cedbeec4eb5a9715c514da5c5ceeec375239220750cdff99e4f87e49c7c8ad corrupted +#FILE=7bbf9dafd68b5b5106b5996eaac419228d72b4872707fc2a611a468319bef509 corrupted +#FILE=72a0718760f744a67853f3ee7f5740a34db124e24f787fc61efdeb538fa30376 corrupted +#FILE=ecca4711802697a96528c8bade5158cca011b1759988aad1e44b10fb9889f8aa corrupted +#FILE=8bb3fc1d6a5e703b2a5037ea3a168b45a8b641bcfd337d3bf67152ec353affb6 corrupted +#FILE=e617b015136b23dcd3eb299ca4114b3e19a3b4ee9c4220f5dc7dd529165a45ab corrupted +#FILE=f0fb18a36848e4c12414c101a3505c4f2a74e0b476f770c5a36a47742629c379 corrupted +#FILE=fe6106acdfcc2fd821814801d8f850cfdd08d901216b52463bd7d6e2ca6fc6d8 corrupted +#FILE=f9a5b18c7d15efe4d3db5a0b5259edbaa8917fc36cec99a7571d5192aa6cff1f corrupted +#FILE=58ac36b24ecdbe6726ce2bda0b308b0273f61e8bad858339409046f93d7478df corrupted +#FILE=8cbb8f7ae044db16671003c6c3bbf063b43dc8520f503e66c49360269b4e154b corrupted +#FILE=6c3e1563ce4235720c73de8297cd3aa84959c28b9c8040ac227154920183aeb4 corrupted +#FILE=86b5e5c78a8de95510cd2fbc4dddf66e824a82412bdfb1d67ca504a51d8f1eac corrupted +#FILE=7fc7b135ed44a3f201cfac31945bf7c3007464634b5b8b464c13d87ca6f7bbea corrupted + + From 4f76101397b23914414e4bd9f6ad162784635da9 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Fri, 2 Feb 2024 13:37:20 -0800 Subject: [PATCH 59/79] blah --- CLAM-2256/unit_tests/deflate.alz | Bin 0 -> 274 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 CLAM-2256/unit_tests/deflate.alz diff --git a/CLAM-2256/unit_tests/deflate.alz b/CLAM-2256/unit_tests/deflate.alz new file mode 100644 index 0000000000000000000000000000000000000000..1114dab3d74015c2b9817e000f082f11d7d6ce6f GIT binary patch literal 274 zcmZ?tiDKkpU|?_p(+ZoKogx$%m>AaGY`-AHAi!X#Uy@o}qE}K;60GH^s~6~T`iy6& zK}gVpr%W&{TcKL&7OPJOX)(g8B?wu|4ycxMUGA$uT8y!32}9Ph8>;1ASh@sAiwRaO nfp9Gx3<_(YS}sg7*WhR1Wq|oa8{rX Date: Fri, 2 Feb 2024 14:53:19 -0800 Subject: [PATCH 60/79] blah --- CLAM-2256/unit_tests/create.py | 72 +++++++++++++++++++++++++ CLAM-2256/unit_tests/oldcreate.py | 90 +++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100755 CLAM-2256/unit_tests/create.py create mode 100755 CLAM-2256/unit_tests/oldcreate.py diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py new file mode 100755 index 0000000000..8b17cf93b2 --- /dev/null +++ b/CLAM-2256/unit_tests/create.py @@ -0,0 +1,72 @@ +#!/usr/bin/python3 + +import sys, os +import shutil +import struct +from optparse import OptionParser + +WORKING_DIRECTORY = ".__create_tmp" + +def delWD(): + if os.path.isdir(WORKING_DIRECTORY): + shutil.rmtree(WORKING_DIRECTORY) + +def createWD(): + delWD() + os.makedirs(WORKING_DIRECTORY) + +def createInFiles(): + cwd = os.getcwd() + os.chdir(WORKING_DIRECTORY) + f = open("test.txt", "w") + f.write("test file 0") + f.close() + + for i in range(1, 5): + os.makedirs(str(i)) + f = open(os.path.join(str(i), "test.txt"), "w") + f.write(f'"test file {i}"') + f.close() + os.chdir(cwd) + +def writeFileHeader(f): + #write alz file header + f.write(struct.pack(' Date: Mon, 5 Feb 2024 13:49:18 -0800 Subject: [PATCH 61/79] blah --- CLAM-2256/unit_tests/create.py | 80 ++++++++++++++++++++++++++++--- CLAM-2256/unit_tests/oldcreate.py | 4 +- CLAM-2256/unit_tests/test.c | 6 +++ 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 CLAM-2256/unit_tests/test.c diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index 8b17cf93b2..ba4cfb0b20 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -1,7 +1,8 @@ #!/usr/bin/python3 -import sys, os +import sys, os, bz2 import shutil +import binascii import struct from optparse import OptionParser @@ -31,13 +32,77 @@ def createInFiles(): def writeFileHeader(f): #write alz file header - f.write(struct.pack(' 0xff: + numBytes = 2 + if len(data) > 0xffff: + numBytes = 4 + if len(data) > 0xffffffff: + numBytes = 8 + + outFile.write(struct.pack(" + +int main(){ + printf("Hello World!\n"); + return 0; +} From aff6249226018f2b63d93b38fb31bc51ed881f11 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 5 Feb 2024 13:50:50 -0800 Subject: [PATCH 62/79] blah --- CLAM-2256/unit_tests/create.py | 1 + CLAM-2256/unit_tests/oldcreate.py | 1 + 2 files changed, 2 insertions(+) diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index ba4cfb0b20..3870288421 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -129,6 +129,7 @@ def addFile(fileName, outFile, bzip2): for f in files: fname = os.path.join(parent, f) addFile(fname, outFile, options.bz2) + break #end of file diff --git a/CLAM-2256/unit_tests/oldcreate.py b/CLAM-2256/unit_tests/oldcreate.py index 56a248a399..4dba5abfb1 100755 --- a/CLAM-2256/unit_tests/oldcreate.py +++ b/CLAM-2256/unit_tests/oldcreate.py @@ -4,6 +4,7 @@ import os +os.system("rm -rf test.c.bz2") os.system("bzip2 -k test.c") """ From 031f7937c11520f32ce58c94d23afbc4b54be71d Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 5 Feb 2024 14:19:40 -0800 Subject: [PATCH 63/79] balh --- CLAM-2256/unit_tests/create.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index 3870288421..42bdbd8a46 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -48,7 +48,7 @@ def addFile(fileName, outFile, bzip2): outFile.write(b'\x20') #time date - outFile.write(b'\x00\x00\x00\x00') + outFile.write(struct.pack(' 0xffffffff: numBytes = 8 + + print (numBytes) outFile.write(struct.pack(" Date: Mon, 5 Feb 2024 14:36:48 -0800 Subject: [PATCH 64/79] blah --- CLAM-2256/unit_tests/create.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index 42bdbd8a46..ecbd8065b6 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -38,6 +38,13 @@ def writeFileHeader(f): f.write(struct.pack(' Date: Mon, 5 Feb 2024 14:37:49 -0800 Subject: [PATCH 65/79] blah --- CLAM-2256/unit_tests/create.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index ecbd8065b6..0d8c1b33c5 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -74,8 +74,6 @@ def addFile(fileName, outFile, bzip2): if len(data) > 0xffffffff: numBytes = 8 - print (numBytes) - outFile.write(struct.pack(" Date: Mon, 5 Feb 2024 14:39:20 -0800 Subject: [PATCH 66/79] blah --- CLAM-2256/unit_tests/create.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index 0d8c1b33c5..4a1c1bd36e 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -82,8 +82,7 @@ def addFile(fileName, outFile, bzip2): if bzip2: outFile.write(b'\x01') else: - print ("unsupported") - import pdb ; pdb.set_trace() + outFile.write(b'\x00') #unknown outFile.write(b'\x00') From 9474df67ab021f0b6948499836375acee935e9e6 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 5 Feb 2024 14:41:55 -0800 Subject: [PATCH 67/79] blah --- CLAM-2256/unit_tests/bzip2.alz | Bin 0 -> 435 bytes CLAM-2256/unit_tests/uncompressed.alz | Bin 0 -> 240 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 CLAM-2256/unit_tests/bzip2.alz create mode 100644 CLAM-2256/unit_tests/uncompressed.alz diff --git a/CLAM-2256/unit_tests/bzip2.alz b/CLAM-2256/unit_tests/bzip2.alz new file mode 100644 index 0000000000000000000000000000000000000000..c3449e43fb8eaae0a3be5a93442a934dc4339c58 GIT binary patch literal 435 zcmZ?tiDKkpU|?_p(i{v5Ko)}l10#diD%M{{+$E{SC3+*~^;n8e=iiy;3L%Y9t3vBL(ld%s@9X-iK4)gx3&@k|q7~9Ib5a!yKZEqm z1@ZEl=)+VhA(WaZp{boCufoF1YlKa$5xUyDdiJusyvEqn8l$U?_uQ0svsLHR}KX literal 0 HcmV?d00001 From 65a96cb9f7366203b1c496ed73e207929a7927e3 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 5 Feb 2024 14:59:35 -0800 Subject: [PATCH 68/79] blah --- CLAM-2256/run.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index 9c1182192f..b9969d992e 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -33,11 +33,18 @@ rm -rf outDir #FILE=86b5e5c78a8de95510cd2fbc4dddf66e824a82412bdfb1d67ca504a51d8f1eac corrupted #FILE=7fc7b135ed44a3f201cfac31945bf7c3007464634b5b8b464c13d87ca6f7bbea corrupted +#cargo run samples/$FILE outDir +FILE=unit_tests/deflate.alz +FILE=unit_tests/uncompressed.alz +rm -rf outDir unalz + +cargo run $FILE outDir + +unalz -d unalz $FILE -cargo run samples/$FILE outDir From 518e43637b89c2599244f49540197a35beaeb7cf Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 5 Feb 2024 15:00:01 -0800 Subject: [PATCH 69/79] blah --- CLAM-2256/run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index b9969d992e..4d09c6793f 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -37,12 +37,14 @@ rm -rf outDir FILE=unit_tests/deflate.alz FILE=unit_tests/uncompressed.alz +FILE=unit_tests/bzip2.alz rm -rf outDir unalz +unalz -d unalz $FILE + cargo run $FILE outDir -unalz -d unalz $FILE From 889b2eadcc67538a94f958051537853d4f4192ec Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 5 Feb 2024 15:13:25 -0800 Subject: [PATCH 70/79] blah --- CLAM-2256/Cargo.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ CLAM-2256/Cargo.toml | 1 + CLAM-2256/src/main.rs | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/CLAM-2256/Cargo.lock b/CLAM-2256/Cargo.lock index e63f97f44b..da0a69af58 100644 --- a/CLAM-2256/Cargo.lock +++ b/CLAM-2256/Cargo.lock @@ -20,6 +20,36 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -60,6 +90,12 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -74,7 +110,14 @@ name = "open_alz" version = "0.1.0" dependencies = [ "byteorder", + "bzip2", "cursor", "deflate", "flate2", ] + +[[package]] +name = "pkg-config" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" diff --git a/CLAM-2256/Cargo.toml b/CLAM-2256/Cargo.toml index 55d0147bdf..fef8318199 100644 --- a/CLAM-2256/Cargo.toml +++ b/CLAM-2256/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] byteorder = "1.5.0" +bzip2 = "0.4.4" cursor = "2.3.0" deflate = "1.0.0" flate2 = "1.0.28" diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index b2ced4c50a..7e6d1d1708 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -9,6 +9,9 @@ use std::fs::create_dir_all; use std::io::Write; use std::path::Path; +use bzip2::Compression; +use bzip2::read::{BzEncoder, BzDecoder}; + //use deflate::deflate_bytes; //use flate2::Decompress; //use flate2::FlushDecompress; @@ -532,6 +535,37 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without */ } + fn extract_file_bzip2(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ + + let mut contents: Vec = Vec::new(); + cursor.set_position(self._start_of_compressed_data); + + /*TODO: Figure out the correct way to allocate a vector of dynamic size and call + * cursor.read_exact, instead of having a loop of reads.*/ + for _i in 0..self._compressed_size { + let ret = cursor.read_u8::<>(); + if ret.is_err() { + println!("Cannot read full amount of data (nocomp)"); + println!("_i = {}", _i); + return Err(ALZExtractError{}); + } + + contents.push( ret.unwrap()); + } + + + + + assert!(false, "bzip2 unimplemented"); + + + + //let compressor = BzEncoder::new(contents, Compression::best()); +// let mut decompressor = BzDecoder::new(compressor); + + return self.write_file(out_dir, &mut contents); + } + fn extract_file(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ const ALZ_COMP_NOCOMP: u8 = 0; const ALZ_COMP_BZIP2: u8 = 1; @@ -550,7 +584,7 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without return self.extract_file_nocomp(cursor, out_dir); } ALZ_COMP_BZIP2=>{ - assert!(false, "Bzip2 Unimplemented"); + return self.extract_file_bzip2(cursor, out_dir); } ALZ_COMP_DEFLATE=>{ return self.extract_file_deflate(cursor, out_dir); From 496111b58e6c5e92041a88463c01d93bf9134b08 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 09:20:25 -0800 Subject: [PATCH 71/79] blah --- CLAM-2256/src/main.rs | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 7e6d1d1708..30ff12070f 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -11,6 +11,7 @@ use std::path::Path; use bzip2::Compression; use bzip2::read::{BzEncoder, BzDecoder}; +//use bzip2::read::{BzDecoder}; //use deflate::deflate_bytes; //use flate2::Decompress; @@ -540,6 +541,7 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without let mut contents: Vec = Vec::new(); cursor.set_position(self._start_of_compressed_data); + /* /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ for _i in 0..self._compressed_size { @@ -553,17 +555,55 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without contents.push( ret.unwrap()); } + */ + + let mut out: Vec = Vec::new(); + for _i in 0..self._uncompressed_size { + out.push(0); + } + + /* - assert!(false, "bzip2 unimplemented"); +// Round trip some bytes from a byte source, into a compressor, into a +// decompressor, and finally into a vector. +let data = "Hello, World!".as_bytes(); +let compressor = BzEncoder::new(data, Compression::best()); +let mut decompressor = BzDecoder::new(compressor); +let mut contents = String::new(); +decompressor.read_to_string(&mut contents).unwrap(); +assert_eq!(contents, "Hello, World!"); +println!("MADE IT!!!"); + + for _i in 0..self._compressed_size { + print!("{:02x} ", contents[_i as usize]); + } + println!(""); + +*/ + + + + let mut decompressor = BzDecoder::new(cursor); + // let mut outString = String::new(); + //let res = decompressor.read_to_string(&mut outString); + + let res = decompressor.read_exact(&mut out); + if res.is_err(){ + assert!(false, "Error decompressing bz2 file"); + } + + +// assert!(false, "Made it!!!"); + //let compressor = BzEncoder::new(contents, Compression::best()); // let mut decompressor = BzDecoder::new(compressor); - return self.write_file(out_dir, &mut contents); + return self.write_file(out_dir, &mut out); } fn extract_file(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ @@ -596,7 +636,7 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without } } - return Ok(()); + //return Ok(()); } fn create_directory(&mut self, out_dir: &String) -> Result<(), ALZExtractError>{ From acb775dea1a4d45b48fb98a2d003b4d796baafa0 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 10:11:34 -0800 Subject: [PATCH 72/79] blah --- CLAM-2256/src/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 30ff12070f..45a769a859 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -9,9 +9,9 @@ use std::fs::create_dir_all; use std::io::Write; use std::path::Path; -use bzip2::Compression; -use bzip2::read::{BzEncoder, BzDecoder}; -//use bzip2::read::{BzDecoder}; +//use bzip2::Compression; +//use bzip2::read::{BzEncoder, BzDecoder}; +use bzip2::read::{BzDecoder}; //use deflate::deflate_bytes; //use flate2::Decompress; @@ -541,7 +541,6 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without let mut contents: Vec = Vec::new(); cursor.set_position(self._start_of_compressed_data); - /* /*TODO: Figure out the correct way to allocate a vector of dynamic size and call * cursor.read_exact, instead of having a loop of reads.*/ for _i in 0..self._compressed_size { @@ -555,8 +554,6 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without contents.push( ret.unwrap()); } - */ - let mut out: Vec = Vec::new(); for _i in 0..self._uncompressed_size { out.push(0); @@ -588,7 +585,11 @@ println!("MADE IT!!!"); - let mut decompressor = BzDecoder::new(cursor); + //let mut decompressor = BzDecoder::new(cursor); + let mut decompressor = BzDecoder::new(&*contents); + + + // let mut outString = String::new(); //let res = decompressor.read_to_string(&mut outString); From d592cdfd1c4ae09b3fd6715f6f588ac91c67d063 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 10:15:41 -0800 Subject: [PATCH 73/79] blah --- CLAM-2256/src/main.rs | 42 +++--------------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 45a769a859..c2e22b0919 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -554,56 +554,20 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without contents.push( ret.unwrap()); } + /*TODO: Figure out why I have to do this, and can't just call + * Vec::with_capacity(self._uncompressed_size) + */ let mut out: Vec = Vec::new(); for _i in 0..self._uncompressed_size { out.push(0); } - /* - - - -// Round trip some bytes from a byte source, into a compressor, into a -// decompressor, and finally into a vector. -let data = "Hello, World!".as_bytes(); -let compressor = BzEncoder::new(data, Compression::best()); -let mut decompressor = BzDecoder::new(compressor); - -let mut contents = String::new(); -decompressor.read_to_string(&mut contents).unwrap(); -assert_eq!(contents, "Hello, World!"); - - -println!("MADE IT!!!"); - - for _i in 0..self._compressed_size { - print!("{:02x} ", contents[_i as usize]); - } - println!(""); - -*/ - - - - //let mut decompressor = BzDecoder::new(cursor); let mut decompressor = BzDecoder::new(&*contents); - - - - // let mut outString = String::new(); - //let res = decompressor.read_to_string(&mut outString); - let res = decompressor.read_exact(&mut out); if res.is_err(){ assert!(false, "Error decompressing bz2 file"); } - -// assert!(false, "Made it!!!"); - - //let compressor = BzEncoder::new(contents, Compression::best()); -// let mut decompressor = BzDecoder::new(compressor); - return self.write_file(out_dir, &mut out); } From 6a759a1fea31ddc5f7e66b73abb5ea8f651c763c Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 10:15:58 -0800 Subject: [PATCH 74/79] blah --- CLAM-2256/src/main.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index c2e22b0919..956ed0f67f 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -529,11 +529,6 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without } return self.write_file(out_dir, &mut contents); - /* - assert!(false, "finish implementing"); - - return Ok(()); - */ } fn extract_file_bzip2(&mut self, cursor: &mut std::io::Cursor<&Vec>, out_dir: &String) -> Result<(), ALZExtractError>{ From 98aae365e0b16b6eefb56dda0843696279b007a4 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 10:17:16 -0800 Subject: [PATCH 75/79] blah --- CLAM-2256/src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 956ed0f67f..e3d7dc583e 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -521,7 +521,6 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without let ret = cursor.read_u8::<>(); if ret.is_err() { println!("Cannot read full amount of data (nocomp)"); - println!("_i = {}", _i); return Err(ALZExtractError{}); } @@ -541,8 +540,7 @@ println!("TODO: Figure out how to not write the beginning of 'contents' without for _i in 0..self._compressed_size { let ret = cursor.read_u8::<>(); if ret.is_err() { - println!("Cannot read full amount of data (nocomp)"); - println!("_i = {}", _i); + println!("Cannot read full amount of data (bzip2)"); return Err(ALZExtractError{}); } From 92f89d3e1e19704cb851ff5d8766b313c6c5d0e0 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 11:45:20 -0800 Subject: [PATCH 76/79] blah --- CLAM-2256/run.sh | 1 + CLAM-2256/unit_tests/create.py | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index 4d09c6793f..71ee1a2bc4 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -38,6 +38,7 @@ rm -rf outDir FILE=unit_tests/deflate.alz FILE=unit_tests/uncompressed.alz FILE=unit_tests/bzip2.alz +FILE=unit_tests/bzip2.bin.alz rm -rf outDir unalz diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index 4a1c1bd36e..7af8087272 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -37,13 +37,13 @@ def writeFileHeader(f): #write 'ignored' bytes f.write(struct.pack(' Date: Tue, 6 Feb 2024 12:07:11 -0800 Subject: [PATCH 77/79] blah --- CLAM-2256/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index e3d7dc583e..74750338f4 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -413,7 +413,7 @@ impl AlzLocalFileHeader { println!(""); */ -println!("TODO: Figure out how to not write the beginning of 'contents' without doing a copy"); +//println!("TODO: Figure out how to not write the beginning of 'contents' without doing a copy"); let _ = self.write_file(out_dir, &mut contents); println!("TODO: put a note in the metadata.json file that this file is incomplete/not decrypted"); From ffe0f4625bc8ca3bebe0e731e266598b494b9f73 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 12:07:37 -0800 Subject: [PATCH 78/79] blah --- CLAM-2256/src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/CLAM-2256/src/main.rs b/CLAM-2256/src/main.rs index 74750338f4..c87aa6447d 100644 --- a/CLAM-2256/src/main.rs +++ b/CLAM-2256/src/main.rs @@ -356,8 +356,6 @@ impl AlzLocalFileHeader { assert!(false, "IS DATA DESCRIPTOR UNIMPLEMENTED"); } - self._dump(); - return Ok(()); } //31456954 From a62e3f11239d3c56fb68510c457ec51a1c425e52 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Tue, 6 Feb 2024 12:09:07 -0800 Subject: [PATCH 79/79] blah --- CLAM-2256/run.sh | 1 + CLAM-2256/unit_tests/create.py | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CLAM-2256/run.sh b/CLAM-2256/run.sh index 71ee1a2bc4..8398772c11 100755 --- a/CLAM-2256/run.sh +++ b/CLAM-2256/run.sh @@ -39,6 +39,7 @@ FILE=unit_tests/deflate.alz FILE=unit_tests/uncompressed.alz FILE=unit_tests/bzip2.alz FILE=unit_tests/bzip2.bin.alz +FILE=unit_tests/uncompressed.bin.alz rm -rf outDir unalz diff --git a/CLAM-2256/unit_tests/create.py b/CLAM-2256/unit_tests/create.py index 7af8087272..b08b45d941 100755 --- a/CLAM-2256/unit_tests/create.py +++ b/CLAM-2256/unit_tests/create.py @@ -137,7 +137,6 @@ def addFile(fileName, outFile, bzip2, inDir): parser.print_help() sys.exit(1) -print (f"before {inDir}") while 1 < len(inDir): if '/' == inDir[len(inDir)-1] or '\\' == inDir[len(inDir)-1]: @@ -145,8 +144,6 @@ def addFile(fileName, outFile, bzip2, inDir): else: break -print (f"after {inDir}") - outFile = open(options.outFile, "wb") writeFileHeader(outFile)