Skip to main content

armorlib/
preprocessor.rs

1//! This module defines the `Preprocessor` trait, which allows for generalized data to be created
2//! about `BinaryObject`s prior to being run through the `ScanModule`s to avoid duplicate
3//! processing. For more information on how to contribute your own preprocessor, see
4//! `docs/contributing/PREPROCESSORS.md`.
5
6use std::collections::HashMap;
7use binary_object::BinaryObject;
8
9/// A trait that defines the necessary functions of a `Preprocessor`. A `Preprocessor` is a
10/// modular component that has no dependencies on other preprocessors. It creates a HashMap
11/// of `String`s mapped to other `String`s that can then be accessed by the scan modules.
12/// For more information on how to contribute your own preprocessor, see
13/// `docs/contributing/PREPROCESSORS.md`.
14pub trait Preprocessor {
15    /// Process the given `BinaryObject` and return a HashMap of `String`s.
16    fn process(&self, binary_object: &BinaryObject) -> HashMap<String, String>;
17
18    /// Returns a tuple of the name and description of the preprocessor. It is important that
19    /// the first item of the tuple, the name, does not change once a preprocessor has been
20    /// added to the master ArmorLib codebase, as the name is what scan modules rely on to
21    /// ensure that the preprocessor's data is in scope. The name should be in snake case.
22    fn info(&self) -> (&'static str, &'static str);
23
24    /// Returns a `&'static str` of the name of the preprocessor. This is the name that the
25    /// scan modules will rely on to ensure that the preprocessor's data is available, so it
26    /// is important that this information does not change.
27    fn name(&self) -> &'static str {
28        return self.info().0;
29    }
30
31    /// Returns a `&'static str` of the description of the preprocessor.
32    fn description(&self) -> &'static str {
33        return self.info().1;
34    }
35}