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

rayhunter-check improvements #56

Merged
merged 1 commit into from
Aug 19, 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
32 changes: 29 additions & 3 deletions bin/src/check.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, i32> = 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);
}
12 changes: 6 additions & 6 deletions lib/src/analysis/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnalyzerMetadata>,
pub analyzers: Vec<AnalyzerMetadata>,
}

#[derive(Serialize, Debug, Clone)]
pub struct PacketAnalysis {
timestamp: DateTime<FixedOffset>,
events: Vec<Option<Event>>,
pub timestamp: DateTime<FixedOffset>,
pub events: Vec<Option<Event>>,
}

#[derive(Serialize, Debug)]
Expand Down Expand Up @@ -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 {
Expand Down
Loading