[−][src]Struct yara::Compiler
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]
&mut self,
path: P,
namespace: &str
) -> Result<(), Error>
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]
&mut self,
rule: &str,
namespace: &str
) -> Result<(), Error>
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]
&mut self,
identifier: &str,
value: V
) -> Result<(), YaraError>
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
Auto Trait Implementations
impl RefUnwindSafe for Compiler
[src]
impl !Send for Compiler
[src]
impl !Sync for Compiler
[src]
impl Unpin for Compiler
[src]
impl UnwindSafe for Compiler
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,