Monday, May 9, 2016

Hex Editor

There are many editors available allowing editing files in hexadecimal. These editors are typically known as "Hex Editor", with which a user can see and edit the raw and exact contents of a file, as opposed to the interpretation of the same content that other, higher level application software may associate with the file format.
When one is not immediately available, there is a handy utility that can be used as a hex editor. The utility is avaialbe on Linux as xxd. This utility is also included with a VIM distribution. xxd creates a hex dump of a given file or standard input. It can also convert a hex dump back to its original binary form.
To edit a binary file, you first convert it with xxd. Then edit the output with your favoriate editor (mine is VIM, of course!). Once editing is done, the file can be converted back to the binary form with xxd.
For example, let's assume that we want to patch the second byte of file sample.bin from 0d to 0a.

$ xxd sample.bin sample.xxd
$ vi sample.xxd
   [change the second byte from 0d to 0a and save the file]
$ xxd -r sample.xxd sample.bin
$ rm sample.xxd

That's it!

No comments:

Post a Comment