AdvancedCommands

WinHex & X-Ways

Advanced Commands

 

When enclosed in braces, several variable declarations comprise a block that can be used repeatedly as a whole. Note, however, that blocks must not be nested in the current implementation. The "~" character can be used in a variable's name as a placeholder for later replacement with the actual repetition count. The optional "numbering" statement defines where to begin counting (0 by default).

 

         numbering  1

         {ab byte                                "len"

         string len                "String No. ~"

         } [10]

 

In this example the actual variable names in the template will be "String No. 1", "String No. 2", ..., "String No. 10". Instead of a constant number of repetitions (10 in this example), you may also specify "unlimited". In that case WinHex will repeat the block until the end of file is encountered. "ExitLoop" can be used to break out of a loop at any time. "Exit" terminates execution of the template completely.

 

"IfEqual" is useful for the comparison of two expressions. Operands can be either both numerical values, be it constant values in decimal notation, integer variables or a formulas, or byte sequences given as text or hex values which are compared byte by byte. ASCII string expressions must be enclosed in quotation marks, hex sequences must be prreceded by a "0x" idennnnnntifier. Formulas need to be enclosed in brackets.

 

         {                byte                                Value

         IfEqual Value 1

                         ExitLoop

         EndIf

         } [10]

 

An "IfEqual" command block is terminated with an "EndIf" statement. If the compared expressions are equal, template interpretation continues after "IfEqual". Optionally, "IfEqual" can be followed by an "Else" statement. The template processor branches into the "Else" block if the expressions are not equal. "IfEqual" commands must not be nested. "IfGreater" is similar to "IfEqual". The condition is true if the first expression is greater than the second. Strings and hex values are compared lexicographically.

 

In order to facilitate reading and navigating the template, you may define groups of variables that are separated by empty spacee in the dialog box:section                "...Section Title..."

         ...variable declaractions...

         endsection

 

The "section", "endsection", and "numbering" statements do not advance the current position in the data to be interpreted.

 

There are three commands that do not declare variables either, but are explicitly used to change the current position. This can be done to skip irrelevant data (forward movement) or to be able access certain variables more than once as different types (backward movement). Use the "move n" statement to skip n bytes from the current position, where n may be negative. "goto n" navigates to the specified absolute position from the beginning of the template interpretation (must be positive). "gotoex n" jumps to the specified absolute position based on the start of the data window (e.g. file or disk).

 

The following example demonstrates how to access a variable both as a 32-bit integer and as a four-part chain of hex values:

 

         int32                                "Disk serial number (decimal)"

         move -4

         hex 4                                "Disk serial number (hex)"