diff --git a/Cargo.lock b/Cargo.lock index a94030de0..346aa1978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,12 +150,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.21.4" @@ -230,7 +224,7 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.18", + "semver", "serde", "serde_json", ] @@ -396,12 +390,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -545,12 +533,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "downcast" version = "0.11.0" @@ -844,7 +826,6 @@ dependencies = [ "git2", "hashbrown 0.14.0", "hex", - "hhmmss", "horrorshow", "indexmap 2.0.0", "indicatif", @@ -904,16 +885,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hhmmss" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a3a7d0916cb01ef108a66108640419767991ea31d11a1c851bed37686a6062" -dependencies = [ - "chrono", - "time 0.2.27", -] - [[package]] name = "horrorshow" version = "0.8.4" @@ -1601,12 +1572,6 @@ dependencies = [ "termtree", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.67" @@ -1775,15 +1740,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustix" version = "0.37.23" @@ -1880,15 +1836,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.18" @@ -1898,12 +1845,6 @@ dependencies = [ "serde", ] -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.188" @@ -1935,21 +1876,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "shell-words" version = "1.1.0" @@ -1994,7 +1920,7 @@ checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369" dependencies = [ "log", "termcolor", - "time 0.3.28", + "time", ] [[package]] @@ -2034,70 +1960,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "strsim" version = "0.10.0" @@ -2219,21 +2087,6 @@ dependencies = [ "syn 2.0.37", ] -[[package]] -name = "time" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros 0.1.1", - "version_check", - "winapi", -] - [[package]] name = "time" version = "0.3.28" @@ -2246,7 +2099,7 @@ dependencies = [ "num_threads", "serde", "time-core", - "time-macros 0.2.14", + "time-macros", ] [[package]] @@ -2255,16 +2108,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - [[package]] name = "time-macros" version = "0.2.14" @@ -2274,19 +2117,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "time-macros-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn 1.0.109", -] - [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index f0ec99041..95feb7278 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ yaml-rust = "0.4.*" tokio = { version = "1", features = ["full"] } num_cpus = "1.*" downcast-rs = "1.*" -hhmmss = "*" indicatif = "*" hashbrown = "0.14.*" hex = "0.4.*" diff --git a/src/debug/checkpoint_process_timer.rs b/src/debug/checkpoint_process_timer.rs index 6125f671d..c9b94548d 100644 --- a/src/debug/checkpoint_process_timer.rs +++ b/src/debug/checkpoint_process_timer.rs @@ -1,7 +1,7 @@ use std::sync::Mutex; +use crate::detections::utils::output_duration; use chrono::{DateTime, Local}; -use hhmmss::Hhmmss; use lazy_static::lazy_static; use nested::Nested; @@ -38,7 +38,7 @@ impl CheckPointProcessTimer { self.stocked_results.push(format!( "{}: {} ", output_str, - (new_checkpoint - self.prev_checkpoint.unwrap()).hhmmssxxx() + output_duration(new_checkpoint - self.prev_checkpoint.unwrap()) )); self.prev_checkpoint = Some(new_checkpoint); } diff --git a/src/detections/utils.rs b/src/detections/utils.rs index 45ea19cb3..7c62b9ab2 100644 --- a/src/detections/utils.rs +++ b/src/detections/utils.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use nested::Nested; use std::path::{Path, PathBuf}; -use chrono::Local; +use chrono::{Duration, Local}; use termcolor::{Color, ColorChoice}; use tokio::runtime::{Builder, Runtime}; @@ -676,6 +676,21 @@ pub fn is_filtered_by_computer_name( false } +///Durationから出力文字列を作成する関数。絶対値での秒数から算出してhh:mm:ss.fffの形式で出力する。 +pub fn output_duration(d: Duration) -> String { + let mut s = d.num_seconds(); + let mut ms = d.num_milliseconds() - 1000 * s; + if s < 0 { + s = -s; + ms = -ms; + } + let h = s / 3600; + s %= 3600; + let m = s / 60; + s %= 60; + format!("{h:02}:{m:02}:{s:02}.{ms:03}") +} + #[cfg(test)] mod tests { use std::path::Path; @@ -691,13 +706,14 @@ mod tests { }, options::htmlreport::HTML_REPORTER, }; + use chrono::NaiveDate; use compact_str::CompactString; use hashbrown::{HashMap, HashSet}; use nested::Nested; use regex::Regex; use serde_json::Value; - use super::output_profile_name; + use super::{output_duration, output_profile_name}; #[test] fn test_create_recordinfos() { @@ -1098,4 +1114,19 @@ mod tests { ), )); } + + #[test] + /// Durationから出力文字列を作成する関数のテスト + fn test_output_duration() { + let time1 = NaiveDate::from_ymd_opt(2021, 12, 26) + .unwrap() + .and_hms_milli_opt(2, 34, 49, 0) + .unwrap(); + let time2 = NaiveDate::from_ymd_opt(2021, 12, 25) + .unwrap() + .and_hms_milli_opt(1, 23, 45, 678) + .unwrap(); + assert_eq!(output_duration(time1 - time2), "25:11:03.322".to_string()); + assert_eq!(output_duration(time2 - time1), "25:11:03.322".to_string()); + } } diff --git a/src/main.rs b/src/main.rs index f4dd616a9..281b4418b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,8 @@ use hayabusa::detections::detection::{self, EvtxRecordInfo}; use hayabusa::detections::message::{AlertMessage, ERROR_LOG_STACK}; use hayabusa::detections::rule::{get_detection_keys, RuleNode}; use hayabusa::detections::utils::{ - check_setting_path, get_writable_color, output_and_data_stack_for_html, output_profile_name, + check_setting_path, get_writable_color, output_and_data_stack_for_html, output_duration, + output_profile_name, }; use hayabusa::options; use hayabusa::options::htmlreport::{self, HTML_REPORTER}; @@ -31,7 +32,6 @@ use hayabusa::timeline::computer_metrics::countup_event_by_computer; use hayabusa::{afterfact::after_fact, detections::utils}; use hayabusa::{detections::configs, timeline::timelines::Timeline}; use hayabusa::{detections::utils::write_color_buffer, filter}; -use hhmmss::Hhmmss; use indicatif::ProgressBar; use indicatif::{ProgressDrawTarget, ProgressStyle}; use itertools::Itertools; @@ -700,7 +700,7 @@ impl App { // 処理時間の出力 let analysis_end_time: DateTime = Local::now(); let analysis_duration = analysis_end_time.signed_duration_since(analysis_start_time); - let elapsed_output_str = format!("Elapsed time: {}", &analysis_duration.hhmmssxxx()); + let elapsed_output_str = format!("Elapsed time: {}", output_duration(analysis_duration)); output_and_data_stack_for_html( &elapsed_output_str, "General Overview {#general_overview}",