1

How to delete part of binary data from binary file? (hex dump). I tried GHex 3.18.0 binary file editor, but it's not suitable for this, just lack even simple features. For example, I need select the offset address range 0x83FFF0 – 0xDDAFEB, and delete the whole block (actually, delete part starting from 0x83FFF0 to the end of file).

I prefer a GUI tool, because I need to see binary content anyway. However: first I can find addresses use GUI editor, then use some scripting command to modify file. (possibly bbe commands?)

  • Are you looking for an interactive tool where you can select parts and delete them? Or for a scriptable tool where you specify ranges to delete? – Gilles May 17 at 19:07
  • Preferably GUI tool, because I need to see binary content anyway. However: first I can find addresses use GUI editor, then use some scripting command to modify file (possibly bbe commands?). – minto May 17 at 19:14
3

You can do this in Emacs, which is available as a package on most Unix systems, if not preinstalled. The built-in hex viewer doesn't support deletion, but the improved hex viewer nhexl-mode does.

Open the file in Emacs and type Alt+x nhexl-mode Enter. If this says “no match”, type Ctrl+g and install nhexl-mode then try again. To install nhexl-mode, the easiest way is as an Emacs package. Choose “Manage Emacs Packages” from the “Options” menu and select nhexl-mode and click “Install”, or type Alt+x package-install Enter nhexl-mode Enter.

In nhexl-mode, navigate to the start of the region you want to delete and press Ctrl+Space. Navigate to the end of the region and press Delete. When you're happy with your changes, save the file.

Emacs isn't suitable for huge files, but a few tens of MB is no problem.

  • Please show how to use bbe command line tool for this task. – minto May 17 at 19:53
  • @minto I have no idea. I've never used that tool. But if you just want to remove specific offsets, you don't need it. Especially removing the end of the file is very easy: just use the truncate command. – Gilles May 17 at 19:59
0

A one-liner on the command line if you need just the first part of the file:

head --bytes=8650736 Original > Truncated

(where 83FFF0hex is obviously 8650736dec )

If you use the Simple Command Line Calculator that becomes:

head --bytes=$(c "ibase=16; 83FFF0") Original > Truncated
  • The head command is for printing of part of files, is it suitable for binary files? – minto May 18 at 10:25
  • @minto No it's not. head is mostly used for text files, but with the --bytes= it becomes a binary files reader. Same with tail so if you need a part in the middle you just pipe head to tail... 0:-) – Fabby May 18 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.