When you apply a patch to a file, you are overwriting part of it with updated data (a patch can also tack additional data on to the end). You can patch any type of file, whether it's text, binary, or whatever, because all files are streams of bytes when it comes down to it.
The parts of it that are supposed to be overwritten are specified in the patch file.
If a software fix involves updating a file, a patch can modify the file to be the same as a full version of an updated file. Since patches aren't the full file, but just the differences, patches will be smaller, consume less disk space, and consume less bandwidth when downloaded.
Direct editing of a binary file in a hex editor (such as
hexer) is sometimes called "manual" patching.
I'm not familiar with
xxd, but it looks like from preliminary searching that
xxd can generate a dump or hex listing of binary data, and can also convert such a listing back into straight binary. So you can dump the hex with
xxd, edit it with
vim or another text editor, and write changes back with an
xxd -r. You can also pipe it a string using
xxd "hexdump format." (Other options let you perform changes to the binary file. Looks like
xxd has a lot of options that let you specify where to start and stop overwriting, or patching.)
The first command in the example is basically telling
xxd to change the bytes in file
xxd.1 starting at offset
0x35 0x74 0x68 (ASCII for "5th").
xxd can read it's own "hexdump" format and that is what the "echo" command is providing to
The second command in the example is dumping a count (
-c) of 13 bytes in the file starting at that same offset.
patch command does a similar thing, but it wants files in a "diff" format. You can make a diff file by saving the output of the
diff command, which will compare two files and express the differences in said diff format. From reading the
man page it looks like patch is meant more for changing text files than straight binary.