YARA rules
ClamAV loads .yar/.yara rules by default, and so does exav: rule files load
alongside ClamAV signatures and match in the same scan.
Using YARA rules
Section titled “Using YARA rules”Put rule files in your signature directory; they load recursively with everything else:
exav -d ./sigs /data # sigs/ contains .cvd, .ndb, and .yar filesA YARA detection is reported like any other:
sample.bin: YARA.SomeRuleName FOUNDUnder --clamav-compat, YARA detections carry the .UNOFFICIAL suffix
(YARA.SomeRuleName.UNOFFICIAL), as clamscan names them: the official .cvd
files ship no YARA rules.
YARA support is behind the default-on yara feature. A build without it still
loads rule files but warns that they will never match. --no-default-features
drops every other default feature too; see
Feature flags.
The native engine
Section titled “The native engine”exav uses YARA-X’s parser crate
(yara-x-parser) and replaces its WASM
back end with a native tree-walking evaluator:
- No wasmtime, no Cranelift, no
rsa, and no code generation at scan time. Depending onyara-xas a library pulls in a large WebAssembly runtime for its back end; the native engine links none of it. - YARA-X is BSD-3-Clause, compatible with exav’s MIT license, and exav reuses and adapts its source and test vectors under it, with attribution. (exav derives nothing from ClamAV’s code, which is GPL.)
Feature coverage
Section titled “Feature coverage”Supported: text, hex and regexp strings with all modifiers (nocase,
ascii, wide, fullword, xor, base64, base64wide, private); full
condition logic (boolean, of, counts, offsets, lengths, anchors, arithmetic,
bitwise, float, comparisons, string operators, matches); for … in,
for … of, with; integer reads (uint/int 8/16/32 and _be); filesize;
entrypoint; rule references; global and private rules; and the pe, math,
hash, string, time, elf and dotnet modules.
External variables: filepath, filename and extension (lowercased, with its
leading dot) are set from the scanned file’s path, and undefined when there is
none. filetype and owner are declared, so rules using them compile, but they
are never set and those conditions never match.
Not supported, and rejected as explicit compile errors rather than evaluated
wrongly: the macho, dex, cuckoo, androguard and other modules; include;
floatN() reads; a bare regular expression used as a condition; and a few
fields of the implemented modules (pe.rich_signature, pe.version_info,
resources, pe.signatures, dotnet.classes).
Limits
Section titled “Limits”A file larger than --max-object-bytes is scanned through a block cache.
Rules that use the pe, elf or dotnet modules read the image of the file
(a PE’s headers and sections, an ELF’s tables and contents), so only a file
whose image is past --max-object-bytes cannot run them: it is reported
LIMITS-EXCEEDED unless something is found. The same verdict comes
from a pattern with more than a million matches and from a rule set that runs
out of evaluation steps. A pattern a rule uses at one offset only ($a at 0)
is looked for there alone, as yara-x does, so its matches elsewhere do not
count. See Limits and tuning.
How matching is verified
Section titled “How matching is verified”The set of matching rules is compared with the real yara-x over varied inputs
(see Differential testing). The
harness runs yara-x as a program (yr) instead of linking it, which would bring
its WebAssembly runtime into exav’s build. Install it with
cargo install yara-x-cli and run make test-yara-diff. Without yr the
harness skips, so read its output rather than only its exit code.
Using the engine directly
Section titled “Using the engine directly”The engine is exav_core::yara, usable as a standalone YARA library:
use exav_core::yara::{Compiler, Scanner as YaraScanner};
fn demo() -> exav_core::yara::Result<bool> { let mut c = Compiler::new(); c.add_source(r#"rule demo { strings: $a = "evil" condition: $a }"#)?; let rules = c.build(); let mut scanner = YaraScanner::new(&rules); let hit = scanner.scan(b"...evil...")?.matching_rules().next().is_some(); Ok(hit)}add_source fails on the first unsupported rule. add_source_lenient compiles
each rule on its own and returns the rejected ones, as a scan’s database load
does. See exav-core for the rest of the library’s
API.
- Signatures: where rule files go and the other formats.
- Prebuilt database: compile rules once with the rest of the database.