architect exporters
Build byte patterns from a reference range and a static mask.
- class PatternGenerator[source]
Bases:
objectGenerate wildcard byte patterns from a region and its static mask.
Static bytes become exact match values; volatile bytes become wildcards (??). The result can be exported as YARA or JSON.
- static generate(reference_bytes, static_mask, name='unnamed_pattern', min_static_ratio=0.3)[source]
Return a byte pattern and its static-byte counts.
Supply one mask value per reference byte. A true value keeps the byte literal in
wildcard_pattern. A false value writes??. The returnedhex_patterncontains all reference bytes. Empty inputs or a static ratio below min_static_ratio returnNone.
- static find_anchors(static_mask, min_anchor_length=4)[source]
Find contiguous runs of static bytes that can serve as anchors.
- static anchor_distinctiveness(reference_bytes, static_mask, min_anchor_length=4)[source]
Measure the byte diversity of a pattern’s static anchors.
min_static_ratioingenerate()answers “is there enough static material to build a rule from?”. It cannot answer the question that decides whether the rule is useful: “do those static bytes say anything?” A window whose anchors are 128 zero bytes passes any static ratio and then matches thousands of positions in the same dump it came from.This is not hypothetical. On the real 8-dump OpenSSL TLS 1.2 corpus the 48-byte master secret at offset 370,672 sits inside a run of zeros: at the default 64 bytes of context the resulting mask has 128 static bytes carrying exactly ONE distinct value, and that rule fires 825,779 times in its own 11 MB source dump under libyara – or 5,311 times under Volatility3’s
RegExScanner, which walks with non-overlappingre.finditerand so reports one hit per ~176-byte stride (tests/test_vol3_verify.pypins the 5,311 for that engine;tests/test_detector_loop_corpus.pypins the 825,779 for this one). Both numbers describe the SAME rule on the SAME dump, 155x apart: a selectivity figure is meaningless without naming the engine that produced it, so a caller should measure its own rule –memdiver scan-yara --count-only --no-max-matches– rather than reuse either.Only bytes inside a static RUN of at least min_anchor_length count — the same anchors
find_anchors()reports, because a lone static byte between two wildcards anchors nothing.- Returns:
distinct_bytes(how many different values the anchors carry),shannon_bits(their per-byte Shannon entropy, 0.0 for a single repeated value),longest_constant_run(the longest run of ONE repeated value within a single anchor — never spanning two anchors, which are not adjacent in the matched bytes) andstatic_bytes(how many bytes were measured). All zero when there are no anchors.- Parameters:
- Return type:
- static infer_fields(variance, key_offset, key_length, threshold=2000.0)[source]
Segment variance into structural fields and dynamic regions.
Group consecutive bytes with variance at or below threshold as static. Group bytes above the threshold as dynamic. The known key region is labeled
key_materialregardless of individual byte variance.
Export byte patterns as YARA rules.
- class YaraExporter[source]
Bases:
objectExport byte patterns as YARA detection rules.
- static export(pattern, rule_name=None, description=None, tags=None, key_offset=None, key_length=None)[source]
Export the byte pattern as a YARA rule.
Supply hex byte pairs and
??wildcards inwildcard_pattern. An invalid token raisesValueError. An all-wildcard pattern logs a warning and still produces a rule.The exporter sanitizes the rule name and tags, escapes the description, and converts numeric metadata to YARA integers. A missing or nonpositive pattern length omits
pattern_length. Supplykey_offsetrelative to the pattern start andkey_lengthas a byte count to include those metadata fields.The exporter returns rule text. The caller can compile it to check limits that depend on the installed YARA version.
- key_locator_from_pattern(pattern)[source]
Read the key locator a pattern dict may already carry.
engine.vol3_emitenriches the dict produced byPatternGenerator.generate()withkey_offset(relative to the pattern window start, exactly asYaraExporter.export()wants it) andkey_length. Callers that hold only such a dict – the HTTP/architect/exportendpoint andVolatility3Exporter.export()’s own YARA fallback – recover the locator here rather than re-deriving or inventing it.A missing,
None, or non-integral value yieldsNoneso the meta line is omitted instead of emitted wrong: the dict can arrive verbatim from an HTTP request body, where any JSON value is possible.
Export byte patterns as JSON signature files.
- class JsonExporter[source]
Bases:
objectExport byte patterns as JSON signatures compatible with pattern_loader.
- static export(pattern, library='', tls_version='', description='', structural_rules=None)[source]
Build a signature dictionary from the pattern and optional rules.
Use library and TLS version values to constrain applicability. The before and after rules go in the signature’s pattern fields. Record the wildcard string and static-byte ratio as metadata.
Generate v1 Volatility 3 plugins from byte patterns and artifact models.
DEPRECATED (v1 generator): pattern plugins are now recipe-v2 plugins
(architect.vol3_recipe.recipe_from_pattern + render). Kept for artifact-model
STRUCTURE plugins (app.tools_semantic), which v2 cannot express yet, and for the
explicit emit_plugin_for_hit(template="v1"). The public entry points emit a
DeprecationWarning so remaining callers surface.
- class Volatility3Exporter[source]
Bases:
objectExport byte patterns as self-contained Volatility3 Python plugins.
- static export(pattern, plugin_name=None, description=None, yara_rule=None)[source]
Export a pattern dict as a Volatility3 plugin Python source.
- Parameters:
pattern (dict) – Pattern dict from PatternGenerator.generate(), optionally enriched with key_offset, key_length, and vtypes by
vol3_emit.plugin_name (str | None) – Plugin class name. Defaults to
MemDiverScanfollowed by the normalized pattern name.description (str | None) – Human-readable description.
yara_rule (str | None) – Pre-built YARA rule string. Generated if not provided, in which case the pattern’s own
key_offset/key_length(when present) become YARA metas on the generated rule.
- Returns:
Complete Python source code for a Volatility3 plugin.
- Return type:
- static export_model(model, plugin_name=None, description=None)[source]
Export an artifact model as a Volatility3 plugin Python source.
byte_patternmodels go throughexport()unchanged. Astructuremodel becomes a plugin that decodes the model’s fields around each prefilter hit (see_STRUCTURE_TEMPLATE). An inconsistent model raisesValueErrorlisting every problem.