[][src]Struct yara::Compiler

pub struct Compiler { /* fields omitted */ }

Yara rules compiler

Implementations

impl Compiler[src]

pub fn new() -> Result<Self, YaraError>[src]

Create a new compiler.

pub fn add_rules_file<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>[src]

Add rules definitions from a file.

Example

let mut compiler = Compiler::new()?;
compiler.add_rules_file("rules.txt")?;

pub fn add_rules_file_with_namespace<P: AsRef<Path>>(
    &mut self,
    path: P,
    namespace: &str
) -> Result<(), Error>
[src]

Add rule definitions from a file within a namespace.

Example

let mut compiler = Compiler::new().unwrap();
let rules = compiler.add_rules_file_with_namespace("CVE-2010-1297.yar", "flash")?;

pub fn add_rules_str(&mut self, rule: &str) -> Result<(), Error>[src]

Add rule definitions from a string.

Example

let mut compiler = Compiler::new()?;
let rules = compiler.add_rules_str("rule is_empty {
  condition:
    filesize == 0
}")?;

pub fn add_rules_str_with_namespace(
    &mut self,
    rule: &str,
    namespace: &str
) -> Result<(), Error>
[src]

Add rule definition from a string within a namespace.

Example

let mut compiler = Compiler::new()?;
compiler.add_rules_str_with_namespace("rule is_empty {
  condition:
    filesize == 0
}", "misc")?;

pub fn compile_rules(self) -> Result<Rules, YaraError>[src]

Compile the rules.

Consume the compiler.

Implementation notes

It is safe to destroy the compiler after, because the rules do not depends on the compiler. In addition, we must hide the compiler from the user because it can be used only once.

pub fn define_variable<V: CompilerVariableValue>(
    &mut self,
    identifier: &str,
    value: V
) -> Result<(), YaraError>
[src]

Add a variable to the compiler.

Valid types are bool, i64, f64, str and cstr.

Note: You must define all the external variables before adding rules to compile.

Example

let mut compiler = Compiler::new().unwrap();
// Add the variables
compiler.define_variable("file_name", "thing.txt")?;
compiler.define_variable("answer", 42)?;
compiler.define_variable("pi", 3.14)?;
compiler.define_variable("is_a_test", true)?;
// Use them in rules
compiler.add_rules_str(r#"
rule TestExternalVariables {
  condition:
    file_name == "thing.txt"
        and answer == 42
        and pi == 3.14
        and is_a_test
}
"#)?;

Trait Implementations

impl Drop for Compiler[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.