I have a partition image that contains a 1MB file populated with random data, and I would like to replace the contents of that file with another 1MB file populated with different random data.
I have done something similar before by creating a file with a known unique string and using sed to replace it e.g.
sed -i 's/foobar_corruptiontest/barfoo_corruptiontest/' partition.img
For a solution I imagined something along the lines of:
head -c 1M </dev/urandom >fileA head -c 1M </dev/urandom >fileB binary_sed -i 's/<fileA/<fileB/' partition.img
I found a tool bbe which purports to be a sedlike editor for binary files, but unless I am reading the man page wrong it doesn't seem to support file input?
Side-note: In case you are very confused why anyone would want to do this, the context is I am testing verity by corrupting a file in a predictable manner, but it should bear no relevance to the question. In fact please do not consider it in an answer.