How to edit binary file on Unix systems

LinuxUnixBinaryfilesHex Editors

Linux Problem Overview


On Windows machines there are lots of third party editors available to edit a binary file.

Any idea how can I edit a binary file on Unix system?

Linux Solutions


Solution 1 - Linux

In Vim, you can type :%!xxd to turn it into a hex editor. :%!xxd -r to go back to normal mode. xxd is shipped in a Vim installation.

See here for some remarks about editing binary files with Vim (it boils down to :set binary to avoid trouble. Use only the "R" or "r" command to change text, and don't delete characters).

If you are an Emacs fan, see here for a guide on how to edit a binary file with Emacs.

Solution 2 - Linux

You can also try GHex 2 GNOME utilities. This give you the automated hex-to-ASCII on the side, as well as the various character/integer decodes at the bottom.

ghex2

(Source: googlepages.com)

Solution 3 - Linux

There are many more hex editors on Linux/Unix....

I use hexedit on Ubuntu:

sudo apt-get install hexedit

Solution 4 - Linux

You can check Wikipedia.

I prefer BIEW especially.

Solution 5 - Linux

It is written in mono/Gtk# and its primary platform is GNU/Linux. However it should be able to run without problems on every platform that mono and Gtk# run. Main Features Bless currently provides the following features:

  • Efficient editing of large data files and block devices.
  • Multilevel undo - redo operations.
  • Customizable data views.
  • Fast data rendering on screen.
  • Multiple tabs.
  • Fast find and replace operations.
  • A data conversion table.
  • Advanced copy/paste capabilities.
  • Highlighting of selection pattern matches in the file.
  • Plugin based architecture.
  • Export of data to text and html (others with plugins).
  • Bitwise operations on data.
  • A comprehensive user manual.

copied from http://home.gna.org/bless/

Solution 6 - Linux

I used to use bvi.

I am developing hexvi to overcome :%!xxd and bvi's limitations.

hexvi

Features

  • vim-like keybindings and commands
  • going to specific offsets
  • inserting, replacing, deleting
  • searching for stuff (PCRE regexes)
  • everything is a command, and can be mapped in hexvirc
  • color schemes
  • support for large files
  • support for multiple files (via tabs)
  • Python so the entry level to hack around should be lower than C's
  • CLI through and through

Cons

  • as of March 2016, it's alpha so features are missing, but I'm working on those:
    • file saving
    • undo/redo
    • command history
    • visual selection
    • man page
  • no autocomplete

bvi

Features

  • vim-like keybindings and commands
  • going to specific offsets
  • inserting, deleting, replacing
  • searching for stuff (text and hex)
  • undo/redo
  • CLI through and through

Cons

  • regarding its vim capabilities - unfortunately, it understands only the most basic things and definitely needs more love in this regard (example: doesn't understand :wq, but understands :w and :q)
  • no visual selection support whatsoever
  • no tab/split screen support
  • crashes often
  • no support for large files
  • no command history
  • no autocomplete

Solution 7 - Linux

As variant, you can use radare2:

> r2 -w /usr/bin/ls

[0x004049d0]>V

[0x004049d0 14% 1104 (0x0:-1=1)]> x @ entry0
- offset - | 0 1  2 3  4 5  6 7  8 9  A B  C D  E F| 0123456789ABCDEF
0x004049d0 |31ed 4989 d15e 4889 e248 83e4 f050 5449| 1.I..^H..H...PTI
0x004049e0 |c7c0 103a 4100 48c7 c1a0 3941 0048 c7c7| ...:A.H...9A.H..
0x004049f0 |202a 4000 e877 dcff fff4 660f 1f44 0000|  *@..w....f..D..
0x00404a00 |b807 e661 0055 482d 00e6 6100 4883 f80e| ...a.UH-..a.H...
0x00404a10 |4889 e576 1bb8 0000 0000 4885 c074 115d| H..v......H..t.]
0x00404a20 |bf00 e661 00ff e066 0f1f 8400 0000 0000| ...a...f........
0x00404a30 |5dc3 0f1f 4000 662e 0f1f 8400 0000 0000| ][email protected].........
0x00404a40 |be00 e661 0055 4881 ee00 e661 0048 c1fe| ...a.UH....a.H..
0x00404a50 |0348 89e5 4889 f048 c1e8 3f48 01c6 48d1| .H..H..H..?H..H.
0x00404a60 |fe74 15b8 0000 0000 4885 c074 0b5d bf00| .t......H..t.]..
0x00404a70 |e661 00ff e00f 1f00 5dc3 660f 1f44 0000| .a......].f..D..
0x00404a80 |803d c19b 2100 0075 1155 4889 e5e8 6eff| .=..!..u.UH...n.
0x00404a90 |ffff 5dc6 05ae 9b21 0001 f3c3 0f1f 4000| ..]....!......@.
0x00404aa0 |bf10 de61 0048 833f 0075 05eb 930f 1f00| ...a.H.?.u......
0x00404ab0 |b800 0000 0048 85c0 74f1 5548 89e5 ffd0| .....H..t.UH....
0x00404ac0 |5de9 7aff ffff 662e 0f1f 8400 0000 0000| ].z...f.........
0x00404ad0 |488b 0731 d248 f7f6 4889 d0c3 0f1f 4000| H..1.H..H.....@.

For details about how work in visual mode you can read here

Solution 8 - Linux

I like KHexEdit, which is part of KDE.

Its "Windows style" UI is probably quite quick to learn for most people (compared to Vim or Emacs anyway).

Solution 9 - Linux

There's a lightweight binary editor called hexedit.

I tried using it for editing ELF binaries in Linux at least.

Solution 10 - Linux

I made wxHexEditor. It's open sourced and is written with the C++/wxWidgets GUI libraries and can open even your exabyte-sized disk!

Just try it.

Solution 11 - Linux

For small changes, I have used hexedit.

It is simple, but fast and useful.

Solution 12 - Linux

I've had good experience with wxHexEditor... just make sure if you are hex-editing a drive you do it via the menu

Devices -> Open Disk Device -> SCSI Disk Drive Partition #_N_

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHemantView Question on Stackoverflow
Solution 1 - LinuxPaweł PolewiczView Answer on Stackoverflow
Solution 2 - LinuxShannon NelsonView Answer on Stackoverflow
Solution 3 - LinuxOsama Al-MaadeedView Answer on Stackoverflow
Solution 4 - LinuxFrancisView Answer on Stackoverflow
Solution 5 - LinuxBrad GilbertView Answer on Stackoverflow
Solution 6 - Linuxrr-View Answer on Stackoverflow
Solution 7 - LinuxAndreyTView Answer on Stackoverflow
Solution 8 - LinuxJonikView Answer on Stackoverflow
Solution 9 - LinuxsetzamoraView Answer on Stackoverflow
Solution 10 - LinuxE.U.A.View Answer on Stackoverflow
Solution 11 - LinuxbitozoidView Answer on Stackoverflow
Solution 12 - LinuxasdfView Answer on Stackoverflow