How to adjust the length and alignment of a structure dynamically

+1 vote
asked Aug 31, 2017 in Grammars by icebreake (130 points)
I'm analysing a binary file that can be divided in mainly three sections (Head, body and footer). The head and footer are both 36 bytes long and the body expends its length dynamically, depending on what is stored in the file. Now I want to have a gramma that recognizes how long the body structure is. Also I need to adjust the alignment of the footer structure, so that the last 36 byte of the file are included in this structure element. The length of the file - (36 bytes head + 36 bytes footer) = lengthe of the body structure. I tryed a long time to find a solution for this problem but without a satisfactory success.

1 Answer

+1 vote
answered Sep 2, 2017 by andreas (3,300 points)
In this case I'd suggest to take a similar approach like in the ZIP grammar.

There a structure is parsed at the end of the file using a script that uses the file length to find the structure position.

In your case the file length can be used to control the length of the body structure.

Does this help?