Binary formats typically aren't easily specified; they are rarely specified in a high level marked language such as ASN.1 (and such specifications cannot be retro-fitted to existing binary formats). The bdec project is an attempt to specify arbitrary binary formats in a markup language, and create a decoder and encoder automatically for that binary format given the high level specification.
The bdec xml specification uses constructs based on the constructs found in ASN.1.
The bdec library consists of a decoding / encoding library and command line decoding and encoding applications. Given a specification, the command line application will create an xml representation of the data contained in the binary file, and can (for some representations) convert the xml back to binary.
The library is capable of creating such xml output, or optionally a python object representing the constructs contained in the binary data.
For example; the xml representation of a FAT bootsector generated by running:
dd if=/dev/sda1 bs=512 count=1 | decode bootsector.xml
Here are some key features of "bdec":
- It is easy to quickly write (and read) a specification
- No need to write a custom decoder (all error conditions are handled internally; decoding either passes or fails).
- The command line application allows visual inspection of problematic files.
- Unicode aware, little-endian / big-endian aware
- Specify fields down to the bit (eg: single bit flags)
- Encoding data structures to binary is now supported.
- This includes encoding from Python instances, XML, and C structures.
- Specifications can now be split into multiple files by simply passing all of the specification files to the decode/encode/compile programs.