preg 0.1.0

Pure-Rust reader and writer for the Windows Group Policy Registry.pol (PReg) file format.
Documentation
  • Coverage
  • 61.54%
    32 out of 52 items documented1 out of 18 items with examples
  • Size
  • Source code size: 28.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 329.5 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • icedracon

preg

crates.io docs.rs

Reader and writer for Registry.pol — the PReg file that carries the registry half of a Windows Group Policy Object. Pure Rust, no FFI, no Windows required.

Every GPO stores its Administrative-Template settings under SYSVOL\<domain>\Policies\{GUID}\{Machine,User}\Registry.pol: an 8-byte header followed by a flat list of [key;value;type;size;data] records, all strings UTF-16LE and NUL-terminated.

use preg::{PolicyFile, RegData};

let pol = PolicyFile::parse(&std::fs::read("Registry.pol")?)?;

// Is LLMNR turned off by this GPO?
let off = pol.dword(
    r"Software\Policies\Microsoft\Windows NT\DNSClient",
    "EnableMulticast",
) == Some(0);

for e in &pol.entries {
    println!("{e}");
}

Writing works the same way and is byte-for-byte round-trip stable:

let mut pol = PolicyFile::new();
pol.set(r"Software\Policies\Microsoft\Windows NT\DNSClient", "EnableMulticast", RegData::Dword(0));
std::fs::write("Registry.pol", pol.to_bytes())?;

Features

  • All value types — REG_SZ, REG_EXPAND_SZ, REG_BINARY, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_LINK, REG_MULTI_SZ, REG_QWORD — plus a verbatim passthrough for anything else, so an unknown type still round-trips.
  • The ** instruction prefixes decoded: **del., **delvals., **deletekeys, **soft., **SecureKey.
  • Case-insensitive get / dword / set / remove, matching registry semantics.
  • Never panics on malformed or hostile input — a lying length field is a typed error, not an out-of-bounds read.

Who this is for

  • Group Policy tooling that has to read or emit policy without a Windows host.
  • Configuration management and drift detection over SYSVOL.
  • Security auditing: many hardening settings (LLMNR, SMB signing, PowerShell logging, ASR rules, WSUS, hardened UNC paths) exist only as a Registry.pol record.
  • DFIR on a SYSVOL copy.

License

MIT