Is there any straightforward way to modify a binary from the commandline? Let's say I know that my binary contains 1234abcd and i want to change it to 12FFabcd or FFFFabcd or maybe even FF34FFabc0 (you get the idea) :-)
How might I achieve that without using any special purpose tools like http://stahlworks.com/dev/swiss-file-knife.html or similar.
It would be great to do it just from the commandline with only standard linux tools.
Or maybe even better instead for searching for the hex string i want to replace directly writing FF at Offset 0x10000, 12 at Offset 0x100001 and so on.
Any idea?
Thanks in advance!
P.S.: I should add the following:
It should be scriptable and run directly from the commandline. I am looking for something like "binary-which-is-included-in-the-distro --write AB --at-offset 100000 --file thebinary.bin". I am quite sure that it is possible with "dd", but I wasn't able to wrap my head around the man page.
dd arguments:
One Josh looking out for another ;)
Writing the same byte at two different positions in the same file with a one liner.
status=none very useful when you don't want any statistics out of dd.
Here's a Bash function
replaceByte
, which takes the following parameters:If you don't need it to be scriptable, you could try the "hexedit" utility. It is available in many Linux distributions (if not installed by default, it can usually be found in the distro's package repository).
If your distro doesn't have it, you can build and install it from source.
The
printf+dd
based solutions do not seem to work for writing out zeros. Here is a generic solution in python3 (included in all modern distros) which should work for all byte values...Usage...
Note: This code can handle input numbers both in hex (prefixed by 0x) and dec (no prefix).
xxd tool, which comes with vim (and thus is quite likely to be available) allows to hex dump a binary file and construct a new binary file from a modified hex dump.