Skip to content

Commit

Permalink
Merge pull request #1493 from Yamato-Security/1492-opening-closing-msg
Browse files Browse the repository at this point in the history
feat: add opening/closing messages
  • Loading branch information
YamatoSecurity authored Nov 14, 2024
2 parents c7d0a7d + c300229 commit c7f1ecf
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-Japanese.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `windash`文字が、`rules/config/windash_characters.txt`から動的に読み込まれるようになった。(#1440) (@fukusuket)
- `logon-summary`コマンドがRDPイベントからのログオン情報を表示するようになった。注意: ファイルに保存する場合、Hayabusaはより詳細な情報を出力する。(#1468) (@fukusuket)
- 見やすくなるように色を更新した。 (#1480) (@yamatosecurity)
- 実行開始と終了のメッセージを出力するようにした。 (#1492) (@fukusuket)

**バグ修正:**

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `windash` characters are now being dynamically read from `rules/config/windash_characters.txt`. (#1440) (@fukusuket)
- `logon-summary` command now displays logon information from RDP events. Note: Hayabusa will output more detailed information when saving to a file. (#1468) (@fukusuket)
- The colors were updated to make it easier to read. (#1480) (@yamatosecurity)
- Added start and finish messages of the day. (#1492) (@fukusuket)

**Bug Fixes:**

Expand Down
77 changes: 42 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nested="*"
num = "0.4.0"
num-format = "*"
pulldown-cmark = { version = "0.9.*", default-features = false, features = ["simd"] }
rand = "0.8.*"
regex = "1"
serde = { version = "1.*", features = ["derive"] }
serde_derive = "1.*"
Expand Down
48 changes: 42 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ use std::borrow::BorrowMut;
use std::ffi::{OsStr, OsString};
use std::fmt::Display;
use std::fmt::Write as _;
use std::io::{copy, BufWriter, Write};
use std::io::{copy, BufRead, BufWriter, Write};
use std::path::Path;
use std::ptr::null_mut;
use std::sync::Arc;
use std::time::Duration;
use std::{
env,
fs::{self, File},
io,
path::PathBuf,
vec,
};
Expand Down Expand Up @@ -62,6 +63,7 @@ use libmimalloc_sys::mi_stats_print_out;
use mimalloc::MiMalloc;
use nested::Nested;
use num_format::{Locale, ToFormattedString};
use rand::seq::SliceRandom;
use rust_embed::Embed;
use serde_json::{Map, Value};
use termcolor::{BufferWriter, Color, ColorChoice};
Expand Down Expand Up @@ -221,7 +223,7 @@ impl App {
.ok();
println!();
}

let _ = self.output_open_close_message("opening_messages.txt", stored_static);
write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),
None,
Expand Down Expand Up @@ -616,7 +618,6 @@ impl App {
}
}
}
println!();
let split_now_version = &now_version
.replace("-dev", "")
.split('.')
Expand Down Expand Up @@ -647,8 +648,9 @@ impl App {
true,
)
.ok();
println!();
}
println!();
let _ = self.output_open_close_message("closing_messages.txt", stored_static);
return;
}
Action::LevelTuning(option) => {
Expand Down Expand Up @@ -717,6 +719,7 @@ impl App {
)
.ok();
}
let _ = self.output_open_close_message("closing_messages.txt", stored_static);
return;
}
Action::SetDefaultProfile(_) => {
Expand Down Expand Up @@ -747,6 +750,7 @@ impl App {
) {
AlertMessage::alert(&e).ok();
}
let _ = self.output_open_close_message("closing_messages.txt", stored_static);
return;
}
Action::ListProfiles(_) => {
Expand Down Expand Up @@ -774,7 +778,7 @@ impl App {
)
.ok();
}
println!();
let _ = self.output_open_close_message("closing_messages.txt", stored_static);
return;
}
}
Expand Down Expand Up @@ -807,6 +811,8 @@ impl App {
if ERROR_LOG_STACK.lock().unwrap().len() > 0 {
AlertMessage::create_error_log(stored_static.quiet_errors_flag);
}
println!();
let _ = self.output_open_close_message("closing_messages.txt", stored_static);

// Debugフラグをつけていた時にはメモリ利用情報などの統計情報を画面に出力する
if stored_static.config.debug {
Expand All @@ -817,7 +823,6 @@ impl App {
mi_stats_print_out(None, null_mut());
}
}
println!();
}

fn analysis_start(
Expand Down Expand Up @@ -2376,6 +2381,37 @@ impl App {
}
}

fn output_open_close_message(
&self,
file_path: &str,
stored_static: &StoredStatic,
) -> io::Result<()> {
if stored_static.common_options.quiet {
return Ok(());
}
let checked_path = check_setting_path(
&CURRENT_EXE_PATH.to_path_buf(),
format!("rules/config/{}", file_path).as_str(),
true,
);
if let Some(f) = checked_path {
if f.exists() {
let file = File::open(f)?;
let lines: Vec<String> =
io::BufReader::new(file).lines().collect::<Result<_, _>>()?;
if let Some(random_line) = lines.choose(&mut rand::thread_rng()) {
println!("{}\n", random_line);
}
} else if let Some(contents) = ONE_CONFIG_MAP.get(file_path) {
let lines: Vec<&str> = contents.lines().collect();
if let Some(random_line) = lines.choose(&mut rand::thread_rng()) {
println!("{}\n", random_line);
}
}
}
Ok(())
}

/// check architecture
fn is_matched_architecture_and_binary(&self) -> bool {
if cfg!(target_os = "windows") {
Expand Down
1 change: 0 additions & 1 deletion src/options/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ impl Update {
)
.ok();
}
println!();
for (key, value) in &update_count_by_rule_type {
println!("Updated {key} rules: {value}");
}
Expand Down

0 comments on commit c7f1ecf

Please sign in to comment.