Skip to main content

syara_x/
lib.rs

1/*!
2SYARA-X — Super YARA in Rust.
3
4Extends the YARA rule format with semantic, ML-classifier, and LLM-based matching.
5
6# Example
7
8```rust
9use syara_x;
10
11let rules = syara_x::compile_str(r#"
12    rule test_rule {
13        strings:
14            $s1 = "hello world" nocase
15        condition:
16            $s1
17    }
18"#).unwrap();
19
20let matches = rules.scan("Hello World");
21assert_eq!(matches.iter().filter(|m| m.matched).count(), 1);
22```
23*/
24
25pub(crate) mod cache;
26pub mod compiled_rules;
27pub(crate) mod compiler;
28pub(crate) mod condition;
29pub(crate) mod config;
30pub mod engine;
31pub mod error;
32pub mod models;
33pub(crate) mod parser;
34
35pub use compiled_rules::CompiledRules;
36pub use error::SyaraError;
37pub use models::{Match, MatchDetail, Rule};
38
39use std::path::Path;
40
41/// Compile rules from a `.syara` file.
42pub fn compile(path: impl AsRef<Path>) -> Result<CompiledRules, SyaraError> {
43    let rules = parser::SyaraParser::new().parse_file(path)?;
44    let registry = config::Registry::new();
45    compiler::Compiler::compile(rules, registry)
46}
47
48/// Compile rules from a string.
49pub fn compile_str(src: &str) -> Result<CompiledRules, SyaraError> {
50    let rules = parser::SyaraParser::new().parse_str(src)?;
51    let registry = config::Registry::new();
52    compiler::Compiler::compile(rules, registry)
53}