fixed custom config directory doesn't load #681
- channel_abbrevations.txt - target_events_IDs.txt - default_details.txt - level_tuning.txt - statistics_event_info.txt
This commit is contained in:
+24
-14
@@ -52,7 +52,7 @@ impl Default for ConfigReader<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[derive(Parser, Clone)]
|
||||
#[clap(
|
||||
name = "Hayabusa",
|
||||
usage = "hayabusa.exe <INPUT> [OTHER-ACTIONS] [OPTIONS]",
|
||||
@@ -242,23 +242,33 @@ impl ConfigReader<'_> {
|
||||
.help_template("\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}");
|
||||
ConfigReader {
|
||||
app: build_cmd,
|
||||
args: parse,
|
||||
args: parse.clone(),
|
||||
headless_help: String::default(),
|
||||
event_timeline_config: load_eventcode_info(
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/statistics_event_info.txt",
|
||||
)
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
utils::check_setting_path(&parse.config, "statistics_event_info.txt", false)
|
||||
.unwrap_or_else(|| {
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/statistics_event_info.txt",
|
||||
true,
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
),
|
||||
target_eventids: load_target_ids(
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/target_event_IDs.txt",
|
||||
)
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
utils::check_setting_path(&parse.config, "target_event_IDs.txt", false)
|
||||
.unwrap_or_else(|| {
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/target_event_IDs.txt",
|
||||
true,
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
+18
-16
@@ -49,30 +49,32 @@ lazy_static! {
|
||||
pub static ref STATISTICS_FLAG: bool = configs::CONFIG.read().unwrap().args.statistics;
|
||||
pub static ref LOGONSUMMARY_FLAG: bool = configs::CONFIG.read().unwrap().args.logon_summary;
|
||||
pub static ref TAGS_CONFIG: HashMap<String, String> = create_output_filter_config(
|
||||
utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "config/mitre_tactics.txt")
|
||||
.to_str()
|
||||
utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "config/mitre_tactics.txt", true)
|
||||
.unwrap().to_str()
|
||||
.unwrap(),
|
||||
);
|
||||
pub static ref CH_CONFIG: HashMap<String, String> = create_output_filter_config(
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/channel_abbreviations.txt"
|
||||
)
|
||||
utils::check_setting_path(&configs::CONFIG.read().unwrap().args.config, "channel_abbreviations.txt", false).unwrap_or_else(|| {
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/channel_abbreviations.txt", true
|
||||
).unwrap()
|
||||
})
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
);
|
||||
pub static ref PIVOT_KEYWORD_LIST_FLAG: bool =
|
||||
configs::CONFIG.read().unwrap().args.pivot_keywords_list;
|
||||
pub static ref DEFAULT_DETAILS: HashMap<String, String> = get_default_details(&format!(
|
||||
"{}/default_details.txt",
|
||||
configs::CONFIG
|
||||
.read()
|
||||
.unwrap()
|
||||
.args
|
||||
.config
|
||||
.as_path()
|
||||
.display()
|
||||
));
|
||||
pub static ref DEFAULT_DETAILS: HashMap<String, String> = get_default_details(
|
||||
utils::check_setting_path(&configs::CONFIG.read().unwrap().args.config, "default_details.txt", false).unwrap_or_else(|| {
|
||||
utils::check_setting_path(
|
||||
&CURRENT_EXE_PATH.to_path_buf(),
|
||||
"rules/config/default_details.txt", true
|
||||
).unwrap()
|
||||
})
|
||||
.to_str()
|
||||
.unwrap()
|
||||
);
|
||||
pub static ref LEVEL_ABBR: LinkedHashMap<String, String> = LinkedHashMap::from_iter([
|
||||
("critical".to_string(), "crit".to_string()),
|
||||
("high".to_string(), "high".to_string()),
|
||||
|
||||
+19
-8
@@ -73,7 +73,8 @@ pub fn value_to_string(value: &Value) -> Option<String> {
|
||||
|
||||
pub fn read_txt(filename: &str) -> Result<Vec<String>, String> {
|
||||
let filepath = if filename.starts_with("./") {
|
||||
check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), filename)
|
||||
check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), filename, true)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
@@ -380,11 +381,13 @@ pub fn make_ascii_titlecase(s: &mut str) -> String {
|
||||
}
|
||||
|
||||
/// base_path/path が存在するかを確認し、存在しなければカレントディレクトリを参照するpathを返す関数
|
||||
pub fn check_setting_path(base_path: &Path, path: &str) -> PathBuf {
|
||||
pub fn check_setting_path(base_path: &Path, path: &str, ignore_err: bool) -> Option<PathBuf> {
|
||||
if base_path.join(path).exists() {
|
||||
base_path.join(path)
|
||||
Some(base_path.join(path))
|
||||
} else if ignore_err {
|
||||
Some(Path::new(path).to_path_buf())
|
||||
} else {
|
||||
Path::new(path).to_path_buf()
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,23 +616,31 @@ mod tests {
|
||||
let exist_path = Path::new("./test_files").to_path_buf();
|
||||
let not_exist_path = Path::new("not_exist_path").to_path_buf();
|
||||
assert_eq!(
|
||||
check_setting_path(¬_exist_path, "rules")
|
||||
check_setting_path(¬_exist_path, "rules", true)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"rules"
|
||||
);
|
||||
assert_eq!(
|
||||
check_setting_path(¬_exist_path, "fake")
|
||||
check_setting_path(¬_exist_path, "fake", true)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"fake"
|
||||
);
|
||||
assert_eq!(
|
||||
check_setting_path(&exist_path, "rules").to_str().unwrap(),
|
||||
check_setting_path(&exist_path, "rules", true)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
exist_path.join("rules").to_str().unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
check_setting_path(&exist_path, "fake").to_str().unwrap(),
|
||||
check_setting_path(&exist_path, "fake", true)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"fake"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user