Getting started with grammars--a file of simple variable-length records

0 votes
asked Apr 25 in Grammars by g1l1t1 (140 points)

I'd like to get started learning and using Synalyze It and Hexinator, but I could use a little more help than the docs offer to get me onto the learning curve.

So I'm hoping someone can provide an example grammar to get me started on a simplified version of a file format I'm interested in.

A file in this format consists of a sequence of records, where each record consists of:

  • An initial 8-bit type value type from a set of predefined values (with a symbolic name for each, but that detail can be left for later).
  • A 16-bit little endian byteCount of data bytes to follow
  • A series of byteCount dataBytes
  • An 8-bit checksum, the two's complement of the sum across typebyteCount, and dataBytes

The full details are much more complex, essentially what you'll see in Intel's OMF-51 object file format specification which you can find at https://www.keil.com/download/files/omf51.zip, but I'm happy to put off all of that until I know how to write a suitable grammar for the basic format.

A script to check a record's checksum would also be helpful but can be left for later.

1 Answer

0 votes
answered Apr 25 by andreas (3,500 points)

This sounds very similar to PNG, have you had a look at this tutorial?

https://www.synalysis.net/tutorials/decode-png-file

...