Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Feb 26, 2024
1 parent ac50c44 commit 980e47a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 56 deletions.
2 changes: 1 addition & 1 deletion libclamav/filetypes_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
91 changes: 36 additions & 55 deletions libclamav_rust/src/scanners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand All @@ -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
}


Expand Down

0 comments on commit 980e47a

Please sign in to comment.