Read, edit, export, and rebuild .NET BinaryFormatter / NRBF streams.
Project description
dnbflib
dnbflib reads, indexes, edits, exports, and rebuilds .NET BinaryFormatter / NRBF
binary streams in Python.
Warning
BinaryFormatter is unsafe for untrusted data. Use this library for inspection, migration, recovery, and editing of files you already trust. Do not accept arbitrary BinaryFormatter payloads from users or the network.
Status
The current maintained APIs are:
DNBFDocumentfor memory-conscious object graph traversal and edits.export_dnbf_to_yaml/rebuild_yaml_exportfor lossless editable YAML packages.DNBFRecordStorefor SQLite-backed record storage and inspection.DNBFWriterfor rebuilding streams from raw records or writable record objects.
Requirements
- Python 3.11 or newer.
pydatastreams, installed automatically by package managers.
Installation
From PyPI, once published:
pip install dnbflib
From a local checkout:
python -m pip install -e .
Object traversal
from dnbflib import DNBFDocument
with DNBFDocument.open("save.dat") as doc:
life = doc.one(class_name="Life", where=lambda obj: obj.member("Name").value == "Alex")
finances = life.member("Finances").deref()
finances.member("BankBalance").set(123456)
doc.write("edited.dat")
DNBFDocument.open() uses an mmap-backed source file and an offset index. Prefer
doc.write(...) over doc.to_bytes() for large files because it streams output chunks.
If more than one object matches a class name, use one(..., where=...) to disambiguate:
with DNBFDocument.open("save.dat") as doc:
life = doc.one(class_name="Life", where=lambda obj: obj.member("Name").value == "Alex")
YAML export
from dnbflib import export_dnbf_to_yaml, rebuild_yaml_export
export_dnbf_to_yaml("save.dat", "save_export")
rebuilt = rebuild_yaml_export("save_export")
The export is lossless by default. It writes a manifest.yaml index and nested per-record
directories containing record.yaml, raw.bin, and decoded sidecar files when useful.
The repository also includes a command-line export example:
python examples/export_to_yaml.py save.dat save_export --verify
Record Store
from dnbflib import DNBFRecordStore, DNBFWriter, RecordTypeEnumeration
store = DNBFRecordStore(":memory:", source_bytes=b"\x0b")
store.add_raw_record(record_type=RecordTypeEnumeration.MessageEnd, offset=0, raw=b"\x0b")
rebuilt = DNBFWriter.from_record_store(store).to_bytes()
assert rebuilt == b"\x0b"
Public API
The top-level dnbflib package exports:
DNBFDocument,DNBFObjectNode,DNBFMemberNodeDNBFRecordStore,StoredRecordDNBFWriterexport_dnbf_to_yaml,export_record_store_to_yaml,rebuild_yaml_exportRecordTypeEnumeration,BinaryTypeEnumeration,PrimitiveTypeEnumerationBinaryObjectString- traversal errors such as
ObjectNotFoundError,AmbiguousObjectError,MemberNotFoundError, andAmbiguousMemberError
Further details on this library are available in docs/index.html.
License
dnbflib is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dnbflib-1.0.0.tar.gz.
File metadata
- Download URL: dnbflib-1.0.0.tar.gz
- Upload date:
- Size: 37.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.9 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19e7cbf7e7d6d76721e57f321381b4aa6a0aa5c6154a8ec4d811d8b2ad1ea3f1
|
|
| MD5 |
e284a0fc66dd4aafc78421458a11d47d
|
|
| BLAKE2b-256 |
3e7a28dc6d39cef2ed0d4c57d16f15b0022a28083a0bd52aee401cb0f7be2aef
|
File details
Details for the file dnbflib-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dnbflib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.9 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b743188cd254121597d0499cf49f6d76971da4c23c75a5b40b73fa9bfd6e542
|
|
| MD5 |
6a4644e500484bb48b7d4330cf29b514
|
|
| BLAKE2b-256 |
defa0c67609ab4e43655dd7f00b7144a9c38e333e2a442989246dd1e9b49c1f7
|