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)?
2 Answers
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 filedumps the binary datafilein continuous hexdump style.fold -w2wraps the input lines by every two characters (= every bytes).perl -pe 's/00/ff/ || s/ff/00/'swaps00andffin the input string. The||logic works asif .. else ..condition. Otherwise the input00is once converted toffand immediately converted back to00again.xxd -r -pis the reversed version ofxxd -pwhich converts the input hexadecimal strings into binaries.