YARA-X: install, yr CLI and YARA differences
YARA-X is VirusTotal's Rust rewrite of YARA. Install it (binaries, brew, cargo, pip), use the yr CLI and Python API, and migrate rules: compatibility, differences, checklist.
YARA-X is the successor of YARA, rewritten in Rust by VirusTotal. It reads the same rule language, so switching is usually painless, but it is deliberately stricter in places where YARA 4.x was lenient, and its CLI and library APIs are new. This guide covers what YARA-X is, how to install and run it, and how to migrate a rule set.
What is YARA-X
YARA was created at VirusTotal and became the standard language for describing malware files. After more than a decade of C code, VirusTotal started YARA-X as a new implementation with three goals: better error reporting, better performance on complex rule sets, and a safer codebase. YARA-X is used in production at VirusTotal (Livehunt and Retrohunt), and YARA 4.x now mainly receives maintenance.
What changes for you:
- Same rules.
meta,strings,condition, modifiers, loops and the common modules work as before. See compatibility below. - A new CLI. The executable is
yr, with subcommands (yr scan,yr compile,yr dump,yr fmt…) instead of the separateyaraandyaracprograms. - New APIs. The Rust, Python, Go and C APIs are not drop-in replacements for the YARA ones. They are conceptually similar (compile, then scan), but code that imports
yaramust be adapted toyara_x. - No process scanning. YARA-X scans files and buffers, not the memory of running processes. Keep YARA 4.x if you rely on
yara rules.yar <pid>.
Install YARA-X
| Method | Command | Notes |
|---|---|---|
| Pre-built binaries | download from GitHub releases | Archives for Linux (x86_64, aarch64), macOS (x86_64, Apple silicon) and Windows; extract and put yr on your PATH |
| Homebrew (macOS) | brew install yara-x | Installs the yr CLI |
| Cargo (any OS with Rust) | cargo install yara-x-cli | Builds yr from the yara-x-cli crate; needs a recent Rust toolchain |
| From source | git clone https://github.com/VirusTotal/yara-x && cd yara-x && cargo install --path cli | Latest unreleased code |
| Python | pip install yara-x | Python 3.9 or later; import it as yara_x |
Check the installation with yr --version. The PyPI wheels include every default module except magic, which needs libmagic; the Python documentation explains how to build with --features=magic-module if you need it.
The yr command line
yr help lists the subcommands; yr <command> --help documents each one.
# Scan a file, or a directory (add -r to recurse), printing matched strings and metadata
yr scan -s -m rules.yar sample.exe
yr scan -r rules/ /mnt/evidence/
# Machine-readable output, one JSON object per file that matched at least one rule
yr scan --output-format ndjson rules.yar /bin | jq .path
# Namespaces keep identical rule names from different sets apart
yr scan forge:yara-rules-core.yar mine:my-rules/ sample.bin
# Compile once, scan many times
yr compile -o rules.yrc rules/
yr scan -C rules.yrc sample.bin
# Show what the pe, elf, macho, dotnet and lnk modules see in a file
yr dump -m pe sample.exe
# Format rules in place, or only verify formatting in CI (exit code 1 if a file would change)
yr fmt rules/
yr fmt --check rules/
yr check rules/ reports syntax errors without scanning. It works but is hidden from yr help because upstream still considers it unfinished; yr compile is the authoritative test that a rule set builds. Useful scan options for incident work are --timeout, --skip-larger <bytes>, --threads and --tag <TAG> (only rules with that tag).
Python API in 10 lines
import yara_x
compiler = yara_x.Compiler()
compiler.new_namespace("forge")
compiler.add_source(open("yara-rules-core.yar").read())
rules = compiler.build()
scanner = yara_x.Scanner(rules)
scanner.set_timeout(60)
results = scanner.scan_file("sample.bin")
for rule in results.matching_rules:
print(rule.namespace, rule.identifier, dict(rule.metadata).get("author"))
for pattern in rule.patterns:
for match in pattern.matches:
print(f" {pattern.identifier} at {match.offset:#x} ({match.length} bytes)")
For a single rule string, yara_x.compile(source).scan(data) is enough. results.module_outputs returns what each module produced (the same data as yr dump), which is handy for building new conditions. If you are porting a yara-python script, the main changes are the module name, the Compiler/Scanner objects and the match objects (matching_rules, patterns, matches).
Compatibility
The rule language is the same: meta, strings, condition, text/hex/regex patterns, modifiers, quantifiers, loops and the common modules. Across the thousands of rules in this library, the vast majority compile with YARA-X 1.20 without any change — each rule page shows its status, and the scanner packs only include rules that compile.
Notable differences
- Stricter parsing. Invalid escape sequences in strings and regexes, invalid or duplicated modifiers, and some ambiguous constructs are errors instead of being silently accepted.
- Clearer errors. Every diagnostic has a code, a message and the exact line and column, with the offending source excerpt. The online editor shows them as you type.
- Unknown module fields are errors. Misspelled
pe.fields fail at compile time instead of evaluating to undefined at scan time. - base64 modifier. The pattern must be at least three bytes long.
- Performance. Better behaviour with complex regular expressions and large rule sets; compile-time warnings about patterns likely to be slow.
- New syntax. The
withstatement defines local variables inside a condition (see conditions). Rules that use it do not compile with YARA 4. - Modules. Most module names and fields are shared; some were reorganised, new ones were added (for example
lnk,dex,crx), andmagicis missing from builds without libmagic, such as the WebAssembly build. - Includes and deprecated features.
includehandling depends on the front-end, and a few long-deprecated features were dropped.
Command-line comparison
| Task | YARA 4.x | YARA-X |
|---|---|---|
| Scan a file or directory | yara rules.yar target | yr scan rules.yar target |
| Check syntax | yarac rules.yar out.bin | yr check rules.yar (hidden) or yr compile |
| Compile to a binary | yarac | yr compile |
| Format a rule | — | yr fmt rules.yar |
| Show module output | yara -D | yr dump file / yr dump -m pe file |
| Print matched strings | yara -s | yr scan -s |
Migration checklist
- Run
yr checkon the whole rule set and fix errors file by file. The error codes are stable, so you can grep for them. - Fix invalid escapes: in text strings only
\" \\ \t \n \r \xNNare valid; in regexes, escape/and avoid escaping ordinary letters. - Remove conflicting modifiers (for example
nocasewithxor, orbase64withfullword). - Replace deprecated identifiers such as
entrypointwithpe.entry_pointorelf.entry_point. - Re-check module field names with
yr dump -m <module> sample. - Re-run your positive samples and goodware corpus (see testing and CI) — matches should be identical.
- Review new compile-time performance warnings; the performance guide explains most of them.
A rule that needs to compile with both engines should avoid with and other YARA-X-only syntax.
A rule that shows the stricter parsing
rule Escape_Example
{
strings:
$ok = "C:\\Windows\\Temp\\"
$bad = "C:\Windows\Temp" // does not compile: \W and \T are not valid escapes
condition:
any of them
}
YARA-X rejects $bad and points at the exact column; the fix is to double each backslash, as in $ok.
Try YARA-X in your browser
YARA-X compiles to WebAssembly. The tools on this site use the official @virustotal/yara-x build (version 1.20.0, BSD-3-Clause), loaded from this site and run in a Web Worker:
- The scanner scans files and ZIP archives with library packs or your own rules.
- The editor compiles as you type and tests against a dropped sample.
- The linter adds performance heuristics to YARA-X diagnostics.
Nothing is uploaded: files are read with the browser File API and scanned in memory. See the official YARA-X documentation for the complete language reference.
FAQ
- What is YARA-X?
- YARA-X is a rewrite of YARA in Rust by VirusTotal. It reads the same rule language, adds better error messages, a new CLI called yr and new modules, and is where new YARA development happens.
- How do I install YARA-X?
- Download a pre-built binary from the GitHub releases page (Linux, macOS, Windows), run brew install yara-x on macOS, or build the CLI with cargo install yara-x-cli. The Python module is pip install yara-x.
- Will my existing YARA rules work with YARA-X?
- Most will compile unchanged. Rules that relied on lenient parsing — invalid escapes, questionable regexes, duplicate or conflicting modifiers — need small fixes that YARA-X points out with precise error messages.
- Is YARA still maintained?
- YARA 4.x still receives maintenance, but new development happens in YARA-X, which VirusTotal uses in production.
- Can YARA-X scan process memory?
- No. Process scanning is not implemented in YARA-X; keep YARA 4.x for live memory scans of running processes.
- Can YARA-X run in a browser?
- Yes. YARA-X compiles to WebAssembly. The scanner, editor and linter on this site run it in a Web Worker, so files are scanned locally.