From 3e3f7bc51ed7d168c5ac9b59366e1205010f0163 Mon Sep 17 00:00:00 2001 From: Kazuminn Date: Sun, 4 Oct 2020 17:07:09 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=A7=E6=8C=87=E6=91=98=E3=81=95=E3=82=8C=E3=81=9F=E3=81=A8?= =?UTF-8?q?=E3=81=93=E3=82=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/detections/utils.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/detections/utils.rs b/src/detections/utils.rs index 04b53b76..db42652a 100644 --- a/src/detections/utils.rs +++ b/src/detections/utils.rs @@ -16,16 +16,11 @@ pub fn check_command( servicecmd: usize, servicename: &str, creator: &str, + mut rdr: csv::Reader<&[u8]>, ) { let mut text = "".to_string(); let mut base64 = "".to_string(); - let mut f = File::open("whitelist.txt").expect("file not found"); - let mut contents = String::new(); - f.read_to_string(&mut contents); - - let mut rdr = csv::Reader::from_reader(contents.as_bytes()); - for entry in rdr.records() { if let Ok(_data) = entry { if let Ok(_re) = Regex::new(&_data[0]) { @@ -199,6 +194,8 @@ fn check_creator(command: &str, creator: &str) -> std::string::String { #[cfg(test)] mod tests { use crate::detections::utils; + use std::fs::File; + use std::io::Read; #[test] fn test_check_regex() { let regextext = utils::check_regex("\\cvtres.exe", 0); @@ -221,7 +218,14 @@ mod tests { #[test] fn test_check_command() { - utils::check_command(1, "dir", 100, 100, "dir", "dir"); + let mut f = File::open("whitelist.txt").expect("file not found"); + let mut contents = String::new(); + f.read_to_string(&mut contents); + + let rdr = csv::Reader::from_reader(contents.as_bytes()); + utils::check_command(1, "dir", 100, 100, "dir", "dir", rdr); + + let rdr = csv::Reader::from_reader(contents.as_bytes()); utils::check_command( 1, "\"C:\\Program Files\\Google\\Update\\GoogleUpdate.exe\"", @@ -229,6 +233,7 @@ mod tests { 100, "dir", "dir", + rdr, ); } }