Skip to content

YARA compatibility and differences

Docs for v0.11.1 · Go 1.27.0+ · Go API

go-yara implements YARA parsing, compilation, and scanning in Go. Compatibility depends on the rule features and modules you use. Compile your own corpus and compare expected outcomes before replacing libyara.

go-yara provides an engine that can be embedded directly in a Go program without a native library. libyara and YARA-X provide other integration paths and a broader set of bundled file-format modules. Which fits an application depends on its rules, deployment constraints, and required output.

This comparison uses go-yara v0.11.0, libyara 4.6.0 / 4.5.8, and YARA-X 1.23.0 / 1.22.0, with sources and CLI measurements reviewed on 2026-11-19.

Area go-yara libyara YARA-X
Implementation and integration Pure Go library; zero CGO, static binaries, and native Go cross-compilation. C library with a C API; Go callers require CGO or an external wrapper. Rust engine with C and Go APIs; the official Go binding wraps the native library via CGO.
Condition execution Go bytecode interpreter with fused assertions, assertionProgram dataflow, and proximity two-pointer joins. Stack-based C bytecode interpreter. Compiles rule conditions to WebAssembly (executed via Wasmtime in native builds).
Pattern searching Shared Aho–Corasick (byte-class tables), entropy-weighted atom selection, optional GOEXPERIMENT=simd Teddy/bounded-class kernels, and specialized hex/regex verifiers. Aho–Corasick atom searches followed by pattern verification. Aho–Corasick candidate searches with specialized pattern and regex machinery.
Bundled modules hash, math, string, time, and pure-Go pe (v0.10.0+, pe.overlay.* in v0.11.0); typed Go host modules and callbacks. Native elf, cuckoo, and dotnet parsers are not bundled. Includes pe, elf, dotnet, cuckoo, and other analysis modules depending on build flags. Includes pe, elf, dotnet, and other analysis modules depending on build features.
Rule and API compatibility Supports standard YARA rules plus Go-oriented extensions (capture(...)/evidence:, external, float min/max, hash.sha512); WithStrictLibyaraCompatibility(true) enforces libyara compile-time rejections. Reference behavior for the project’s libyara differential tests. Targets YARA rule compatibility with documented syntax/regex differences and newer Rust APIs.
  • Choose go-yara when you need a pure-Go dependency (no CGO, static cross-compiled binaries, Wasm playground builds), direct Go host-module callbacks and zero-reflection WithBorrowedEvidence(true) JSON streaming, deterministic binary rule caches (MarshalBinary), or WithStrictLibyaraCompatibility(true) without shipping libyara shared libraries.
  • Choose libyara when you need maximum legacy rule/module parity (elf, dotnet, cuckoo, full delayed-import/Authenticode valid_on surface) or existing C/Python tooling already built around libyara.
  • Choose YARA-X when you want VirusTotal’s next-generation Rust engine with bundled elf/dotnet parsers, WebAssembly-compiled conditions, and strict/modernized YARA-X rule diagnostics, and CGO/Rust native libraries fit your deployment model.

Measured CLI comparison (clean prefilter vs dense-root vs heavy regex)

Section titled “Measured CLI comparison (clean prefilter vs dense-root vs heavy regex)”

Measured on Apple M3 Max (-p 4, median of 3 CLI runs via /usr/bin/time -l). To separate steady-state scanning from compilation, libyara and YARA-X use pre-compiled rule binaries (-C) in the dense-root and heavy-regex workloads, and scan throughput is computed from (workload_wall - 1KB_baseline_wall):

Workload go-yara v0.11.1 (scalar / SIMD) libyara 4.6.0 YARA-X 1.23.0
Compile 2,000 rules (1 KB, -p 1, source) 31.6 ms (37.3 MiB) / 31.3 ms (37.3 MiB) 25.5 ms (12.5 MiB) 151.7 ms (37.2 MiB)
512 MB clean, 2,000 distinct-prefix rules (-p 4, source) 23.8 GB/s (167 MiB) / 25.0 GB/s (168 MiB) 2.1 GB/s (141 MiB) 2.6 GB/s (165 MiB)
256 MB dense-root, 2,000 overlapping rules (nocase/wide/fullword, -p 4, -C for C/Rust) 144 MB/s (307 MiB) / 145 MB/s (305 MiB) 92 MB/s (84.3 MiB) 221 MB/s (155 MiB)
100 MB heavy regex (Bitcoin + JWT, -p 4, -C for C/Rust) 113 MB/s (126 MiB) / 107 MB/s (125 MiB) 59 MB/s (64.4 MiB) 91 MB/s (81.8 MiB)

Honest takeaways:

  • go-yara wins on high-selectivity prefiltering, heavy fullword regexes, and zero-CGO Go integration: When rules have distinct 3+ byte prefixes and clean traffic dominates, sparse/byte-class Aho–Corasick and Teddy prefiltering reach 24–25 GB/s (~9–12× faster than libyara/YARA-X on that workload). With the pre-VM fullword guard (#619), go-yara also leads on the 100 MB Bitcoin/JWT regex stress test (107–113 MB/s vs 91 MB/s YARA-X and 59 MB/s libyara).
  • YARA-X wins on dense-root overlapping rules: When short/common prefixes (http://, MZ) trigger frequent verification across hundreds of rules, YARA-X (221 MB/s, 155 MiB RSS) remains ~1.5× faster than go-yara (144–145 MB/s, 305–307 MiB RSS, improved from 28 MB/s / 1.82 GiB in v0.11.0 via #618/#620/#622). Compiling from source without -C is slower in YARA-X (151.7 ms vs 31 ms), so pre-compile in CLI pipelines.
  • libyara wins on peak memory footprint: Across dense-root (84.3 MiB), heavy-regex (64.4 MiB), and cold-compile (12.5 MiB) runs, libyara 4.6.0 uses the least RAM while compiling 2,000 rules in 25.5 ms.

The matching architecture has substantial overlap. Atom selection, verification strategy, condition execution, and result handling can each affect performance. go-yara’s lack of a native dependency is a deployment property; it does not establish a scanning-speed advantage. The performance page explains its algorithms, measurements, and benchmark conditions.

For rules that depend on bundled ELF or .NET analysis, libyara and YARA-X already provide those parsers; native PE rules can use go-yara’s pure-Go pe module starting in v0.10.0 within its documented directory limits. Exposing other application-parsed data through a go-yara host module requires an adapter and compatible field semantics. Similarly, a rule accepted by one engine may need changes in another: YARA-X documents differences in regex escapes, base64 patterns, modifiers, and other constructs, while go-yara’s differences are listed below.

Sources: libyara’s atom selection, Aho–Corasick implementation, condition interpreter, and modules; YARA-X’s compiler, scanner, Wasm runtime, Go binding, and modules. The upstream API comparison and language differences provide migration details.

Rules can use text strings, hex patterns with wildcards and jumps, regular expressions, string counts and offsets, condition operators, and rule references. The built-in scalar/range modules are hash, math, string, and time; their function signatures are generated from the documented release. Starting in v0.10.0, go-yara also bundles a pure-Go pe module backed by go-pe (headers, sections, standard imports/exports and regex queries, imphash, resources, version_info, Rich headers, pdb_path, Authenticode metadata and offline integrity verification, declared_extent/input_truncated, is_dotnet(), and pe.overlay.data_offset/data_size/certificate_size in v0.11.0; see PE module coverage).

Native elf, cuckoo, and dotnet parsers are not bundled, and delayed PE imports, flagged import queries, single-argument/mixed regex pe.imports, signatures[i].valid_on(timestamp), and signatures[i].file_digest remain unsupported. A structured host module can expose data supplied by your application, but it does not supply those parsers or make an existing native module interchangeable.

This input puts the same bytes under three kinds of rules. The text rule requires two whole-word occurrences ignoring case; the hex rule requires a fixed three-byte gap after MZ; the regex rule requires a two-digit ID in a specific range.

Byte offsets Input bytes Used by
0–1 MZ Hex pattern and little-endian uint16(0)
2–4 Two zero bytes and a space Hex jump [3]
5–9 hello First text occurrence and hex suffix
10 Space Word boundary
11–15 HELLO Second text occurrence, @word[2] == 11
16 Space Separator
17–21 id=42 Regex occurrence in the selected range
Complete Go example: compare text, hex, and regex conditions
main.go
package main
import (
"context"
"fmt"
"log"
"github.com/cawalch/go-yara/compiler"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
program, err := compiler.NewCompiler().CompileSourceWithContext(context.Background(), `
rule text_count {
strings: $word = "hello" nocase fullword
condition: #word == 2 and @word[2] == 11
}
rule hex_header {
strings: $header = { 4D 5A [3] 68 65 6C 6C 6F }
condition: $header at 0
}
rule numeric_id {
strings: $id = /id=[0-9]{2}/
condition: uint16(0) == 0x5a4d and $id in (17..21)
}`)
if err != nil {
return err
}
for _, sample := range []struct{ name, input string }{
{"numeric", "MZ\x00\x00 hello HELLO id=42"},
{"letters", "MZ\x00\x00 hello HELLO id=ab"},
} {
result, err := program.Scan([]byte(sample.input))
if err != nil {
return err
}
fmt.Printf("%s: text=%t hex=%t regex=%t\n", sample.name,
result.RuleResults["text_count"], result.RuleResults["hex_header"], result.RuleResults["numeric_id"])
}
return nil
}
Output
numeric: text=true hex=true regex=true
letters: text=true hex=true regex=false

#word counts occurrences, while @word[2] selects the second occurrence using a one-based index. Offsets are zero-based byte positions. The second input replaces the digits with letters: the text and hex rules still match, but the regex rule fails. The hex jump [3] requires exactly three intervening bytes; it is not a match-count expression.

Operation Behavior
Integer math.min and math.max Compare integers as unsigned values, matching YARA.
Float or mixed numeric min and max A go-yara extension: returns a float and uses signed numeric ordering.
string.to_int without a base Autodetects decimal, octal, and hexadecimal consistently across platforms. "0b10" is undefined; use string.to_int("10", 2).
String ordering (<, <=, >, >=) Compares strings lexicographically by unsigned byte value. For example, "\xff" > "a". Native libyara can order high bytes differently when C char is signed.
String statistics on high bytes Treats bytes as signed characters. Native results can differ where C char is unsigned.
Range statistics Treats bytes as unsigned values.
Invalid ranges or conversions Produces YARA’s undefined value. A valid range beginning inside the input is truncated at EOF.

For min and max, untyped external arguments retain the declared integer result contract unless a float argument is statically known. Use a float literal or a typed module field to select a float overload.

Native string.to_int behavior for a binary prefix can vary with the host C library and build. A native result on one machine is not a portable rule contract.

The current source checkout aligns icontains, iequals, istartswith, and iendswith with libyara’s byte comparisons. They fold ASCII letters and compare every other byte exactly, including embedded NULs. This correction is unreleased. Recompile rules whose cached conditions were folded from string literals to apply it.

hash.sha512 and float overloads of math.min and math.max extend the libyara 4.5.x function set. The two-argument math.deviation(offset, size) computes standard deviation. YARA-compatible mean absolute deviation uses math.deviation(offset, size, mean) or math.deviation(string, mean), with a floating-point mean.

Structured host modules, the external declaration syntax, and evidence extraction also need review when moving rules between engines. The capture(...) modifier and evidence: section add extraction behavior; other YARA implementations may reject that syntax.

The CLI’s --streaming mode reports literal text-pattern matches without complete condition evaluation. ScanReader and MatchesReader evaluate full rule conditions, regex, and hex patterns using bounded input windows. Retained occurrences and result data can grow with matches. Sparse block scanning retains supplied blocks.

Serialized go-yara programs use a project-specific format. They are not libyara compiled-rule files. Check the upgrade rules before sharing caches between versions, including the v0.10.0 format-20 migration. Use WithStrictLibyaraCompatibility(true) (v0.10.0+) when your pipeline requires libyara compile-time rejections for unreferenced strings or empty wildcard string sets.

Compile the full rule set and investigate every rejected rule. Compare matched rule names on known positive and negative inputs, then check counts, offsets, undefined values, and module calls that your rules depend on. Include truncated and malformed files as well as ordinary samples.

If you find a difference, report a minimal rule, the input bytes or a small reproducer, both engine versions, and the observed results in a GitHub issue.