From a3599ca5d03e950dd30fb12b1cab1413c62d00d8 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:39:46 +0900 Subject: [PATCH 1/7] adjust rules option when use update option #615 --- src/main.rs | 2 +- src/options/update_rules.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3cbc9432..5ae85436 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ impl App { } if configs::CONFIG.read().unwrap().args.update_rules { - match UpdateRules::update_rules() { + match UpdateRules::update_rules(configs::CONFIG.read().unwrap().args.rules.to_str().unwrap()) { Ok(output) => { if output != "You currently have the latest rules." { write_color_buffer( diff --git a/src/options/update_rules.rs b/src/options/update_rules.rs index 764a2a8a..e4244fe1 100644 --- a/src/options/update_rules.rs +++ b/src/options/update_rules.rs @@ -20,12 +20,12 @@ pub struct UpdateRules {} impl UpdateRules { /// update rules(hayabusa-rules subrepository) - pub fn update_rules() -> Result { + pub fn update_rules(rule_path: &str) -> Result { let mut result; let mut prev_modified_time: SystemTime = SystemTime::UNIX_EPOCH; let mut prev_modified_rules: HashSet = HashSet::default(); let hayabusa_repo = Repository::open(Path::new(".")); - let hayabusa_rule_repo = Repository::open(Path::new("rules")); + let hayabusa_rule_repo = Repository::open(Path::new(rule_path)); if hayabusa_repo.is_err() && hayabusa_rule_repo.is_err() { write_color_buffer( &BufferWriter::stdout(ColorChoice::Always), @@ -40,15 +40,15 @@ impl UpdateRules { // case of exist hayabusa-rules repository UpdateRules::_repo_main_reset_hard(hayabusa_rule_repo.as_ref().unwrap())?; // case of failed fetching origin/main, git clone is not executed so network error has occurred possibly. - prev_modified_rules = UpdateRules::get_updated_rules("rules", &prev_modified_time); - prev_modified_time = fs::metadata("rules").unwrap().modified().unwrap(); + prev_modified_rules = UpdateRules::get_updated_rules(rule_path, &prev_modified_time); + prev_modified_time = fs::metadata(rule_path).unwrap().modified().unwrap(); result = UpdateRules::pull_repository(&hayabusa_rule_repo.unwrap()); } else { // case of no exist hayabusa-rules repository in rules. // execute update because submodule information exists if hayabusa repository exists submodule information. - prev_modified_time = fs::metadata("rules").unwrap().modified().unwrap(); - let rules_path = Path::new("rules"); + prev_modified_time = fs::metadata(rule_path).unwrap().modified().unwrap(); + let rules_path = Path::new(rule_path); if !rules_path.exists() { create_dir(rules_path).ok(); } @@ -73,7 +73,7 @@ impl UpdateRules { } if result.is_ok() { let updated_modified_rules = - UpdateRules::get_updated_rules("rules", &prev_modified_time); + UpdateRules::get_updated_rules(rule_path, &prev_modified_time); result = UpdateRules::print_diff_modified_rule_dates( prev_modified_rules, updated_modified_rules, From 1b66eb169dd605910df7c818fd5d7be831215514 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:41:59 +0900 Subject: [PATCH 2/7] cargo fmt --- src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5ae85436..ffe09ab7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,9 @@ impl App { } if configs::CONFIG.read().unwrap().args.update_rules { - match UpdateRules::update_rules(configs::CONFIG.read().unwrap().args.rules.to_str().unwrap()) { + match UpdateRules::update_rules( + configs::CONFIG.read().unwrap().args.rules.to_str().unwrap(), + ) { Ok(output) => { if output != "You currently have the latest rules." { write_color_buffer( From b0b1398927d588f7b8300b8b91894e4e01600769 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:49:12 +0900 Subject: [PATCH 3/7] add: v1.4.2 format --- CHANGELOG-Japanese.md | 14 ++++++++++++++ CHANGELOG.md | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG-Japanese.md b/CHANGELOG-Japanese.md index efdd0550..8235f17e 100644 --- a/CHANGELOG-Japanese.md +++ b/CHANGELOG-Japanese.md @@ -1,5 +1,19 @@ # 変更点 +## v1.4.2 [2022/07/XX] + +**新機能:** + +- XXX + +**改善:** + +- XXX + +**バグ修正:** + +- XXX + ## v1.4.1 [2022/06/30] **改善:** diff --git a/CHANGELOG.md b/CHANGELOG.md index 2da4e42a..3f6da33f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changes +## v1.4.2 [2022/07/XX] + +**New Features:** + +- XXX + +**Enhancements:** + +- XXX + +**Bug Fixes:** + +- XXX + ## v1.4.1 [2022/06/30] **Enhancements:** From 8ccaf1d21d8414926b9894374aaa261635b291a4 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:51:50 +0900 Subject: [PATCH 4/7] add: #615 feature --- CHANGELOG-Japanese.md | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-Japanese.md b/CHANGELOG-Japanese.md index 8235f17e..561bffbd 100644 --- a/CHANGELOG-Japanese.md +++ b/CHANGELOG-Japanese.md @@ -8,7 +8,7 @@ **改善:** -- XXX +- `--update-rules` オプションを利用する時に、更新対象のレポジトリを`--rules`オプションで指定できるようにした。 (#615) (@hitenkoku) **バグ修正:** diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f6da33f..4c8c095d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ **Enhancements:** -- XXX +- You can specify update target repository by `--rules` option when you use `--update-rules` option. (#615) (@hitenkoku) **Bug Fixes:** From 35a46628fa0dae2cd0af61f0784195c893065336 Mon Sep 17 00:00:00 2001 From: Tanaka Zakku <71482215+YamatoSecurity@users.noreply.github.com> Date: Sat, 2 Jul 2022 20:07:31 +0900 Subject: [PATCH 5/7] changelog update --- CHANGELOG.md | 2 +- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c8c095d..ea9409cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ **Enhancements:** -- You can specify update target repository by `--rules` option when you use `--update-rules` option. (#615) (@hitenkoku) +- Combining the two options, you can now update rules with `--update-rules` option to a custom rules directory with the `--rules` option. (#615) (@hitenkoku) **Bug Fixes:** diff --git a/Cargo.lock b/Cargo.lock index 3c68bd4d..9a44a3db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,7 +169,7 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.11", + "semver 1.0.12", "serde", "serde_json", ] @@ -220,9 +220,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.7" +version = "3.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7b16274bb247b45177db843202209b12191b631a14a9d06e41b3777d6ecf14" +checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" dependencies = [ "atty", "bitflags", @@ -678,7 +678,7 @@ dependencies = [ "base64", "bytesize", "chrono", - "clap 3.2.7", + "clap 3.2.8", "crossbeam-utils", "csv", "downcast-rs", @@ -914,7 +914,7 @@ dependencies = [ "anyhow", "atty", "chrono", - "clap 3.2.7", + "clap 3.2.8", "file-chunker", "indicatif", "memmap2", @@ -1476,9 +1476,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d92beeab217753479be2f74e54187a6aed4c125ff0703a866c3147a02f0c6dd" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" dependencies = [ "serde", ] @@ -1491,18 +1491,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.137" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" dependencies = [ "proc-macro2", "quote", @@ -1902,9 +1902,9 @@ checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] name = "unicode-normalization" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dee68f85cab8cf68dec42158baf3a79a1cdc065a8b103025965d6ccb7f6cbd" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" dependencies = [ "tinyvec", ] diff --git a/Cargo.toml b/Cargo.toml index 6134b603..05ad4831 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hayabusa" -version = "1.4.1" +version = "1.4.2-dev" authors = ["Yamato Security @SecurityYamato"] edition = "2021" From d688495cb7db1114725d312d668eaf47498e5471 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 20:32:32 +0900 Subject: [PATCH 6/7] change: hayabusa-rules clone when rules option directory is not git repository and rules option is not ./rules. #615 --- src/options/update_rules.rs | 48 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/options/update_rules.rs b/src/options/update_rules.rs index e4244fe1..406b2986 100644 --- a/src/options/update_rules.rs +++ b/src/options/update_rules.rs @@ -35,7 +35,7 @@ impl UpdateRules { ) .ok(); // execution git clone of hayabusa-rules repository when failed open hayabusa repository. - result = UpdateRules::clone_rules(); + result = UpdateRules::clone_rules(Path::new(rule_path)); } else if hayabusa_rule_repo.is_ok() { // case of exist hayabusa-rules repository UpdateRules::_repo_main_reset_hard(hayabusa_rule_repo.as_ref().unwrap())?; @@ -52,23 +52,35 @@ impl UpdateRules { if !rules_path.exists() { create_dir(rules_path).ok(); } - let hayabusa_repo = hayabusa_repo.unwrap(); - let submodules = hayabusa_repo.submodules()?; - let mut is_success_submodule_update = true; - // submodule rules erase path is hard coding to avoid unintentional remove folder. - fs::remove_dir_all(".git/.submodule/rules").ok(); - for mut submodule in submodules { - submodule.update(true, None)?; - let submodule_repo = submodule.open()?; - if let Err(e) = UpdateRules::pull_repository(&submodule_repo) { - AlertMessage::alert(&format!("Failed submodule update. {}", e)).ok(); - is_success_submodule_update = false; + if rule_path == "./rules" { + let hayabusa_repo = hayabusa_repo.unwrap(); + let submodules = hayabusa_repo.submodules()?; + let mut is_success_submodule_update = true; + // submodule rules erase path is hard coding to avoid unintentional remove folder. + fs::remove_dir_all(".git/.submodule/rules").ok(); + for mut submodule in submodules { + submodule.update(true, None)?; + let submodule_repo = submodule.open()?; + if let Err(e) = UpdateRules::pull_repository(&submodule_repo) { + AlertMessage::alert(&format!("Failed submodule update. {}", e)).ok(); + is_success_submodule_update = false; + } + } + if is_success_submodule_update { + result = Ok("Successed submodule update".to_string()); + } else { + result = Err(git2::Error::from_str(&String::default())); } - } - if is_success_submodule_update { - result = Ok("Successed submodule update".to_string()); } else { - result = Err(git2::Error::from_str(&String::default())); + write_color_buffer( + &BufferWriter::stdout(ColorChoice::Always), + None, + "Attempting to git clone the hayabusa-rules repository into the rules folder.", + true, + ) + .ok(); + // execution git clone of hayabusa-rules repository when failed open hayabusa repository. + result = UpdateRules::clone_rules(rules_path); } } if result.is_ok() { @@ -129,10 +141,10 @@ impl UpdateRules { } /// git clone でhauyabusa-rules レポジトリをrulesフォルダにgit cloneする関数 - fn clone_rules() -> Result { + fn clone_rules(rules_path: &Path) -> Result { match Repository::clone( "https://github.com/Yamato-Security/hayabusa-rules.git", - "rules", + rules_path, ) { Ok(_repo) => { println!("Finished cloning the hayabusa-rules repository."); From 01e26c2ae87dafeb66a13883ff4a4cd83643c1ee Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 20:34:25 +0900 Subject: [PATCH 7/7] updated hayabusa-rules submodule reference --- rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules b/rules index 6c9647e4..cf1ea8fd 160000 --- a/rules +++ b/rules @@ -1 +1 @@ -Subproject commit 6c9647e4558400a7122aa3b8f7f4f622505cd965 +Subproject commit cf1ea8fd0dd1ed3d09ac2961980350635911e53c