There already is a beautiful trick in this thread to write bytes to binary file at desired address with dd ,is there any way to swap bytes(e.g swap 0x00 and 0xFF), or replace bytes with common tools (such as dd)?
Asked
Active
Viewed 1,604 times
1 Answers
1
Would you please try the following:
xxd -p input_file | fold -w2 | perl -pe 's/00/ff/ || s/ff/00/' | xxd -r -p > output_file
xxd -p file
dumps the binary datafile
in continuous hexdump style.fold -w2
wraps the input lines by every two characters (= every bytes).perl -pe 's/00/ff/ || s/ff/00/'
swaps00
andff
in the input string. The||
logic works asif .. else ..
condition. Otherwise the input00
is once converted toff
and immediately converted back to00
again.xxd -r -p
is the reversed version ofxxd -p
which converts the input hexadecimal strings into binaries.

tshiono
- 21,248
- 2
- 14
- 22