Skip to content

Commit

Permalink
feat: add UserData associated type in ModuleData trait
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed Apr 28, 2024
1 parent 02d6f8c commit 5f73583
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions boreal/src/module/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct Data {

impl ModuleData for Console {
type PrivateData = Data;
type UserData = ();
}

impl Console {
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl Data {

impl ModuleData for Dex {
type PrivateData = Data;
type UserData = ();
}

fn parse_file(mem: &[u8], data: &mut Data) -> Option<HashMap<&'static str, Value>> {
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/dotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub struct Data {

impl ModuleData for Dotnet {
type PrivateData = Data;
type UserData = ();
}

fn parse_file<HEADERS: ImageNtHeaders>(
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl Module for Elf {

impl ModuleData for Elf {
type PrivateData = Data;
type UserData = ();
}

#[derive(Default)]
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub struct Cache {

impl ModuleData for Hash {
type PrivateData = Data;
type UserData = ();
}

fn compute_hash_from_bytes<D: Digest>(bytes: &[u8]) -> Value {
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ struct FileData {

impl ModuleData for MachO {
type PrivateData = Data;
type UserData = ();
}

impl MachO {
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/magic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum CacheEntry {

impl ModuleData for Magic {
type PrivateData = Data;
type UserData = ();
}

impl Magic {
Expand Down
10 changes: 9 additions & 1 deletion boreal/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ impl std::fmt::Debug for ModuleDataMap {
///
/// impl ModuleData for Foo {
/// type PrivateData = FooData;
/// type UserData = ();
/// }
///
/// impl Module for Foo {
Expand Down Expand Up @@ -308,8 +309,15 @@ impl std::fmt::Debug for ModuleDataMap {
/// }
/// ```
pub trait ModuleData: Module {
/// Data to associate with the module.
/// Private Data to associate with the module.
///
/// This is the data that the module can store and retrieve during a scan.
type PrivateData: Any + Send + Sync;

/// Data that the user can provide to the module.
///
/// The data can be provided by the user through the [`boreal::scanner::ScanParams`].
type UserData: Any + Send + Sync;
}

impl ModuleDataMap {
Expand Down
1 change: 1 addition & 0 deletions boreal/src/module/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ impl Module for Pe {

impl ModuleData for Pe {
type PrivateData = Data;
type UserData = ();
}

impl Pe {
Expand Down

0 comments on commit 5f73583

Please sign in to comment.