40 releases (breaking)

0.29.0 Sep 26, 2024
0.28.0 Jun 3, 2024
0.27.0 May 6, 2024
0.26.0 Feb 16, 2024
0.1.0 May 30, 2018

#35 in FFI

Download history 140/week @ 2024-08-23 385/week @ 2024-08-30 251/week @ 2024-09-06 104/week @ 2024-09-13 335/week @ 2024-09-20 188/week @ 2024-09-27 311/week @ 2024-10-04 179/week @ 2024-10-11 223/week @ 2024-10-18 28/week @ 2024-10-25 38/week @ 2024-11-01 32/week @ 2024-11-08 179/week @ 2024-11-15 137/week @ 2024-11-22 159/week @ 2024-11-29 263/week @ 2024-12-06

748 downloads per month
Used in 5 crates

MIT/Apache

4MB
103K SLoC

C 57K SLoC // 0.1% comments Rust 37K SLoC // 0.0% comments Happy 3K SLoC Visual Studio Project 2K SLoC Lex 1.5K SLoC // 0.1% comments C++ 784 SLoC // 0.3% comments Bazel 697 SLoC // 0.3% comments Automake 316 SLoC // 0.1% comments Batch 211 SLoC Visual Studio Solution 191 SLoC M4 190 SLoC // 0.4% comments JavaScript 84 SLoC // 0.0% comments RPM Specfile 84 SLoC // 0.1% comments NuGet Config 47 SLoC Python 34 SLoC // 0.8% comments Snakemake 8 SLoC Shell 3 SLoC Bitbake 1 SLoC

yara-rust

Tests Status Crates.io Documentation

Bindings for the Yara library from VirusTotal.

More documentation can be found on the Yara's documentation.

Example

The implementation is inspired from yara-python.

const RULES: &str = r#"
    rule contains_rust {
      strings:
        $rust = "rust" nocase
      condition:
        $rust
    }
"#;

fn main() {
    let compiler = Compiler::new().unwrap();
    let compiler = compiler
        .add_rules_str(RULES)
        .expect("Should have parsed rule");
    let rules = compiler
        .compile_rules()
        .expect("Should have compiled rules");
    let results = rules
        .scan_mem("I love Rust!".as_bytes(), 5)
        .expect("Should have scanned");
    assert!(results.iter().any(|r| r.identifier == "contains_rust"));
}

Features

  • Support from Yara v4.2.
  • Compile rules from strings or files.
  • Save and load compiled rules.
  • Scan byte arrays (&[u8]) or files.

Feature flags and Yara linking.

Look at the yara-sys crate documentation for a list of feature flags and how to link to your Yara crate.

TODO

  • Remove some unwrap on string conversions (currently this crate assume the rules, meta and namespace identifier are valid Rust's str).
  • Accept AsRef<Path> instead of &str on multiple functions.
  • Implement the scanner API.
  • Add process scanning.
  • Report the warnings to the user.

License

Licensed under either of

at your option.

Contributing

Please follow the conventional commit rules when committing to this repository.

If you add any new feature, add the corresponding unit/doc tests.

Dependencies