Scripting commands apply to more environments. Comments in the script file start with a double slash. The script supports parameters up to 255 characters long. The point of doubt is hexadecimal, the text string (even 10 binary values) can be used as parameters, you can use quotation marks to cast a numeric parameter as a text parameter. If there is a space in the text or variable name, the quotation marks are required and all the characters in the quotation marks are identified as a parameter.
When you use mathematical expressions in Winhex, you can reference mathematical expressions, but you must enclose them in parentheses. You cannot have spaces in a mathematical expression. You can also apply a numeric variable to a mathematical expression. Supported operations are, addition (+), subtraction (-), multiplication (*), divisible (/), modulo (%), logical operators and (&), or (|), and XOR (^). The following are valid mathematical expressions: (5*2+1), (myvar1/(myvar2+4)), or (-myvar).
The following is a detailed description of the script commands currently supported and the usage examples.
Create "D:\My File.txt" 1000
Creates a new 1000-byte file, overwriting it if a file already exists with the same name.
Open "D:\My File.txt"
Open "D:\*.txt"
Open the file in the specified format, if the wildcard character is "?" Then Winhex will let the user select the file to open.
Open C:
Open D:
Opens the specified logical drive. If the wildcard character is ":?" The Winhex will let the user select the logical drive or disk to open.
Open 80h
Open 81h
Open 9Eh
Opens the specified physical media. The floppy disk is 00h, the hard disk and the U disk is 80h, the disc is 9Eh. You can add a second parameter to set the editing mode ("In-place" or "read-only") of the file or media.
CreateBackup
Creates a WHX backup of the current state of the active file.
Createbackupex 0 100000 650 true "F:\My backup.whx"
Backs up data from 0 sectors to 100000 sectors in the current active disk. The backup file is automatically split into 650M size. And the compression option is selected. The path of the output file and the name are written as the last parameter.
If the backup file does not need to be split, the third parameter should have a value of 0. If you do not start the compression function, change "true" to "false".
If you need to automatically assign filenames and file paths, the last parameter is represented as "".
Goto 0x128
Goto myvariable
Moves the position of the cursor to the offset 0x128 position (16 binary representation). You can also use a numeric variable (up to 8 bytes) to define the position of the cursor movement.
Move-100
Moves the position of the current cursor backwards by 100 bytes (16 binary).
Write "Test"
Write 0x0D0A
Write myvariable
Writes the ASCII character "Test" or the two-byte 16-digit "0D0A" at the cursor's current position (in overwrite mode). It is also possible to write values in a numeric variable.
also move the cursor to the back of the covered part. When the end of the file is reached, an empty byte is added to the tail of the file to complete the operation. the next write command will not add empty bytes to the tail of the file.
Write2
is similar to "Write", but when the end of the file is reached, no empty bytes are added to the file.
So it isn't safe to assume this Write2 always moves the current position forward by the number of bytes written. Insert "Test"
The feature is similar to "Write", but can only be applied to files in "Insert" mode.
Read myvariable 10
Reads 10 bytes of data from the current position into the "myvariable" variable. If a variable does not exist, it will create one. Winhex can support 48 different variables at the same time. Another command to create a variable is "Assign".
READLN myvariable
Reads a whole row of data from the current position into the "myvariable" variable until a newline character is encountered. If the variable already exists, the size of the variable will be changed from the new.
Close
Closes the currently active window without saving.
CloseAll
Close all windows without saving.
Save
Saves changes to open files or disks in the currently active window.
SaveAs "C:\New Name.txt"
Saves the file opened by the currently active window as a file in the specified directory. If the wildcard character is "?", then Winhex will let the user choose which path to save and the file name.
SaveAll
Save all the changes in the window.
Terminate
Interrupts the execution of the script.
Exit
Interrupts the execution of the script and closes the Winhex.
Exitifnofilesopen
If a file is not open in Winhex, the execution of the script file is terminated.
Block 100 200
Block "My Variable 1" "My Variable 2"
Defines an offset from 100 to 200 in the current active window (10 binary). The next line of command represents the selection of the definition from the variable "my Variable 1" to "My Variable 2" (Up to 8 bytes)
Block1 0x100
Defines a byte of the block at offset 0x100. You can also use variables.
Block2 0x200
Defines an optional block from the beginning to the 0x200 portion of the offset. You can also use variables.
Copy
Copies the current selection into the Clipboard. If no block is defined, its functionality is the same as the copy command in the Edit menu.
Cut
Cuts the files in the current selection to the Clipboard.
Remove
Removes the data from the current selection from the file.
Copyintonewfile "D:\New File.dat"
Copyintonewfile "D:\File +myvariable+.dat"
Copies the data in the current selection into the specified new file without copying it into the Clipboard. If no block is defined, its functionality is the same as the copy command in the Edit menu. You can also copy the data in the disk sector as a new file. The new file is not automatically opened in the Winhex edit window. You can add a variable between "+" and the variable name is interpreted as an integer less than 2^24 (16M). It is often useful in cyclic applications and file recovery.
Paste
Pastes data from the Clipboard into a file without changing the current position of the cursor.
Writeclipboard
Writes data from the Clipboard to the current position of the file or disk fan, without changing the current position of the cursor and overwriting data from the location of the current cursor.
Convert Param1 Param2
Converts the data in the current active file from one format to another format. Valid parameters are Ansi,ibm,ebcdic,binary,hexascii,intelhex,motorolas, Base64, uucode, lowercase, and uppercase, with the same functionality as the Convert menu command in the Convert menu.
Aesencrypt "My Password"
Encrypts the currently active file or disk with AES, or its selected block, using the specified key (up to 32 bits).
Aesdecrypt "My Password"
Decrypts the currently active file or disk.
Find "John" [MatchCase Matchword down up blockonly saveallpos Unicode wildcards]
Find 0x1234 [down up blockonly Saveallpos wildcards]
Searches for a string named "John" in the currently active window, or the number of 16 binary values 0x1234, and stops at the first search place. The other parameters are optional. The default Winhex searches the entire file or disk. The other optional parameters feature is the same as the usual Winhex search option.
ReplaceAll "Jon" "Don" [MatchCase Matchword down up blockonly Unicode wildcards]
ReplaceAll 0x0A 0x0D0A [down up blockonly wildcards]
Replaces all of the above-mentioned strings or 16 binary values in the current active window with a different value. Can only be applied to disk in "In-place" mode.
Winhex script Command (Chinese version)