When you attempt to open a compiled executable or a compiled .bin firmware file using a standard Linux text editor like nano, the screen instantly fills with unreadable gibberish, and the terminal often crashes. Standard text editors are designed to read ASCII characters, not raw machine code. To safely inspect the raw, underlying byte architecture of any binary file on a Linux system, you must convert it into a human-readable hexadecimal format using the xxd command.
How to Generate a Hex Dump
The xxd utility reads the raw zeroes and ones of a binary file and translates them into base-16 hexadecimal code. To execute a basic hex dump, open your terminal and run:
xxd firmware.bin
The terminal will output the data in three distinct columns:
- Offset (Left): The exact byte address (location) within the file, formatted in hex (e.g.,
00000000:). - Hex Data (Center): The actual raw data, grouped into 16-byte blocks per line, represented by hexadecimal pairs (e.g.,
4f67 2a99). - ASCII Translation (Right): The command attempts to translate the hex data back into standard text characters. Unreadable binary data is represented by simple dots (
.), allowing you to safely read any embedded text strings (like error messages or developer notes) hidden inside the binary without crashing your terminal.
Because binary files are often massive, it is highly recommended to pipe the output into the less command (e.g., xxd firmware.bin | less) so you can scroll through the output page by page.
How to Convert Hex Back to Binary (Reverse Dump)
The true power of xxd is that it is not just a viewer; it is a two-way conversion tool. Security researchers and programmers frequently dump a binary to a text file, edit the hex code using a text editor, and then recompile it.
First, dump the data to a standard text file:
xxd firmware.bin > editable_hex.txt
You can now open editable_hex.txt in nano or vim and manually alter the hex pairs in the center column.
Once you save your changes, you can use the -r (reverse) flag to instruct xxd to read your edited text file and convert the hex strings back into a raw, compiled binary file.
xxd -r editable_hex.txt patched_firmware.bin
The resulting patched_firmware.bin file will be a perfectly valid executable containing your manual byte-level modifications.