diff --git a/daemon/src/analysis.rs b/daemon/src/analysis.rs index d38c9e8..0710b1f 100644 --- a/daemon/src/analysis.rs +++ b/daemon/src/analysis.rs @@ -7,7 +7,7 @@ use axum::{ http::StatusCode, }; use futures::TryStreamExt; -use log::{debug, error, info}; +use log::{error, info}; use rayhunter::analysis::analyzer::{AnalyzerConfig, Harness}; use rayhunter::diag::{DataType, MessagesContainer}; use rayhunter::qmdl::QmdlReader; @@ -24,7 +24,6 @@ use crate::server::ServerState; pub struct AnalysisWriter { writer: BufWriter, harness: Harness, - bytes_written: usize, } // We write our analysis results to a file immediately to minimize the amount of @@ -39,7 +38,6 @@ impl AnalysisWriter { let mut result = Self { writer: BufWriter::new(file), - bytes_written: 0, harness, }; let metadata = result.harness.get_metadata(); @@ -48,12 +46,11 @@ impl AnalysisWriter { } // Runs the analysis harness on the given container, serializing the results - // to the analysis file, returning the file's new length, and whether any - // warnings were detected + // to the analysis file, returning the whether any warnings were detected pub async fn analyze( &mut self, container: MessagesContainer, - ) -> Result<(usize, bool), std::io::Error> { + ) -> Result { let mut warning_detected = false; for row in self.harness.analyze_qmdl_messages(container) { if !row.is_empty() { @@ -61,13 +58,12 @@ impl AnalysisWriter { } warning_detected |= row.contains_warnings(); } - Ok((self.bytes_written, warning_detected)) + Ok(warning_detected) } async fn write(&mut self, value: &T) -> Result<(), std::io::Error> { let mut value_str = serde_json::to_string(value).unwrap(); value_str.push('\n'); - self.bytes_written += value_str.len(); self.writer.write_all(value_str.as_bytes()).await?; self.writer.flush().await?; Ok(()) @@ -133,7 +129,7 @@ async fn perform_analysis( analyzer_config: &AnalyzerConfig, ) -> Result<(), String> { info!("Opening QMDL and analysis file for {name}..."); - let (analysis_file, qmdl_file, entry_index) = { + let (analysis_file, qmdl_file) = { let mut qmdl_store = qmdl_store_lock.write().await; let (entry_index, _) = qmdl_store .entry_for_name(name) @@ -147,7 +143,7 @@ async fn perform_analysis( .await .map_err(|e| format!("{e:?}"))?; - (analysis_file, qmdl_file, entry_index) + (analysis_file, qmdl_file) }; let mut analysis_writer = AnalysisWriter::new(analysis_file, analyzer_config) @@ -171,16 +167,10 @@ async fn perform_analysis( .await .expect("failed getting QMDL container") { - let (size_bytes, _) = analysis_writer + let _ = analysis_writer .analyze(container) .await .map_err(|e| format!("{e:?}"))?; - debug!("{name} analysis: {size_bytes} bytes written"); - let mut qmdl_store = qmdl_store_lock.write().await; - qmdl_store - .update_entry_analysis_size(entry_index, size_bytes) - .await - .map_err(|e| format!("{e:?}"))?; } analysis_writer diff --git a/daemon/src/diag.rs b/daemon/src/diag.rs index f5158cc..4d1da33 100644 --- a/daemon/src/diag.rs +++ b/daemon/src/diag.rs @@ -130,18 +130,13 @@ pub fn run_diag_read_thread( } if let Some(analysis_writer) = maybe_analysis_writer.as_mut() { - let analysis_output = analysis_writer.analyze(container).await + let heuristic_warning = analysis_writer.analyze(container).await .expect("failed to analyze container"); - let (analysis_file_len, heuristic_warning) = analysis_output; if heuristic_warning { info!("a heuristic triggered on this run!"); ui_update_sender.send(display::DisplayState::WarningDetected).await .expect("couldn't send ui update message: {}"); } - let mut qmdl_store = qmdl_store_lock.write().await; - let index = qmdl_store.current_entry.expect("DiagDevice had qmdl_writer, but QmdlStore didn't have current entry???"); - qmdl_store.update_entry_analysis_size(index, analysis_file_len).await - .expect("failed to update analysis file size"); } }, Err(err) => { diff --git a/daemon/src/qmdl_store.rs b/daemon/src/qmdl_store.rs index 2261b0f..9022e21 100644 --- a/daemon/src/qmdl_store.rs +++ b/daemon/src/qmdl_store.rs @@ -51,7 +51,6 @@ pub struct ManifestEntry { pub start_time: DateTime, pub last_message_time: Option>, pub qmdl_size_bytes: usize, - pub analysis_size_bytes: usize, pub rayhunter_version: Option, pub system_os: Option, pub arch: Option, @@ -66,14 +65,12 @@ impl ManifestEntry { start_time: now, last_message_time: None, qmdl_size_bytes: 0, - analysis_size_bytes: 0, rayhunter_version: Some(metadata.rayhunter_version), system_os: Some(metadata.system_os), arch: Some(metadata.arch), } } - pub fn get_qmdl_filepath>(&self, path: P) -> PathBuf { let mut filepath = path.as_ref().join(&self.name); filepath.set_extension("qmdl"); @@ -239,7 +236,6 @@ impl RecordingStore { .open(entry.get_analysis_filepath(&self.path)) .await .map_err(RecordingStoreError::ReadFileError)?; - self.update_entry_analysis_size(entry_index, 0).await?; Ok(file) } @@ -265,16 +261,6 @@ impl RecordingStore { self.write_manifest().await } - // Sets the given entry's analysis file size - pub async fn update_entry_analysis_size( - &mut self, - entry_index: usize, - size_bytes: usize, - ) -> Result<(), RecordingStoreError> { - self.manifest.entries[entry_index].analysis_size_bytes = size_bytes; - self.write_manifest().await - } - async fn write_manifest(&mut self) -> Result<(), RecordingStoreError> { let tmp_path = self.path.join("manifest.toml.new"); let mut manifest_tmp_file = File::create(&tmp_path) diff --git a/daemon/web/src/lib/manifest.svelte.ts b/daemon/web/src/lib/manifest.svelte.ts index 9643f5e..f9e60e5 100644 --- a/daemon/web/src/lib/manifest.svelte.ts +++ b/daemon/web/src/lib/manifest.svelte.ts @@ -11,7 +11,6 @@ interface JsonManifestEntry { start_time: string; last_message_time: string; qmdl_size_bytes: number; - analysis_size_bytes: number; } export class Manifest { @@ -62,7 +61,6 @@ export class ManifestEntry { constructor(json: JsonManifestEntry) { this.name = json.name; this.qmdl_size_bytes = json.qmdl_size_bytes; - this.analysis_size_bytes = json.analysis_size_bytes; this.start_time = new Date(json.start_time); if (json.last_message_time) { this.last_message_time = new Date(json.last_message_time);