Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #689966 > unrolled thread

Need Help: Replace Bytes In Binary File

Started byFarley Flud <ff@linux.rocks>
First post2025-05-04 15:32 +0000
Last post2025-05-04 17:15 -0700
Articles 9 — 4 participants

Back to article view | Back to comp.os.linux.advocacy


Contents

  Need Help: Replace Bytes In Binary File Farley Flud <ff@linux.rocks> - 2025-05-04 15:32 +0000
    Re: Need Help: Replace Bytes In Binary File Chris Ahlstrom <OFeem1987@teleworm.us> - 2025-05-04 11:57 -0400
      Re: Need Help: Replace Bytes In Binary File Farley Flud <ff@linux.rocks> - 2025-05-04 19:23 +0000
        Re: Need Help: Replace Bytes In Binary File Farley Flud <ff@linux.rocks> - 2025-05-04 21:14 +0000
          Re: Need Help: Replace Bytes In Binary File vallor <vallor@cultnix.org> - 2025-05-04 21:39 +0000
            Re: Need Help: Replace Bytes In Binary File vallor <vallor@cultnix.org> - 2025-05-04 21:47 +0000
              Re: Need Help: Replace Bytes In Binary File % <pursent100@gmail.com> - 2025-05-04 17:16 -0700
              Re: Need Help: Replace Bytes In Binary File Farley Flud <ff@linux.rocks> - 2025-05-05 08:14 +0000
            Re: Need Help: Replace Bytes In Binary File % <pursent100@gmail.com> - 2025-05-04 17:15 -0700

#689966 — Need Help: Replace Bytes In Binary File

FromFarley Flud <ff@linux.rocks>
Date2025-05-04 15:32 +0000
SubjectNeed Help: Replace Bytes In Binary File
Message-ID<pan$def57$d367618d$5365ea3b$700171a@linux.rocks>
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? 



-- 
Systemd: solving all the problems that you never knew you had.

[toc] | [next] | [standalone]


#689968

FromChris Ahlstrom <OFeem1987@teleworm.us>
Date2025-05-04 11:57 -0400
Message-ID<vv82pn$29efv$4@dont-email.me>
In reply to#689966
Farley Flud wrote this post while blinking in Morse code:

> 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

I most crack open bvi these days. Previously I used hexer a lot. But they're no
scriptable afaik.

-- 
Preserve Wildlife!  Throw a party today!

[toc] | [prev] | [next] | [standalone]


#689970

FromFarley Flud <ff@linux.rocks>
Date2025-05-04 19:23 +0000
Message-ID<pan$469e9$5479b7cb$3265e5a7$145bcea7@linux.rocks>
In reply to#689968
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.

Moreover, this method can only overwrite existing bytes and cannot insert
extra bytes at a given offset.

Incidentally, my fave hex editor is a java program called Hexditor:

http://flying.guy.chez-alice.fr/HexditorEn.php

Unlike all other GNU/Linux hex editors, Hexditor allows full insertion/
deletion anywhere in the file.

Another possibility is wxHexEditor:

https://www.wxhexeditor.org/home.php

But this software is still in beta for the past 8 years!

The author is correct though: "because there is no good hex editor for
Linux system."



-- 
Systemd: solving all the problems that you never knew you had.

[toc] | [prev] | [next] | [standalone]


#689977

FromFarley Flud <ff@linux.rocks>
Date2025-05-04 21:14 +0000
Message-ID<pan$883eb$94630766$6fffee5$582c1c40@linux.rocks>
In reply to#689970
On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:

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

For the record, I just discovered another program that is designed
to 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.


-- 
Systemd: solving all the problems that you never knew you had.

[toc] | [prev] | [next] | [standalone]


#689979

Fromvallor <vallor@cultnix.org>
Date2025-05-04 21:39 +0000
Message-ID<m7q555FhujlU1@mid.individual.net>
In reply to#689977
On Sun, 04 May 2025 21:14:57 +0000, Farley Flud <ff@linux.rocks> wrote in
<pan$883eb$94630766$6fffee5$582c1c40@linux.rocks>:

> On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:
> 
>> 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.
>>
>>
> For the record, I just discovered another program that is designed to
> 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.

-- 
-v System76 Thelio Mega v1.1 x86_64 NVIDIA RTX 3090 Ti
   OS: Linux 6.14.5 Release: Mint 22.1 Mem: 258G
   "A tribble a day keeps the Klingons well fed."

[toc] | [prev] | [next] | [standalone]


#689980

Fromvallor <vallor@cultnix.org>
Date2025-05-04 21:47 +0000
Message-ID<m7q5kdFhujlU2@mid.individual.net>
In reply to#689979
On 4 May 2025 21:39:49 GMT, vallor <vallor@cultnix.org> wrote in
<m7q555FhujlU1@mid.individual.net>:

> On Sun, 04 May 2025 21:14:57 +0000, Farley Flud <ff@linux.rocks> wrote
> in <pan$883eb$94630766$6fffee5$582c1c40@linux.rocks>:
> 
>> On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:
>> 
>>> 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.
>>>
>>>
>> For the record, I just discovered another program that is designed to
>> 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

-- 
-v System76 Thelio Mega v1.1 x86_64 NVIDIA RTX 3090 Ti
   OS: Linux 6.14.5 Release: Mint 22.1 Mem: 258G
   "Don't ask me. The cats are in charge around here."

[toc] | [prev] | [next] | [standalone]


#689984

From% <pursent100@gmail.com>
Date2025-05-04 17:16 -0700
Message-ID<RDidnVrsDcT7noX1nZ2dnZfqnPednZ2d@giganews.com>
In reply to#689980
vallor wrote:
> On 4 May 2025 21:39:49 GMT, vallor <vallor@cultnix.org> wrote in
> <m7q555FhujlU1@mid.individual.net>:
> 
>> On Sun, 04 May 2025 21:14:57 +0000, Farley Flud <ff@linux.rocks> wrote
>> in <pan$883eb$94630766$6fffee5$582c1c40@linux.rocks>:
>>
>>> On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:
>>>
>>>> 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.
>>>>
>>>>
>>> For the record, I just discovered another program that is designed to
>>> 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
> 
you don't need that to post

[toc] | [prev] | [next] | [standalone]


#689994

FromFarley Flud <ff@linux.rocks>
Date2025-05-05 08:14 +0000
Message-ID<pan$8c79b$6723a83a$1b9cfc4e$c4b161b1@linux.rocks>
In reply to#689980
On 4 May 2025 21:47:57 GMT, vallor wrote:

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

I prefer tkinfo:

tkinfo /usr/share/info/bbe.info.bz2 &

File: bbe.info,  Node: Commands,  Next: Limits,  Prev: Block,  Up: Invoking bbe

3.3 `bbe' commands
==================

Commands in `bbe' can be divided in two groups: Block related commands
and byte related commands. Block related commands operate at block
level e.g. remove a block.  Byte related commands work allways inside a
block and they don't have effect beyond the block boundaries.

   Same escape codes for byte values in STRINGs can be used as in START
and STOP of block definition.
...





-- 
Systemd: solving all the problems that you never knew you had.

[toc] | [prev] | [next] | [standalone]


#689983

From% <pursent100@gmail.com>
Date2025-05-04 17:15 -0700
Message-ID<RDidnVvsDcSlnoX1nZ2dnZfqnPcAAAAA@giganews.com>
In reply to#689979
vallor wrote:
> On Sun, 04 May 2025 21:14:57 +0000, Farley Flud <ff@linux.rocks> wrote in
> <pan$883eb$94630766$6fffee5$582c1c40@linux.rocks>:
> 
>> On Sun, 04 May 2025 19:23:22 +0000, Farley Flud wrote:
>>
>>> 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.
>>>
>>>
>> For the record, I just discovered another program that is designed to
>> 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.
> 
warning will robinson here he goes ,

[toc] | [prev] | [standalone]


Back to top | Article view | comp.os.linux.advocacy


csiph-web