How to edit a binary file on Unix systems [closed]
Asked Answered
H

12

69

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

How can I edit a binary file on a Unix system?

Hammonds answered 8/5, 2009 at 10:33 Comment(2)
@JanusTroelsen that question is about v7 unix from the 70s :) On AskUbuntu (GUI only...) #839727Calve
Similar later question, with more upvotes and now closed: #5498697Calve
T
43

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)

Transmarine answered 9/5, 2009 at 4:34 Comment(3)
Thanks. it present on my sunos system. any thing on hpux ?Hammonds
I don't know what all is on HPux, but since it is open source software you could probably find the source, compile and install it yourself.Transmarine
I would have loved it if copy-paste would have working. I am using ghex v2.5 and it only paste one byte at a time. is there a way to bulk copy paste ??Gild
S
125

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.

Safe answered 8/5, 2009 at 12:24 Comment(7)
Yes, this works, but it is more difficult to use because you need to work at keeping the xxd text formatted properly, and the ASCII decode on the side isn't automatic.Transmarine
More difficult than what? I'd like to remind that the question was about hexeditors shipped with *nix. Console users don't have much choice.Treasonable
@ShannonNelson I agree. Also have a look at bvi, sudo apt-get install bvi , which is ncurses and uses vim-like shortcuts.Calve
In particular, you can't add or remove bytes from the middle easily: #27087271Calve
I see this trick recommended all over the place and it makes me sad. You can't search for anything that happens to span two or more visual lines, you can't easily go to specific offset, the editing is inferior (can't input floats for example), can't delete or insert new bytes without screwing everything up... what can you do besides flipping bytes?Radack
@rr It's more than enough when you found offending snippet in objdump's output and need to simply nop it out in executable. I'd +100 this if I could.Cilicia
Excellent solution. vim -b. I used it to change the soname on some shared library dependencies in an executable and worked perfectly.Chinookan
T
43

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)

Transmarine answered 9/5, 2009 at 4:34 Comment(3)
Thanks. it present on my sunos system. any thing on hpux ?Hammonds
I don't know what all is on HPux, but since it is open source software you could probably find the source, compile and install it yourself.Transmarine
I would have loved it if copy-paste would have working. I am using ghex v2.5 and it only paste one byte at a time. is there a way to bulk copy paste ??Gild
B
18

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

I use hexedit on Ubuntu:

sudo apt-get install hexedit
Bretbretagne answered 9/5, 2009 at 15:35 Comment(0)
D
10

You can check Wikipedia.

I prefer BIEW especially.

Deckhouse answered 8/5, 2009 at 10:38 Comment(2)
Thanks for the wikipedia link. I liked Hexditor.jarProminence
Hexinator is pretty good, but I like 010Editor best thoughAudryaudrye
M
9

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 https://github.com/afrantzis/bless

Mickel answered 8/5, 2009 at 13:15 Comment(0)
R
7

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
Radack answered 16/8, 2015 at 11:7 Comment(0)
R
4

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

Rosie answered 29/3, 2016 at 13:50 Comment(0)
A
3

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

Astomatous answered 8/5, 2009 at 16:3 Comment(0)
E
2

There's a lightweight binary editor called hexedit.

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

Eamon answered 8/5, 2009 at 10:46 Comment(2)
The link is broken: "Page not found"Hiedihiemal
Updated the broken link which points to the same link present on of the answers.Eamon
L
2

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.

Lavonda answered 19/3, 2011 at 22:37 Comment(1)
I removed the offensive statement (try to avoid these) and added info about used GUI toolkit (found on your website). Hope it's OK.Melanie
B
1

For small changes, I have used hexedit.

It is simple, but fast and useful.

Backrest answered 8/5, 2009 at 15:49 Comment(0)
I
1

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_
Incomer answered 31/1, 2012 at 20:25 Comment(1)
What is the reason for "via the menu"? What happens if you don't?Hiedihiemal

© 2022 - 2024 — McMap. All rights reserved.