[linux] How to edit binary file on Unix systems

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?

This question is related to linux unix binaryfiles hex-editors

The answer is


you can check wikipedia.

I prefer BIEW especially.


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

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_

In vim You can type :%!xxd to turn it into a hexeditor. :%!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 (boils down to :set binary to avoid trouble, use only the "R" or "r" command to change text, don't delete characters).

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


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


Bless is a high quality, full featured hex editor.

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/


There are much more hexeditors on Linux/Unix....

I use hexedit on Ubuntu

sudo apt-get install hexedit

I made wxHexEditor, it's open sourced, written with C++/wxWidgets GUI libs and can open even your exabyte sized disk!

http://wxhexeditor.sf.net

Just try.


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 :)


There's lightweight binary editor, check hexedit. http://www.linux.org/apps/AppId_6968.html. I tried using it for editing ELF binaries in Linux at least.


For small changes, I have used hexedit:

http://rigaux.org/hexedit.html

Simple but fast and useful.


Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to unix

Docker CE on RHEL - Requires: container-selinux >= 2.9 What does `set -x` do? How to find files modified in last x minutes (find -mmin does not work as expected) sudo: npm: command not found How to sort a file in-place How to read a .properties file which contains keys that have a period character using Shell script gpg decryption fails with no secret key error Loop through a comma-separated shell variable Best way to find os name and version in Unix/Linux platform Resource u'tokenizers/punkt/english.pickle' not found

Examples related to binaryfiles

Transform hexadecimal information to binary using a Linux command How can I save a base64-encoded image to disk? How to edit binary file on Unix systems Managing large binary files with Git What is the best place for storing uploaded images, SQL database or disk file system? How can you encode a string to Base64 in JavaScript?

Examples related to hex-editors

Excel VBA Password via Hex Editor Need a good hex editor for Linux How to edit binary file on Unix systems What's a good hex editor/viewer for the Mac?