I need to replace some bytes in potentially very large binary files.
Fortunately, I know the offset and I know the byte length.
I can easily invoke a hex editor and manually do the replacement
but I desire a faster method using CLI.
How can I do this with CLI?
This link has some ideas:
https://stackoverflow.com/questions/4783657/write-byte-at-address-hexedit-modify-binary-from-the-command-line
On Sun, 4 May 2025 11:57:43 -0400, Chris Ahlstrom wrote:
This link has some ideas:
https://stackoverflow.com/questions/4783657/write-byte-at-address-hexedit-modify-binary-from-the-command-line
That does work on my files.
printf '\x49\x4e\x41\x52\x59' | dd of=$1 bs=1 seek=7 count=5 conv=notrunc
But the offset has to known beforehand and the replacement bytes
have to be entered manually. It's just as slow as using search and
replace with a hex editor.
On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:
On Sun, 4 May 2025 11:57:43 -0400, Chris Ahlstrom wrote:For the record, I just discovered another program that is designed to search/replace on binary files in the manner of sed:
This link has some ideas:That does work on my files.
https://stackoverflow.com/questions/4783657/write-byte-at-address- hexedit-modify-binary-from-the-command-line
printf '\x49\x4e\x41\x52\x59' | dd of=$1 bs=1 seek=7 count=5
conv=notrunc
But the offset has to known beforehand and the replacement bytes have
to be entered manually. It's just as slow as using search and replace
with a hex editor.
https://sourceforge.net/projects/bbe-/
I am very surprised that there are not more such utilities.
Bbe seems to have a bit of a learning curve. For now, I'll stick to
manual editing with Hexditor.
On Sun, 04 May 2025 21:14:57 +0000, Farley Flud <[email protected]> wrote
in <pan$883eb$94630766$6fffee5$[email protected]>:
On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:hexedit-modify-binary-from-the-command-line
On Sun, 4 May 2025 11:57:43 -0400, Chris Ahlstrom wrote:
This link has some ideas:
https://stackoverflow.com/questions/4783657/write-byte-at-address-
For the record, I just discovered another program that is designed toThat does work on my files.
printf '\x49\x4e\x41\x52\x59' | dd of=$1 bs=1 seek=7 count=5
conv=notrunc
But the offset has to known beforehand and the replacement bytes have
to be entered manually. It's just as slow as using search and replace
with a hex editor.
search/replace on binary files in the manner of sed:
https://sourceforge.net/projects/bbe-/
I am very surprised that there are not more such utilities.
Bbe seems to have a bit of a learning curve. For now, I'll stick to
manual editing with Hexditor.
Thank you for suggesting bbe.
Incidentally:
$ apt-cache show bbe [...]
Section: universe/editors Origin: Ubuntu [...]
_ _ _ _ _ _ _
There are examples in the info documentation. For viewing it, I
recommend pinfo(1), which is sort of like lynx(1) for info files
Ah, nevermind pinfo(1) -- it will fail an assertion:
pinfo: initializelinks.c:159: finddot: Assertion `closest>=str'
failed.
Aborted (core dumped)
...when you browse to Invocating bbe > Commands
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 20:19:18 |
| Calls: | 12,104 |
| Calls today: | 4 |
| Files: | 15,004 |
| Messages: | 6,518,101 |