Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add file size next to file name under the progress bar #1500

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-Japanese.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- 見やすくなるように色を更新した。 (#1480) (@yamatosecurity)
- 実行開始と終了のメッセージを出力するようにした。 (#1492) (@fukusuket)
- 出力に新しい配色を追加した。 (#1491) (@fukusuket)
- ファイルサイズがプログレスバーの下のファイル名の横に表示されるようになった。 (#1471) (@fukusuket)

**バグ修正:**

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- The colors were updated to make it easier to read. (#1480) (@yamatosecurity)
- Added start and finish messages of the day. (#1492) (@fukusuket)
- New color scheme added to output. (#1491) (@fukusuket)
- File size is now displayed next to the file name under the progress bar. (#1471) (@fukusuket)

**Bug Fixes:**

Expand Down
61 changes: 34 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl App {
if stored_static.html_report_flag {
let mut output_data = Nested::<String>::new();
output_data.extend(vec![
format!("- Command line: {}", std::env::args().join(" ")),
format!("- Command line: {}", env::args().join(" ")),
format!(
"- Start time: {}",
analysis_start_time.format("%Y/%m/%d %H:%M")
Expand Down Expand Up @@ -320,7 +320,7 @@ impl App {
if let Some(html_path) = &stored_static.output_option.as_ref().unwrap().html_report
{
// if already exists same html report file. output alert message and exit
if !(stored_static.output_option.as_ref().unwrap().clobber)
if !stored_static.output_option.as_ref().unwrap().clobber
&& utils::check_file_expect_not_exist(
html_path.as_path(),
format!(
Expand All @@ -333,7 +333,7 @@ impl App {
}
}
if let Some(path) = &stored_static.output_path {
if !(stored_static.output_option.as_ref().unwrap().clobber)
if !stored_static.output_option.as_ref().unwrap().clobber
&& utils::check_file_expect_not_exist(
path.as_path(),
format!(
Expand Down Expand Up @@ -386,7 +386,7 @@ impl App {
if let Some(path) = &stored_static.output_path {
for suffix in &["-successful.csv", "-failed.csv"] {
let output_file = format!("{}{suffix}", path.to_str().unwrap());
if !(stored_static.output_option.as_ref().unwrap().clobber)
if !stored_static.output_option.as_ref().unwrap().clobber
&& utils::check_file_expect_not_exist(
Path::new(output_file.as_str()),
format!(
Expand Down Expand Up @@ -422,7 +422,7 @@ impl App {
| Action::LogMetrics(_)
| Action::Search(_) => {
if let Some(path) = &stored_static.output_path {
if !(stored_static.output_option.as_ref().unwrap().clobber)
if !stored_static.output_option.as_ref().unwrap().clobber
&& utils::check_file_expect_not_exist(
path.as_path(),
format!(
Expand Down Expand Up @@ -468,7 +468,7 @@ impl App {
pivot_key_unions.iter().for_each(|(key, _)| {
let keywords_file_name =
csv_path.as_path().display().to_string() + "-" + key + ".txt";
if !(stored_static.output_option.as_ref().unwrap().clobber) && utils::check_file_expect_not_exist(
if !stored_static.output_option.as_ref().unwrap().clobber && utils::check_file_expect_not_exist(
Path::new(&keywords_file_name),
format!(
" The file {} already exists. Please specify a different filename or add the -C, --clobber option to overwrite.",
Expand Down Expand Up @@ -1118,7 +1118,7 @@ impl App {
let subdir_ret =
Self::collect_evtxfiles(path_str, target_extensions, stored_static);
ret.extend(subdir_ret);
Option::Some(())
Some(())
});
} else if target_extensions.contains(
path.extension()
Expand Down Expand Up @@ -1188,21 +1188,7 @@ impl App {
.ok();
let mut total_file_size = ByteSize::b(0);
for file_path in &evtx_files {
let file_size = match fs::metadata(file_path) {
Ok(res) => res.len(),
Err(err) => {
if stored_static.verbose_flag {
AlertMessage::warn(&err.to_string()).ok();
}
if !stored_static.quiet_errors_flag {
ERROR_LOG_STACK
.lock()
.unwrap()
.push(format!("[WARN] {err}"));
}
0
}
};
let file_size = Self::get_file_size(file_path, stored_static);
total_file_size += ByteSize::b(file_size);
}
write_color_buffer(
Expand Down Expand Up @@ -1789,9 +1775,12 @@ impl App {
let mut afterfact_writer = afterfact::init_writer(stored_static);
for evtx_file in evtx_files {
if is_show_progress {
let size = Self::get_file_size(&evtx_file, stored_static);
let file_size = ByteSize::b(size);
let pb_msg = format!(
"{:?}",
&evtx_file.to_str().unwrap_or_default().replace('\\', "/")
"{:?} ({})",
&evtx_file.to_str().unwrap_or_default().replace('\\', "/"),
file_size.to_string_as(false)
);
if !pb_msg.is_empty() {
pb.set_message(pb_msg);
Expand Down Expand Up @@ -2548,11 +2537,11 @@ impl App {
parse_config = parse_config.num_threads(0); // 設定しないと遅かったので、設定しておく。

let evtx_parser = evtx_parser.with_configuration(parse_config);
Option::Some(evtx_parser)
Some(evtx_parser)
}
Err(e) => {
eprintln!("{e}");
Option::None
None
}
}
}
Expand Down Expand Up @@ -2678,10 +2667,28 @@ impl App {
| Action::PivotKeywordsList(_)
| Action::SetDefaultProfile(_)
| Action::Search(_)
| Action::ComputerMetrics(_) => std::env::args().len() != 2,
| Action::ComputerMetrics(_) => env::args().len() != 2,
_ => true,
}
}

fn get_file_size(file_path: &Path, stored_static: &StoredStatic) -> u64 {
match fs::metadata(file_path) {
Ok(res) => res.len(),
Err(err) => {
if stored_static.verbose_flag {
AlertMessage::warn(&err.to_string()).ok();
}
if !stored_static.quiet_errors_flag {
ERROR_LOG_STACK
.lock()
.unwrap()
.push(format!("[WARN] {err}"));
}
0
}
}
}
}

#[cfg(test)]
Expand Down
Loading