( Some help pages may not display correctly in html because those help pages may have sample codein them, part of which may be mis-interpreted as html tags.

All help pages, including this help page, are available in biterScripting with the help command. )

System Feature
hex
Purpose
Editing binary files and data
Description
biterScripting can be used effectively for editing binary files and data.
This is accomplished with the repro and echo commands, and
output redirection, both in hexadecimal mode.
This technique can be used to automatically edit binary files in bulk or
to manually edit binary files one by one. Binary files can be
pictures, videos, audio files, data files, documents, slideshows, etc.
They can have file extensions of .jpg, .pdf, .doc, .docx, .xls, .wav, etc.
(Some of these file types and/or associated file extensions may be trademarks,
service marks, or other forms of intellectual property of their respective
owners.)
We will consider a generic file extension .bin in these examples but the
same technique can be used to edit binary files of any type and with any extension.
Let's assume that we have a large number of .bin files in directory
C:/Test. Each of these files have a string "Phoenix". We
want to change this string to "Chicago".
Let's first get the hexadecimal representation of the string "Phoenix"
and "Chicago". This is done using the following commands.
echo -h "Phoenix"
50686f656e6978 # This is the output of the command.
echo -h "Chicago"
4368696361676f # This is the output of the command.
The hexadecimal representation of the data in these .bin files can be
obtained with the repro (reproduce) command with the -h option. With that,
we can now write a quick script as below.
var string filelist, file, hexcontent
# Collect a list of all .bin files in folder C:/Test.
lf -n "*.bin" "C:/Test" > $filelist
# Go thru file list, one file at a time.
while ($filelist <> "")
do
# Get the next file from the list.
lex "1" $filelist > $file
# Get the hexadecimal representation the file's content.
repro -h $file > $hexcontent
# Replace "Phoenix" with "Chicago" - we will use their
# hex representations we found out above.
sal -c "^50686f656e6978 ^" "4368696361676f" $hexcontent > null
# Write file back.
echo $hexcontent h> { echo $file }
done
This will now replace the string "Phoenix" to "Chicago" in all of the binary
files.
Here is another example - let's say, we want to manually edit a file myfile.bin.
The following three commands will do that.
# Create a text file containing hexadecimal representation of file myfile.bin.
repro -h "myfile.bin" > "myfile.txt"
# Manually edit myfile.txt.
system "myfile.txt"
# The file is now open in a text editor. It is showing hexadecimal bytes.
# Edit the open file. Once you save the file, the system will automatically
# return to the following command.
repro "myfile.txt" h> "myfile.bin"
# The edited binary file is now written back.
See Also
echoreprostreaminputoutputerror