Editing binary files in linux

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

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

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?

@JanusTroelsen that question is about v7 unix from the 70s 🙂 On AskUbuntu (GUI only. ) stackoverflow.com/questions/839227/…

12 Answers 12

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.

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.

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.

@ShannonNelson I agree. Also have a look at bvi, sudo apt-get install bvi , which is ncurses and uses vim-like shortcuts.

In particular, you can’t add or remove bytes from the middle easily: stackoverflow.com/questions/27086771/…

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?

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

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.

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 ??

There are many more hex editors on Linux/Unix.

sudo apt-get install hexedit 

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.
Читайте также:  Отключить заставку linux mint

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

hexvi

  • 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
  • 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

    bvi

    • vim-like keybindings and commands
    • going to specific offsets
    • inserting, deleting, replacing
    • searching for stuff (text and hex)
    • undo/redo
    • CLI through and through
    • 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
    > 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| ]. @.f. 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

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

    Источник

    Top Hex Editors for Linux

    In this article, we are going to review some of the best hex editors for Linux. But before we start, let’s look at what a hex editor really is.

    What is Hex editor

    In simple words, a hex editor allows you to examine and edit binary files. The difference between a regular text editor and the hex editor is that the regular editor represents the logical content of the file, while a hex editor represents the physical contents of the file.

    Who use Hex editor

    Hex editors are used for editing individual bytes of data and are mostly used by programmers or system administrators. Some of the most commonly used cases are debugging or reverse engineering binary communication protocols. Of course, there are many other things you can use hex editors – for example reviewing files with the unknown file format, performs hex comparison, reviewing program memory dump, and others.

    Most of these mentioned hex editors are available to install from the default repository using your distribution’s package manager, like so:

    # yum install package [On CentOS] # dnf install package [On Fedora] # apt install package [On Debian/Ubuntu] # zypper install package [On OpenSuse] # pacman -Ss package [on Arch Linux]

    If no package available, head over to the website of each tool where you will get the standalone package for download and installation procedures, along with details on dependencies.

    1. Xxd Hex Editor

    Most (if not every) Linux distributions come with an editor that allows you to perform hexadecimal and binary manipulation. One of those tools is the command-line tool – xxd, which is most commonly used to make a hex dump of a given file or standard input. It can also convert a hex dump back to its original binary form.

    Xxd Hex Editor for Linux

    2. Hexedit Hex Editor

    Hexedit is another hexadecimal command-line editor that might already be preinstalled on your OS. Hexedit shows both the hexadecimal and ASCII view of the file at the same time.

    Hexedit for Linux

    3. Hexyl Hex Editor

    Another useful tool for examining binary file is hexyl, is a simple hex viewer for Linux terminal that uses a colored output to determine different categories of bytes.

    Hexyl - Hex Viewer for Linux

    The view of hexyl is split into three columns:

    • Offset column to tell you how many bytes into the file you are.
    • Hex column, which contains the hexadecimal view of the file. (Note that there is a splitting line in between)
    • Textual representation of a file.

    The installation of this hex viewer is different for different operating systems, so it is recommended to check the readme file in the project to see the exact installation instructions for your OS.

    4. Ghex – GNOME Hex Editor

    Ghex is a graphical hex editor that lets users edit a binary file in both hex and ASCII format. It has a multilevel undo and redo mechanism that some may find useful. Another useful feature is finding and replacing functions and converting between binary, octal, decimal, and hexadecimal values.

    Ghex - Graphical Hex Editor for Linux

    5. Bless Hex Editor

    One of the more advanced hex editors in this article is Bless, which is similar to Ghex, it has a graphical interface that allows you to edit large data files with a multilevel undo/redo mechanism. It also has customizable data views, a find-replace feature, and multi-threaded search and saves operations. Multiple files can be opened at once using tabs. Functionality can also be extended through plugins.

    Bless - Hex Editor for Linux

    6. Okteta Editor

    Okteta is another simple editor for reviewing raw data files. Some of the main features of okteta include:

    Okteta Editor for Raw Data

    • Different views of characters – traditional in columns or in rows with a value of the top of the character.
    • Editing similar to a text editor.
    • Different profiles for data views.
    • Multiple open files.
    • Remote files by FTP or HTTP.

    7. wxHexEditor

    wxHexEditor is another one of the Linux hex editors that have some advanced features and while there is no official documentation for the editor, there is a well-written wiki page that provides an explanation as to how to use them too.

    wxHexEditor for Linux

    whHexEditor is aimed mainly at large files. It works faster with larger files because it does not attempt to copy the entire file into your RAM. It has low memory consumption and can view multiple files at once. Since it has so many features and benefits, you may want to review them all on the wiki page or the official wxHexEditor website.

    8. Hexcurse – Console Hex Editor

    Hexcurse is a Ncurses-based hex editor. It can open, edit, and save files within a friendly terminal interface that allows you to go to a specific line or perform a search. You can easily toggle between hex/decimal addresses or switch between hex and ASCI windows.

    Hexcurse - Hex Editor for Linux

    9. Hexer Binary Editor

    Hexer is another command-line binary editor. The difference in this one is that it is a Vi-like style editor for binary files. Some of the most notable features are – multi buffers, multilevel undo, command-line editing with completion, and binary regular expression.

    Hexer - Binary Editor for Linux

    Conclusion

    That was a quick review of some of the most commonly used hex editors in Linux. Let us hear your opinion. What hex editors do you use and why do you prefer that editor in particular? What makes it better over the others?

    Источник

    How to Edit and Convert Binary Files on Linux

    If a file stores data in contiguous bytes format, a program trying to read this file will need to be instructed on how to read it since such files do not directly define a compatible method for reading their associated content.

    This type of file is called a binary file. Opening such a file on a normal text editor program will only display unreadable characters. It is because binary data store data as bytes and not as textual characters.

    The headers of a binary file are accompanied by an instruction set that reveals how its stored data should be read. Since binary files can store any data type, we can broadly classify all file types as either binary or text.

    Create Binary File in Linux

    We are going to create a sample binary file that we will try to edit. We will first create a text file with some data in it and then convert the text file to a binary file using the hexdump command.

    $ echo "LinuxShellTips changed my Linux perspective!" > simple.txt $ hexdump simple.txt > simple.bin

    The cat command should confirm to us that the binary conversion was a success.

    Create Binary File in Linux

    Editing Binary Files in Linux

    We are going to use the xxd command associated with the vim editor package. We first need to open the file on Vim editor using the -b flag since we are dealing with a binary file.

    Use keyboard key [i] to enter insert mode and edit the binary file where needed. For instance, we can remove the first-line hex entries 694c to see what happens.

    Edit Binary File in Linux

    Convert Binary File to Text in Linux

    To convert the binary file to text mode to view the implemented changes, we will switch to command mode using the keyboard key [Esc] and then key in the vim command:

    Convert Binary File to Text

    Once we hit [Enter] on the keyboard, we should see the edits we made.

    View Binary File in Linux

    To save changes and quit vim use:

    We have successfully demonstrated the possibility of editing a binary file in Linux using vim editor. Know of other cool ways of editing binary files? Feel free to leave a comment or feedback.

    Источник

Оцените статью
Adblock
detector