Variable Declarations
The body of a template definition mainly consists of variable declarations, similar to those in programming languages. A declaration has the basic form
type "title"
where type can be one of the following:
int8, uint8 = byte, int16, uint16, int24, uint24, int32, uint32, uint48, int64,
uint_flex,
binary,
float = single, real, double, longdouble = extended,
char, char16, string, string16,
zstring, zstring16,
boole8 = boolean, boole16, boole32,
hex,
DOSDateTime, FileTime, OLEDateTime, SQLDateTime, UNIXDateTime = time_t, JavaDateTime,
GUID
"title" must only be enclosed in inverted commas if it contains space characters. "title" must not consist only of digits. WinHex does not distinguish between upper and lower case characters in titles. 41 characters are used to identify a variable at most.
type can be preceded by at most one member of each of the following modifier groups:
big-endian little-endian (see Endian-ness)
hexadecimal decimal octal
read-only read-write
local
These modifiers only affect the immediately following variable. They are redundant if they appear in the header already. "local" translates timestamps except DOSDateTime from UTC to the timezone specified in the General Options.
The number at the end of a type name denotes the size of each variable (strings: of each character) in bits. With char16 and string16, WinHex supports Unicode characters and strings. However, Unicode characters other than the first 256 ANSI-equivalent characters are not supported. The maximum string size that can be edited using a template is 8192 bytes.
The types string, string16, and hex require an additional parameter that specifies the number of elements. This parameter may be a constant or a previously declared variable or a mathematical expression (see below). If it is a constant, it may be specified in hexadecimal format, which is recognized if the number is preceded by 0x.
You may declare arrays of variables by placing the array size in square brackets next to the type or the title. The following two lines declare a dynamically sized ASCII string, whose length depends on the preceding variable:
uint8 "len"
char[len] "A string"
The same could be achieved by the following two declarations:
byte "len"
string len "A string"
The character "~" can be used as a placeholder for later replacement with the actual array element number (see Advanced Commands). This does not apply to arrays of char variables, since they are automatically translated into a string.
Numerical parameters of string, string16, and hex variables as well as array size expressions may be specified in mathematical notation. They will be processed by the integrated formula parser. Such expressions need to be enclosed in parentheses. They must not contain space characters. They may make use of previously declared integer variables whose names do not contain space characters either. Supported operations are addition (+), subtraction (-), multiplication (*), integer division (/), modular division (%), bitwise AND (&), bitwise OR (|), and bitwise XOR (^). Valid mathematical expressions are for example (5*2+1) or (len1/(len2+4)). The result is always an integer and must be a positive number.
zstring and zstring16 are null-terminated strings whose size is determined dynamically at run-time.