How to create a PATCH file for the binary differen

2019-04-06 04:57发布

I want to know how to create a PATCH for the difference file I got by comparing two binary files. $cmp -l > output file name

I checked for text files 'diff" can be used to compare and generate a PATCH file $ diff -u oldFile newFile > mods.diff # -u tells diff to output unified diff format

I want to apply the PATCH on the old binary image file to get my new binary image file.

4条回答
We Are One
2楼-- · 2019-04-06 05:33

If you still want to use diff & patch. Here is a way... Write a c program yourself to insert a newline character at the end of every 512/1024/your_choice bytes (this is just to fool the diff as it compares the files line by line). Run this script on your two input files.

Then run 'diff -au file1 file2 > mod.diff (you will get the patch here)'

Patching is simple 'patch < mod.diff'

Than again write a program to remove the newlines from the binary file. That is all...

查看更多
乱世女痞
3楼-- · 2019-04-06 05:37

Diff and Patch are designed to work with text files, not arbitrary binary data. You should use something like bsdiff instead.

查看更多
仙女界的扛把子
4楼-- · 2019-04-06 05:43

JDIFF is a program that outputs the differences between two (binary) files.
Also you can use therdiff command.

查看更多
Melony?
5楼-- · 2019-04-06 05:44

If your repository, or package is using git you can make binary diff with git diff --patch --binary old_dir patched_dir Of course you can also use it with commits git diff --patch --binary commit1 commit2

查看更多
登录 后发表回答