Skip to content

WEVT Support#274

Merged
omerbenamram merged 17 commits intomasterfrom
wevt-template-extract
Dec 26, 2025
Merged

WEVT Support#274
omerbenamram merged 17 commits intomasterfrom
wevt-template-extract

Conversation

@omerbenamram
Copy link
Owner

@omerbenamram omerbenamram commented Dec 23, 2025

Closes #103

Motivation

Issue #103 is about offline / carved EVTX analysis: records frequently reference template instances (substitution values), but the corresponding template definitions live in provider PE resources (WEVT_TEMPLATE). Without those templates, you can parse the record BinXML but you can’t reliably render the final event fragment.

This PR makes template extraction + spec-backed parsing a first-class, cross-platform workflow in evtx_dump, so you can:

  • extract templates from provider binaries into a cache
  • extract a record’s TemplateInstance substitution array
  • render the final XML event fragment offline

What’s implemented

  • Module organization: evtx::wevt_templates is split into focused modules (extract, manifest, binxml, render, temp) with stable re-exports (public API paths remain the same).
  • Spec-backed CRIM/WEVT parsing: deterministic parsing with strict bounds checks and actionable errors; exposes stable join keys (provider/event → template GUID/offset).
  • WEVT inline-name BinXML support: the deserializer supports the inline-name dialect used in templates, enabling deterministic rendering.
  • evtx_dump workflow commands:
    • extract-wevt-templates: build the cache/index (including provider/event → template GUID join rows)
    • dump-template-instances: dump per-record substitution arrays (JSONL)
    • apply-wevt-cache: render template + substitutions to XML (substitutions from EVTX record or JSON)
  • Docs: a concise end-to-end flow in the README + deeper technical notes in docs/wevt_templates.md.

Integration / compatibility

  • Existing evtx_dump usage is unchanged; these subcommands are additive.
  • wevt_templates is now built by default as part of the evtx_dump feature, so CI (cargo test) and release binaries compile/include the offline-template tooling.
    • Library-only consumers can still disable default features (or avoid evtx_dump) to avoid pulling in template extraction dependencies.

References

Tests: cargo test (default features)


Note

Introduces end-to-end offline WEVT template support and hardens parsing.

  • Adds wevt_templates feature with optional deps (goblin, glob); new evtx_dump subcommands: extract-wevt-templates, dump-template-instances, apply-wevt-cache
  • Enables cache-backed rendering via --wevt-cache-index for XML/JSON outputs
  • Implements WEVT inline-name BinXML dialect and strict NameHash validation; threads BinXmlNameEncoding through deserializer
  • Major parser refactor: replaces I/O macros with ByteCursor, converts many readers to *_cursor variants, improves bounds checks and error types; more resilient chunk/file/record header handling
  • Documentation: README section and docs/wevt_templates.md with usage and format details
  • Minor: .gitignore updates and Cargo feature wiring

Written by Cursor Bugbot for commit 1c9450e. This will update automatically on new commits. Configure here.

@omerbenamram omerbenamram changed the title Refactor wevt_templates into submodules WEVT Support Dec 23, 2025
- Add wevt_templates Cargo feature (optional glob dep)
- Add evtx::wevt_templates PE resource extractor
- Add evtx_dump extract-wevt-templates subcommand
- Add synthetic PE test + ignored Willi sample test
Use a small PE32+ with a WEVT_TEMPLATE resource (id=1/lang=1033) so tests don't generate binary data at runtime.
- Add best-effort TTBL/TEMP discovery (guid + header fields)\n- Extend extract-wevt-templates with --split-ttbl to emit TEMP entries\n- Add tests for TTBL parsing and assert Willi sample yields 46 TEMP entries (ignored)
- Add BinXmlNameEncoding and thread it through BinXmlDeserializer/token readers\n- Parse WEVT inline name layout (hash+len+utf16+nul)\n- Add TEMP BinXML parsing + XML rendering helpers\n- Add evtx_dump flags: --dump-temp-xml (and internal iterator position accessor)\n- Smoke-tested on Willi sample: rendered templates like <Data Name="GroupName">{sub:0}</Data>
- Make evtx_dump feature include wevt_templates for CI/release builds\n- Update README with concise end-to-end offline template rendering flow\n- Refresh subcommand help text
Strip braces + case-normalize GUIDs for --template-guid and manifest template GUIDs so braced/unbraced inputs match. Also normalize provider/template GUIDs when loading the cache index, and add regression tests.
- Add DeserializationError::Truncated for slice/bounds failures.

- Introduce utils::bytes (Option + Result APIs) for LE reads + fixed tables, with docs.

- Parse EVTX chunk/file/record headers from &[u8] (from_bytes/from_bytes_at); keep reader wrappers.

- Make IterChunkRecords parse record headers without building a Cursor (bounds-oriented).

- Replace legacy try_read/try_seek macros with ReadExt trait; remove src/macros.rs.

- Consolidate UTF-16 decoding into utils::utf16 and reuse from BinXML + WEVT manifest parsing.

- Use utils::bytes in wevt_templates (extract + manifest util); remove duplicate wevt_templates/util.rs.

- Add optional goblin dep behind wevt_templates for PE resource extraction; update minimal PE fixture.

\nTests: cargo test --features fast-alloc --locked --offline
- Introduce named read helpers (read_*_named) and thread semantic field names into Truncated errors\n- Add WevtManifestError::InvalidGuid; parse GUIDs via Guid::from_buffer (no Cursor)\n- Harden utils::bytes::read_array against offset overflow
@omerbenamram omerbenamram merged commit 49ad8ce into master Dec 26, 2025
4 checks passed
@omerbenamram omerbenamram deleted the wevt-template-extract branch December 26, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add support for WEVT_TEMPLATE evtx template structure parsing

1 participant