
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
dingsda
Advanced tools
A powerful declarative symmetric parser/builder for binary data with XML de- and encoding
DingsDa is a powerful declarative and symmetrical parser and builder for binary data. It is a fork of Construct 2.1, which removes the parser generator features, but adds preprocessing and XML de- and encoding. It is build mainly with reverse engineering data formats in mind.
Instead of writing imperative code to parse a piece of data, you declaratively define a data structure that describes your data. As this data structure is not code, you can use it in one direction to parse data into Pythonic objects, and in the other direction, to build objects into binary data.
The library provides both simple, atomic constructs (such as integers of various sizes), as well as composite ones which allow you form hierarchical and sequential structures of increasing complexity. Construct features bit and byte granularity, easy debugging and testing, an easy-to-extend subclass system, and lots of primitive constructs to make your work easier:
A Struct is a collection of ordered, named fields::
>>> format = Struct(
... "signature" / Const(b"BMP"),
... "width" / Int8ub,
... "height" / Int8ub,
... "pixels" / Array(this.width * this.height, Byte),
... )
>>> format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))
b'BMP\x03\x02\x07\x08\t\x0b\x0c\r'
>>> format.parse(b'BMP\x03\x02\x07\x08\t\x0b\x0c\r')
Container(signature=b'BMP')(width=3)(height=2)(pixels=[7, 8, 9, 11, 12, 13])
A Sequence is a collection of ordered fields, and differs from Array and GreedyRange in that those two are homogenous::
>>> format = Sequence(PascalString(Byte, "utf8"), GreedyRange(Byte))
>>> format.build([u"lalaland", [255,1,2]])
b'\nlalaland\xff\x01\x02'
>>> format.parse(b"\x004361789432197")
['', [52, 51, 54, 49, 55, 56, 57, 52, 51, 50, 49, 57, 55]]
Most constructs can be build into XML and parsed back from XML:
>>> s = Struct(
... "a" / Int32ul,
... "b" / Int32ul,
... "s" / Struct(
... "c" / Int32ul,
... "d" / Int32ul,
... ),
... )
>>> data = {"a": 1, "b": 2, "s": {"c": 3, "d": 4}}
>>> xml = s.toET(obj=data, name="test")
>>> assert(ET.tostring(xml) == b'<test a="1" b="2"><s c="3" d="4" /></test>')
>>> s = "test" / Struct(
... "a" / Int32ul,
... "b" / Int32ul,
... )
>>> xml = ET.fromstring(b'<test a="1" b="2" />')
>>> obj = s.fromET(xml=xml)
>>> assert(obj == {"a": 1, "b": 2})
However some constructs, like Switch or FocusedSeq have some caveats, because they use the XML tag name for identifying the corresponding construct.
This is mainly build for easy and quick describing of datastructures with an easy, human readable and changeable XML representation, rather than completeness of all possible constructs.
FAQs
A powerful declarative symmetric parser/builder for binary data with XML de- and encoding
We found that dingsda demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.