BinView
Current
Legacy
Runs in both Layout and Modeler as a command plug-in. Requires LightWave 6.0 or later. The source code for BinView is one of the programming samples in the plug-in SDK. BinView shouldn't be used to look at files that are bigger than 2 GB.
BinView is a binary file viewer. Programmers use utilities like BinView
(sometimes called hex editors) to debug code that reads and writes binary files. Most such
tools are limited to displaying the file data as bytes written in hexadecimal format, but
BinView can display the contents of binary files as any of the numeric types used by most
computers. You don't have to know, for example, that 3F 80 00 00
is the byte
pattern corresponding to the floating-point number 1.0
. BinView can show it to
you both ways.
You can also use BinView to look at text files. They aren't as easy to
read, of course, but you can check, for example, which line ending is used by the file,
something you can't see in most text editors. Different computers use 0D
,
0A
, or a combination of the two at the ends of lines. Poorly written
software can confuse line endings, using more than one convention in a file, adding
spurious characters, or using a convention that differs from the one used on the intended
target platform.
BinView is only a viewer, not an editor. It can't be used to change the contents of binary files. This is an intentional safety limitation. You can't damage a file just by looking at it in BinView.
Source File
You begin in BinView by choosing the file you want to look at. When you first open BinView, it automatically displays a file dialog so that you can choose the first file. Any time you want to look at a different file, click on the New button (or press the n key), or type a new filename in the edit field and press Enter.
Data Window
The data window is divided into three columns. The offset column, on the left, numbers the bytes. The first byte in the file is byte 0, the second row starts with byte 16, and so on. The file contents are displayed in the center column. The column on the right displays the same data, interpreted as printable ASCII characters, which makes it easy to see text embedded in the file.
A row of controls just above the data window tells you about the display and lets you change what it shows.
- File Size
- The size of the file, in bytes.
- Offset Modulo 4
- This tells you whether the first byte displayed in the window is at an offset evenly divisible by 4. The number in the window is the remainder after dividing the offset by 4. Useful when you're looking for a part of the file that you know is supposed to be aligned on an even byte or on a longword boundary.
- Row Width
- By default, BinView displays 16 bytes per line, but you can set this to any width between 1 and 16. Use the comma and period keys (unshifted < and > keys on U.S. keyboards) to adjust the row width from the keyboard.
- Byte Order
- Most computers use the same byte patterns to represent numbers internally, but the
patterns can be written in one of two directions. The Intel byte order (keyboard shorcut i)
puts the least significant byte at the lowest offset in the file. This is the byte order
used by all machines running Microsoft Windows, as well as some others (e.g. Dec VAX). The
Motorola (m) byte order is the reverse, putting the most significant byte
first, the Internet standard.
Referring to an episode involving eggs in Swift's Gulliver's Travels, these are sometimes called big-endian (Motorola, Internet) and little-endian (Intel, Windows). IFF images and LightWave objects are big-endian. This setting only affects BinView's interpretation of the non-byte data types. BinView doesn't change the order in which bytes are displayed.
- Data Type
- This can be one of five numeric types.
- Byte (b)
- Each byte is displayed individually, as two-digit hex numbers.
- Word (w)
- Adjacent pairs of bytes are interpreted and displayed as 2-byte integers. This is
usually how the
short
type in C is stored. - Long (l)
- Bytes are grouped in fours and displayed as 4-byte integers.
- Float (f)
- IEEE 4-byte floating-point numbers. The high bit is the sign bit s, the next 8 bits are the exponent e, and the trailing 23 bits are the mantissa m. The number is (-s) (1 + m / 223) (2e-127). When e = 255, the number is interpreted as infinity (m = 0) or the special value NAN (not-a-number).
- Double (d)
- IEEE 8-byte floating-point numbers. These have an 11-bit exponent and a 52-bit mantissa.
All of these are the standard byte patterns used by the vast majority of current computers.
- Sign Bit Interpretation
- This affects Word and Long data types. By default, BinView interprets the high bit of the most significant byte as a sign bit. When this bit is set, the number is negative, and the remaining bits are in what's called two's complement form. Turning on the Unsigned checkbox causes all integers to be positive, with no sign bit. The u key toggles the checkbox.
Navigation
You can move around in the file using the cursor keys. The left and right arrow keys shift by a single byte, and the up and down arrow keys shift the data a row at a time. You can also use the Page Up, Page Down, Home and End keys.
To jump to specific byte offsets, type a number in the Jump edit field and press Enter. You can choose whether the jump is absolute (the * key), or relative to the current position forward (+) or backward (-). To repeat the jump, press j.
To search for a specific sequence of bytes, type the sequence in the Search edit field and click the Search button or press Enter. BinView always searches forward from the current byte offset. To repeat a search, press s.
BinView can interpret what you type as text (t), a mixture of text and
hexadecimal byte values (h), or as the current data type of the display
(c). If the search string is text, BinView looks for the literal characters
in the string. For searches of the current data type, BinView parses the search string,
converting it into the byte sequence that would be used to represent the values. In Text
+ Hex mode, the search string can contain both byte values, written as two-digit hex
numbers separated by spaces, and printable characters, each preceeded by a forward slash
(/
).
Type | String | Bytes |
Text | text |
74 65 78 74 |
Text + Hex | 01 02 E5 /t/e/x/t |
01 02 E5 74 65 78 74 |
Current | 1.0 |
3F 80 00 00 |
The actual bytes for Current data type search strings depends, of course, on what you're displaying. Here I'm assuming Motorola Float. The byte values of text characters are their ASCII values.
Print To File
When I was writing the LightWave object file format supplement, I needed a way to display binary file contents in the document. Rather than copy the BinView display by hand, which would be tedious and error-prone, I created the Print To File dialog.
Press the p key to open the dialog. If the output file already exists, Write mode will replace it, while Append mode will only add the new output to the end of the existing file. You can print any or all of the three columns in the data window, and you can add a comment that will help you identify the file contents later.
Keyboard Shortcut Summary
left | Move back 1 byte |
---|---|
right | Move forward 1 byte |
up | Move back 1 row |
down | Move forward 1 row |
Page Down | Move forward 1 page |
Page Up | Move back 1 page |
Home | Move to the start of the file |
End | Move to the end of the file |
n | New file |
b | Byte |
w | Word |
l | Long |
f | Float |
d | Double |
u | Unsigned |
i | Intel byte order |
m | Motorola byte order |
j | Jump |
+ | Relative forward (jump mode) |
- | Relative backward (jump mode) |
* | Absolute (jump mode) |
s | Search |
t | Text (search mode) |
h | Text + hex (search mode) |
c | Current (search mode) |
, (unshifted <) | Reduce row width by 1 |
. (unshifted >) | Increase row width by 1 |
p | Print to file |