# preg
[](https://crates.io/crates/preg)
[](https://docs.rs/preg)
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.
```rust
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:
```rust
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