Merge branch 'main' into 603-bug-non-utf-8-byte-sequences-error-with-color-output
This commit is contained in:
@@ -3,6 +3,8 @@ extern crate csv;
|
||||
extern crate regex;
|
||||
|
||||
use crate::detections::configs;
|
||||
use crate::detections::configs::CURRENT_EXE_PATH;
|
||||
|
||||
use termcolor::Color;
|
||||
|
||||
use tokio::runtime::Builder;
|
||||
@@ -66,7 +68,16 @@ pub fn value_to_string(value: &Value) -> Option<String> {
|
||||
}
|
||||
|
||||
pub fn read_txt(filename: &str) -> Result<Vec<String>, String> {
|
||||
let f = File::open(filename);
|
||||
let filepath = if filename.starts_with("./") {
|
||||
CURRENT_EXE_PATH
|
||||
.join(filename)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
} else {
|
||||
filename.to_string()
|
||||
};
|
||||
let f = File::open(filepath);
|
||||
if f.is_err() {
|
||||
let errmsg = format!("Cannot open file. [file:{}]", filename);
|
||||
return Result::Err(errmsg);
|
||||
@@ -437,7 +448,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_check_regex() {
|
||||
let regexes: Vec<Regex> =
|
||||
utils::read_txt("./rules/config/regex/detectlist_suspicous_services.txt")
|
||||
utils::read_txt("./../../../rules/config/regex/detectlist_suspicous_services.txt")
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|regex_str| Regex::new(®ex_str).unwrap())
|
||||
@@ -453,7 +464,7 @@ mod tests {
|
||||
fn test_check_allowlist() {
|
||||
let commandline = "\"C:\\Program Files\\Google\\Update\\GoogleUpdate.exe\"";
|
||||
let allowlist: Vec<Regex> =
|
||||
utils::read_txt("./rules/config/regex/allowlist_legitimate_services.txt")
|
||||
utils::read_txt("./../../../rules/config/regex/allowlist_legitimate_services.txt")
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|allow_str| Regex::new(&allow_str).unwrap())
|
||||
|
||||
Reference in New Issue
Block a user