Program status

Program created 2004
Program last touched July 2007
Status Stalled


Templet is an essential tool for binary-data editting usage. Based on ideas from Resorcerer for Macintosh, it uses user-definable templates to split data into editable chunks and to let the user edit each of them individually. Basically it is a highly enhanced structure viewer and editor. The language used is flexible enough to represent almost any form of binary data imaginable.

Imagine the power of XML combined with the speed and size of binary data. This approach combines the best of both. XML uses tags to distinguish data items in a file. But consider if you had twenty such files, each of them with the same structure, only different data. Each would be repeating the structure description over and over again. Usually the "useful" data items comprise less than 30% of XML's total size, the rest is just descriptors. What if we stripped the descriptors away into a single file and then use the 20 files without descriptors (<30% size) plus one descriptos file. Much better size outcome. Also mass-parsing becomes a bit easier, since we only have to parse the descriptor file once, the data then are all in the same format.

Looking from the other side, how many times does it happen that there is a binary file that needs a few bytes edited and you have the structure description. Imagine that you would just tell a program the description and it would let you edit exactly the fields you need, leaving the rest unchanged.

Also personally I've become quite used to actually describing binary data my programs use with the language grammar used in Templet, simply because of its simplicity and yet power.

This is actually my fourth attempt at the program, the first having been started in MS VC++, the second in Delphi, the next one in BC++B and this last one in back again in MS VC++. Of these four tries it is the most advanced, although still quite far from being usable.

Language example

The language sequentially describes the data just as a C++ struct declaration does. Some advanced features include variable-sized data, counted and sized repetitions and switch-case constructs. This actually covers a very large portion of what is usually found in binary data nowadays.

The language uses 4-byte identifiers for data types and a text description of each field. This way the user knows what they are editting and the program knows, what the data is.

An example speaks thousands of words:
Type Description Note
DWRD Document signature Decimal word
CASE $4d5a = Win / DOS Executable Symbolic value. This creates a menu for the previous item containing this item as a value
HLNG Document version Hex long, just another data piece
BCNT Number of subitems Byte count - used with counted lists to indicate the number of items
PSTR A silly string Pascal String - one-byte-counted string. This shows that other data values may come between the list count and the actual list
LSTC Item Counted list start. From here till LSTE the items will be repeated as many times as the corresponding count indicates.
KLNG Item type Key long. Keyes items make the switch-case constructs, allowing different data interpretation dependent on a key value. A list of CASEs must follow to enumerated allowed values
CASE 0 = Text Text types branch
CASE 1 = Recursion Recursion example
CASE 2 = inclusion Another branch
KEYB 0 The actual branch begins with KEYB labeled the same as CASE and ends with a KEYE.
WSTR String 1 Word-counted string
LSTR String 2 Long-counted string
CSTR String 3 NULL-terminated string (C-style)
KEYE Frist branch end
KEYB 1 "Recursion" branch start
SELF Recursion This field is actually replaced with a new instance of the template, thus allowing recursion. It must always be placed in a conditional block to prevent infinite loop.
KEYE The recursion branch end
KEYB 2 The inclusion branch
INCL BMP This field is actually replaced with the contents of the BMP template. Care must be taken not to create an inclusion circle, since such a case cannot be automatically detected.
KEYE Inclusion example end
LSKP Offset to end of data Long Skip. Uneditable value that contains the offset to the matching SKPE field.
DBYT Silly byte Just to show that more items may be present in a skip.
HEXD Unstructured data Hex dump - normally till the end of file, but here it is limited by the LSKP / SKPE pair, effectively creating a sized hex dump.
dlng Number Lowercase indicates Intel-endianness, Uppercase is for Motorola- (Mac)-endianness
SKPE Skip end. Allows for arbitrarily sized hex dumps etc.
LSTE List end. Matches the closest unmatched list start.

As you can see, the format is quite flexible, which makes it the more difficult to implement. Currently inclusion is not implemented and I'm not sure about recursion. Skips are probably not implemented or at least buggy.


Templet compiled application (RARred EXE, no warranties!) 64 KiB
Templet sources (RARred CPP) 60 KiB

Generated: 9.8.2011 15:05:01 by WebComposerWebComposer.