fixed display relative path processing #623

This commit is contained in:
DastInDark
2022-07-18 22:29:06 +09:00
parent b97de6b588
commit 45f49682d5
2 changed files with 11 additions and 16 deletions

View File

@@ -254,16 +254,11 @@ impl Detection {
} else { } else {
None None
}; };
let abs_rule_path = &PathBuf::from(&rule.rulepath)
.canonicalize()
.unwrap()
.display()
.to_string()[4..];
let detect_info = DetectInfo { let detect_info = DetectInfo {
filepath: record_info.evtx_filepath.to_string(), filepath: record_info.evtx_filepath.to_string(),
rulepath: get_output_str_path( rulepath: get_output_str_path(
&configs::CONFIG.read().unwrap().args.rules, &configs::CONFIG.read().unwrap().args.rules,
Path::new(abs_rule_path), Path::new(&rule.rulepath),
), ),
level: rule.yaml["level"].as_str().unwrap_or("-").to_string(), level: rule.yaml["level"].as_str().unwrap_or("-").to_string(),
computername: record_info.record["Event"]["System"]["Computer"] computername: record_info.record["Event"]["System"]["Computer"]

View File

@@ -31,7 +31,8 @@ use termcolor::{BufferWriter, ColorSpec, WriteColor};
use super::detection::EvtxRecordInfo; use super::detection::EvtxRecordInfo;
lazy_static! { lazy_static! {
pub static ref OUTPUT_OMIT_REGEX: Regex = Regex::new(r"\.\./|\./|\.\\|\.\.\\").unwrap(); pub static ref OUTPUT_OMIT_REGEX: Regex =
Regex::new(r"\.\./|\./|\.\\|\.\.\\|\\\\\?\\").unwrap();
} }
pub fn concat_selection_key(key_list: &[String]) -> String { pub fn concat_selection_key(key_list: &[String]) -> String {
@@ -396,20 +397,19 @@ pub fn check_setting_path(base_path: &Path, path: &str) -> PathBuf {
/// 与えられたoption_pathが相対パスであるかを確認し、絶対パスであればそのまま絶対パスのまま文字列として返却を行い、 /// 与えられたoption_pathが相対パスであるかを確認し、絶対パスであればそのまま絶対パスのまま文字列として返却を行い、
/// 相対パスであれば、カレントディレクトリとの相対パスの文字列から不要な(./、../)を除外した文字列を返却する関数 /// 相対パスであれば、カレントディレクトリとの相対パスの文字列から不要な(./、../)を除外した文字列を返却する関数
pub fn get_output_str_path(option_path: &Path, target_path: &Path) -> String { pub fn get_output_str_path(option_path: &Path, target_path: &Path) -> String {
if option_path.is_absolute() && !OUTPUT_OMIT_REGEX.is_match(option_path.to_str().unwrap()) { let ret_path = if option_path.is_absolute()
target_path.to_str().unwrap().to_string() || !OUTPUT_OMIT_REGEX.is_match(target_path.to_str().unwrap())
{
target_path.canonicalize().unwrap().display().to_string()
} else { } else {
let diff_path_result = diff_paths(target_path, &env::current_dir().unwrap()); let diff_path_result = diff_paths(target_path, &env::current_dir().unwrap());
if let Some(diff_path) = diff_path_result { if let Some(diff_path) = diff_path_result {
OUTPUT_OMIT_REGEX diff_path.display().to_string()
.replace_all(diff_path.to_str().unwrap(), "")
.to_string()
} else { } else {
OUTPUT_OMIT_REGEX target_path.display().to_string()
.replace_all(target_path.to_str().unwrap(), "")
.to_string()
} }
} };
OUTPUT_OMIT_REGEX.replace_all(&ret_path, "").to_string()
} }
#[cfg(test)] #[cfg(test)]