#[cfg(feature = "detection")]
mod detection;
#[cfg(feature = "hashing")]
mod hashing;
mod histogram;
mod searcher;
#[cfg(feature = "yara")]
mod yara;
pub(crate) mod exporter;
pub(crate) mod importer;
use crate::{WombatApp, panels::FileInfoData};
use bladvak::{ErrorManager, eframe::egui};
use file_format::FileFormat;
use histogram::Histogram;
use searcher::Searcher;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct WindowsData {
pub(crate) histogram: Histogram,
pub(crate) searcher: Searcher,
#[cfg(feature = "detection")]
pub(crate) detection: detection::Detection,
#[cfg(feature = "hashing")]
pub(crate) hashing: hashing::Hashing,
#[cfg(feature = "yara")]
pub(crate) yara: yara::Yara,
}
impl WindowsData {
pub(crate) fn new() -> Self {
Self {
histogram: Histogram::new(),
#[cfg(feature = "detection")]
detection: detection::Detection::new(),
searcher: Searcher::new(),
#[cfg(feature = "hashing")]
hashing: hashing::Hashing::new(),
#[cfg(feature = "yara")]
yara: yara::Yara::new(),
}
}
pub(crate) fn reset(&mut self) {
self.histogram.reset();
#[cfg(feature = "detection")]
self.detection.reset();
self.searcher.reset();
#[cfg(feature = "hashing")]
self.hashing.reset();
#[cfg(feature = "yara")]
self.yara.reset();
}
pub(crate) fn selection_stale(&mut self) {
#[cfg(feature = "hashing")]
self.hashing.selection_stale();
}
pub(crate) fn ui_top_bar(&mut self, ui: &mut egui::Ui) {
ui.toggle_value(&mut self.histogram.is_open, "Histogram");
ui.toggle_value(&mut self.searcher.is_open, "Searcher");
#[cfg(feature = "detection")]
ui.toggle_value(&mut self.detection.is_open, "Detection");
#[cfg(feature = "hashing")]
ui.toggle_value(&mut self.hashing.is_open, hashing::Hashing::window_title());
#[cfg(feature = "yara")]
ui.toggle_value(&mut self.yara.is_open, yara::Yara::window_title());
}
}
impl WombatApp {
pub(crate) fn ui_windows(&mut self, ui: &mut egui::Ui, error_manager: &mut ErrorManager) {
let Some(document) = self.documents.get_current_doc_mut() else {
return;
};
document
.windows_data
.histogram
.ui(&document.binary_file, ui, error_manager);
#[cfg(feature = "hashing")]
document.windows_data.hashing.ui(
&document.binary_file,
&document.selection,
ui,
error_manager,
);
#[cfg(feature = "yara")]
document
.windows_data
.yara
.ui(&document.binary_file, ui, error_manager);
if document.file_format.is_none() {
let file_fmt = FileFormat::from_bytes(&document.binary_file);
let data = FileInfoData {
kind: file_fmt.kind(),
file_type: file_fmt.media_type().to_string(),
extension: file_fmt.extension().to_string(),
name: file_fmt.name().to_string(),
};
document.file_format = Some(data);
}
if let Some(range) = document.windows_data.searcher.ui(
&document.binary_file,
&document.selection,
ui,
error_manager,
) {
document.go_to_range(range);
}
#[cfg(feature = "detection")]
if let Some(infos) = &document.file_format
&& let Some(range) =
document
.windows_data
.detection
.ui(&document.binary_file, infos, ui, error_manager)
{
document.go_to_range(range);
}
}
}