TemplateDefinitionHeader

WinHex & X-Ways

Template Definition Header

 

The header of a template definition has the following format:

 

template "title"

[description "description"]

[applies_to (file/disk/RAM)]

[fixed_start offset]

[sector-aligned]

[requires offset "hex values"]

[big-endian]

[hexadecimal/octal]

[read-only]

[multiple [fixed overall size]]

// Put any general comments to the template here.

begin

         variable declarations

end

 

Tags in brackets are optional. The order of the tags is irrelevant. Expressions need only be enclosed in inverted commas if they contain space characters. Comments may appear anywhere in a template definition. Characters following a double slash are ignored by the parser.

 

The keyword "applies_to" must be followed by one and only one of the words file, disk, or RAM. WinHex issues a warning if you are going to use a template on data from a different source.

 

While by default templates start interpreting the data at the current cursor position when applied, an optional fixed_start statement ensures interpretation always starts at the specified absolute offset within the file or disk.

 

If the template applies to a disk, the keyword "sector-aligned" ensures the template interpretation starts at the beginning of the current sector, regardless of the exact cursor position.

 

Similar to the "applies_to" statement, the "requires" statement enables WinHex to prevent an erroneous application of a template definition to data that does not match. Specify an offset and a hex-value chain of an arbitrary length that identifies the data for which the template definition was intended. For example, a valid master boot record can be recognized by the hex values 55 AA at offset 0x1FE, an executable file by the hex values 4D 5A ("MZ") at offset 0x0. There may be multiple "appliesto" statements in a template definition header, which are all considered.

 

The keyword "big-endian" causes all multi-byte integer and boolean variables in the template definition to be read and written in big-endian order (high-order byte first).

 

The keyword "hexadecimal" causes all integer variables in the template definition to be displayed in hexadecimal notation.

 

The keyword "read-only" ensures that the template can only be used to examine, but not to manipulate data structures. The edit controls within the template will be grayed out.

 

If the keyword "multiple" is specified in the header, WinHex allows browsing to neighboring data records while displaying the template. This requires that WinHex has knowledge of the record's size. If it is not specified as a parameter to the "multiple" statement, WinHex assumes the overall size of a template structure (=record) to be the current position at the end of the template interpretation less the base editing position. If this is a variable size, i.e. array sizes or move parameters are determined dynamically by the value of variables, WinHex cannot browse to precedent data records.