Once a program has been compiled, it is not easy to get a peek at the source code or to manipulate its behavior. But there is one thing we can do, which is look at the hexadecimal values inside the binary files. We can also make changes to the data and compile it back to a binary file. This will sometimes reveal information about a file, or allow us to modify its behavior if we can manage to edit the right bit.
A classic example is video game hacks. When playing a game, let’s say your character has a health value of 100. Chances are that you can search the game’s binary files for “100,” and by editing this value to “999,” you could change the health of your character in game. This might take a few tries to find the correct bit, but determined users have tried and succeeded at making such edits in the past. This is just an example and it works more reliably in older, basic games, but it illustrates how hex editors can modify a compiled binary file.
In this tutorial you will learn:
- How to install the
xxdcommand on major Linux distros
- How to create a hex dump of a binary file
- How to convert a hex dump back to binary file
xxdLinux command examples
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to Install the xxd Command on Linux
You can use the appropriate command below to install the
xxdhexadecimal editor command with your system’s package manager.
$ sudo apt update $ sudo apt install xxd
$ sudo dnf install xxd
$ sudo pacman -S xxd
xxd Linux Command Examples
xxd is a command line hex editor that can create a hex dump of a binary file. It can also convert the dump back to binary form later. This gives you the ability to edit the dump file and then convert it back to see how your changes have affected the program.
Let’s see how to use the
xxd command through examples below.
- The most basic syntax is to just supply a file name to the
xxdcommand. This will generate a hex dump of the file and will be output to your terminal.
$ xxd file_name
As you can see above, some of the content is easily readable, and we can glean information from this compiled file.
- You can use Bash shell redirection
>character if you want to dump this data to a file.
$ xxd file_name > hex_dump
- To convert your hexadecimal data back to binary, use the
-roption. Unless you want the output to show in your terminal, make sure you redirect it to a new file.
$ xxd -r hex_dump > binary_file
- Another handy option to use with
-boption. Using this option will convert the file to binary bits instead of a hexadecimal dump.
$ xxd -b file_name > binary_dump
In this tutorial, we saw how to install and use the
xxdcommand on a Linux system.
xxdis a command line program that creates a hexadecimal dump of a binary file. This allows us to glean information that would otherwise be obscured, and also allows us to change different hex bits before converting the file back to binary. Through lots of trial and error, it is possible to edit a file in the way you desire with xxd.