Struct dectree_rs::SignatureDecisionTree

source ·
pub struct SignatureDecisionTree<T>
where T: Clone + Default,
{ /* private fields */ }
Expand description

Represents a decision tree that can be used to search for signatures. This is a tree structure that can be used to search for signatures in a binary blob. The tree is built by adding signatures to the tree and then searching for them.

use dectree_rs::SignatureDecisionTree;
 
let mut tree = SignatureDecisionTree::new();
tree.add_signature(vec![0x55, 0xe9, 0xd8, 0x01, 0xfe, 0xff, 0x32, 0x77, 0x89, 0x4f, 0x55], None, None);
tree.add_signature(vec![0x55, 0xe9, 0xd8, 0x01, 0xfe, 0xff, 0x32], None, None);
tree.add_signature(vec![0x55, 0xe9, 0xd8, 0x01, 0xfe, 0x00], None, None);
assert_eq!(tree.get_signature(vec![0x55, 0xe9, 0xd8, 0x01, 0xfe, 0xff, 0x32, 0x00, 0x99, 0x36, 0x5f, 0x21, 0xfd], None), Some(()));
assert_eq!(tree.get_signature(vec![0x55, 0xe9, 0xd8, 0x01, 0xfe, 0xff, 0x32], None), Some(()));
assert_eq!(tree.get_signature(vec![0x55, 0xe9, 0xd8, 0x01, 0xfe, 0x00], None), Some(()));
assert_eq!(tree.get_signature(vec![0x55], None), None);

Implementations§

source§

impl<T> SignatureDecisionTree<T>
where T: Clone + Default,

source

pub fn new() -> Self

Create a new SignatureDecisionTree.

source

pub fn add_signature( &mut self, bytes: Vec<u8>, masks: Option<Vec<u8>>, val: Option<T> )

Add a signature to the search tree. If masks goes unspecified, it will be assumed to be all ones vec![0xff; bytes.len()].

Additionally, you may specify val as the object to get back with tree.get_signature().

source

pub fn is_signature(&self, bytes: Vec<u8>, offset: Option<i32>) -> bool

Check if a signature is in the search tree.

source

pub fn get_signature(&self, bytes: Vec<u8>, offset: Option<i32>) -> Option<T>

Get the object associated with a signature in the search tree.

Trait Implementations§

source§

impl<T> Clone for SignatureDecisionTree<T>
where T: Clone + Default + Clone,

source§

fn clone(&self) -> SignatureDecisionTree<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for SignatureDecisionTree<T>
where T: Clone + Default + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for SignatureDecisionTree<T>
where T: Clone + Default + Default,

source§

fn default() -> SignatureDecisionTree<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.