use serde::Serialize;
use crate::detect::FileType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Verdict {
Clean,
Suspicious,
Malicious,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Severity {
Info,
Low,
Medium,
High,
Critical,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct Finding {
pub code: &'static str,
pub severity: Severity,
pub message: String,
pub offset: Option<u64>,
}
impl Finding {
pub fn new(code: &'static str, severity: Severity, message: impl Into<String>) -> Self {
Self {
code,
severity,
message: message.into(),
offset: None,
}
}
pub fn at(mut self, offset: usize) -> Self {
self.offset = Some(offset as u64);
self
}
}
pub const CODES: &[&str] = &[
"type.executable",
"type.mismatch",
"type.unknown",
"type.not_allowed",
"name.dangerous_extension",
"payload.php",
"payload.script",
"payload.template",
"hash.blocklisted",
"yara.match",
"yara.error",
"limit.size",
"limit.decompression",
"limit.depth",
"limit.time",
"limit.complexity",
"image.malformed",
"image.trailing_data",
"image.vendor_trailer",
"image.polyglot",
"image.metadata.payload",
"image.pixel_bomb",
"svg.script",
"svg.event_handler",
"svg.javascript_uri",
"svg.data_uri",
"svg.foreign_object",
"svg.external_ref",
"svg.entity",
"svg.malformed",
"pdf.javascript",
"pdf.launch",
"pdf.postscript",
"pdf.open_action",
"pdf.additional_action",
"pdf.obfuscated_name",
"pdf.embedded_file",
"pdf.rich_media",
"pdf.xfa",
"pdf.encrypted",
"pdf.polyglot",
"pdf.trailing_data",
"pdf.submit_form",
"pdf.remote_goto",
"pdf.uri",
"pdf.dangerous_uri",
"pdf.external_ref",
"pdf.xml_entity",
"pdf.xml_external_ref",
"pdf.pixel_bomb",
"pdf.page_size",
"pdf.draw_recursion",
"pdf.conflicting_objects",
"pdf.risky_codec",
"pdf.print_only",
"pdf.signature_modified",
"pdf.incremental_update",
"pdf.malformed",
"ps.pipe",
"ps.file_access",
"ps.device_access",
"ps.ghostscript_internal",
"ps.exec_dynamic",
"ps.unusual_filter",
"ps.malformed",
"ps.wmf_preview",
];
#[derive(Debug, Clone, Serialize)]
#[non_exhaustive]
pub struct Report {
pub verdict: Verdict,
pub detected_type: FileType,
pub declared_types: Vec<FileType>,
pub size: u64,
pub sha256: String,
pub findings: Vec<Finding>,
}
impl Report {
pub fn has(&self, code: &str) -> bool {
self.findings.iter().any(|f| f.code == code)
}
}