From f2a075a10397699791c2c0c0a8652dbe4811cbbd Mon Sep 17 00:00:00 2001 From: Will Greenberg Date: Mon, 12 Aug 2024 13:32:38 -0700 Subject: [PATCH] rayhunter-check improvements --- bin/src/check.rs | 32 +++++++++++++++++++++++++++++--- lib/src/analysis/analyzer.rs | 12 ++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/bin/src/check.rs b/bin/src/check.rs index d844a53..ebc210b 100644 --- a/bin/src/check.rs +++ b/bin/src/check.rs @@ -1,4 +1,4 @@ -use std::{future, path::PathBuf, pin::pin}; +use std::{collections::HashMap, future, path::PathBuf, pin::pin}; use rayhunter::{analysis::analyzer::Harness, diag::DataType, qmdl::QmdlReader}; use tokio::fs::File; use clap::Parser; @@ -23,9 +23,35 @@ async fn main() { let mut qmdl_reader = QmdlReader::new(qmdl_file, Some(file_size as usize)); let mut qmdl_stream = pin!(qmdl_reader.as_stream() .try_filter(|container| future::ready(container.data_type == DataType::UserSpace))); - println!("{}\n", serde_json::to_string(&harness.get_metadata()).expect("failed to serialize report metadata")); + println!("Analyzers:"); + for analyzer in harness.get_metadata().analyzers { + println!(" - {}: {}", analyzer.name, analyzer.description); + } + let mut skipped_reasons: HashMap = HashMap::new(); + let mut total_messages = 0; + let mut warnings = 0; + let mut skipped = 0; while let Some(container) = qmdl_stream.try_next().await.expect("failed getting QMDL container") { let row = harness.analyze_qmdl_messages(container); - println!("{}\n", serde_json::to_string(&row).expect("failed to serialize row")); + total_messages += 1; + for reason in row.skipped_message_reasons { + *skipped_reasons.entry(reason).or_insert(0) += 1; + skipped += 1; + } + for analysis in row.analysis { + for maybe_event in analysis.events { + if let Some(event) = maybe_event { + warnings += 1; + println!("{}: {:?}", analysis.timestamp, event); + } + } + } + } + if skipped > 0 { + println!("Messages skipped:"); + for (reason, count) in skipped_reasons.iter() { + println!(" - {}: \"{}\"", count, reason); + } } + println!("{} messages analyzed, {} warnings, {} messages skipped", total_messages, warnings, skipped); } diff --git a/lib/src/analysis/analyzer.rs b/lib/src/analysis/analyzer.rs index 7756a33..fbd65ef 100644 --- a/lib/src/analysis/analyzer.rs +++ b/lib/src/analysis/analyzer.rs @@ -60,19 +60,19 @@ pub trait Analyzer { #[derive(Serialize, Debug)] pub struct AnalyzerMetadata { - name: String, - description: String, + pub name: String, + pub description: String, } #[derive(Serialize, Debug)] pub struct ReportMetadata { - analyzers: Vec, + pub analyzers: Vec, } #[derive(Serialize, Debug, Clone)] pub struct PacketAnalysis { - timestamp: DateTime, - events: Vec>, + pub timestamp: DateTime, + pub events: Vec>, } #[derive(Serialize, Debug)] @@ -175,7 +175,7 @@ impl Harness { pub fn get_metadata(&self) -> ReportMetadata { let names = self.get_names(); - let descriptions = self.get_names(); + let descriptions = self.get_descriptions(); let mut analyzers = Vec::new(); for (name, description) in names.iter().zip(descriptions.iter()) { analyzers.push(AnalyzerMetadata {