From 980e47a85b302d05bb56dad8cbc9a661e8c2eb1d Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Mon, 26 Feb 2024 15:05:47 -0800 Subject: [PATCH] blah --- libclamav/filetypes_int.h | 2 +- libclamav_rust/src/scanners.rs | 91 ++++++++++++++-------------------- 2 files changed, 37 insertions(+), 56 deletions(-) diff --git a/libclamav/filetypes_int.h b/libclamav/filetypes_int.h index 80ab8de5b4..e1572a4c4c 100644 --- a/libclamav/filetypes_int.h +++ b/libclamav/filetypes_int.h @@ -298,6 +298,6 @@ static const char *ftypes_int[] = { "0:0:00010d0a:PyPy 3.8 byte-compiled (.pyc):CL_TYPE_ANY:CL_TYPE_PYTHON_COMPILED:200", "0:0:50010d0a:PyPy 3.9 byte-compiled (.pyc):CL_TYPE_ANY:CL_TYPE_PYTHON_COMPILED:200", "1:0:??0d0d0a:Python 3.7 or newer byte-compiled (.pyc):CL_TYPE_ANY:CL_TYPE_PYTHON_COMPILED:200", - "0:0:414c5a01:ALZ:CL_TYPE_ANY:CL_TYPE_ALZ:200", //TODO: Change the FLEVEL to 210. Just leaving it as 200 for testing in this branch. + "0:0:414c5a01:ALZ:CL_TYPE_ANY:CL_TYPE_ALZ:210", NULL}; #endif diff --git a/libclamav_rust/src/scanners.rs b/libclamav_rust/src/scanners.rs index ce37b428d4..9649211cf9 100644 --- a/libclamav_rust/src/scanners.rs +++ b/libclamav_rust/src/scanners.rs @@ -43,36 +43,30 @@ use crate::{ sys::{cl_error_t, cl_error_t_CL_ERROR, cl_error_t_CL_SUCCESS, cli_ctx, cli_magic_scan_buff}, }; -//use crate::{ -// ctx, -// alz::Alz, -// sys::{cl_error_t, cl_error_t_CL_ERROR, cl_error_t_CL_SUCCESS, cli_ctx, cli_magic_scan_buff}, -//}; - -/* DELETEME*/ -use std::fs::create_dir_all; -use std::fs::File; -use std::io::Write; -const DUMP_DIRECTORY: &str = "andy_dump_files"; -fn dump_file(name: &str, buf: &[u8], ctx: *mut cli_ctx){ - - let fmap = unsafe { ctx::current_fmap(ctx).expect("")}; - - //let mut temp: String = String::from(out_dir); - let mut temp: String = DUMP_DIRECTORY.to_string(); - temp.push('/'); - temp.push_str( fmap.name()); - temp.push('/'); - temp.push_str(name); - temp = temp.replace('\\', "/"); - - let p = Path::new(&temp); - create_dir_all(p.parent().unwrap()).expect(""); - - let mut out = File::create(&temp).expect("Error creating output file"); - out.write_all(buf).expect("Error writing to file"); -} -/* END DELETEME*/ +// /* DELETEME*/ +//use std::fs::create_dir_all; +//use std::fs::File; +//use std::io::Write; +//const DUMP_DIRECTORY: &str = "dump_files"; +//fn dump_file(name: &str, buf: &[u8], ctx: *mut cli_ctx){ +// +// let fmap = unsafe { ctx::current_fmap(ctx).expect("")}; +// +// //let mut temp: String = String::from(out_dir); +// let mut temp: String = DUMP_DIRECTORY.to_string(); +// temp.push('/'); +// temp.push_str( fmap.name()); +// temp.push('/'); +// temp.push_str(name); +// temp = temp.replace('\\', "/"); +// +// let p = Path::new(&temp); +// create_dir_all(p.parent().unwrap()).expect(""); +// +// let mut out = File::create(&temp).expect("Error creating output file"); +// out.write_all(buf).expect("Error writing to file"); +//} +// /* END DELETEME*/ /// Rust wrapper of libclamav's cli_magic_scan_buff() function. /// Use magic sigs to identify the file type and then scan it. @@ -182,7 +176,6 @@ pub unsafe extern "C" fn extract_alz(ctx: *mut cli_ctx) -> cl_error_t { return cl_error_t_CL_ERROR; } }; - //println!("name = {}", fmap.name()); let file_bytes = match fmap.need_off(0, fmap.len()) { Ok(bytes) => bytes, @@ -195,7 +188,6 @@ pub unsafe extern "C" fn extract_alz(ctx: *mut cli_ctx) -> cl_error_t { } }; -// Alz::parse_alz_file(file_bytes); let alz = match Alz::from_bytes(file_bytes) { Ok(x) => x, Err(err) => { @@ -204,38 +196,27 @@ pub unsafe extern "C" fn extract_alz(ctx: *mut cli_ctx) -> cl_error_t { } }; - /* DELETE ME!!! */ - for i in 0..alz.embedded_files.len(){ - -// let mut name: String; - let name = match alz.embedded_files[i].name.clone() { - Some(name) => name, - None => String::from(""), - }; - - let buf: &[u8] = &alz.embedded_files[i].data; - dump_file(&name, buf, ctx); - } - /* END DELETE ME!!! */ +// /* DELETE ME!!! */ +// for i in 0..alz.embedded_files.len(){ +// let name = match alz.embedded_files[i].name.clone() { +// Some(name) => name, +// None => String::from(""), +// }; +// +// let buf: &[u8] = &alz.embedded_files[i].data; +// dump_file(&name, buf, ctx); +// } +// /* END DELETE ME!!! */ - //println!("extract_alz (IN RUST), scanning files"); -// let mut scan_result = cl_error_t_CL_SUCCESS; for i in 0..alz.embedded_files.len(){ let ret = magic_scan(ctx, &alz.embedded_files[i].data, alz.embedded_files[i].name.clone()); if ret != cl_error_t_CL_SUCCESS { - println!("RETURNING from extract_alz because magic_scan returned '{}'", ret); return ret; } -// println!("i = {}", i); } -cl_error_t_CL_SUCCESS -// for i in 0..12 { -// print!("{:02x} ", file_bytes[i]); -// } -// println!(""); - //return cl_error_t_CL_SUCCESS; + cl_error_t_CL_SUCCESS }