<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Enodev.fr / Christophe's log (Posts about data corruption)</title><link>https://www.enodev.fr/</link><description></description><atom:link href="https://www.enodev.fr/categories/data-corruption.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Tue, 16 Jan 2024 22:07:07 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Compare binary files</title><link>https://www.enodev.fr/posts/compare-binary-files.html</link><dc:creator>Christophe Vu-Brugier</dc:creator><description>&lt;p&gt;Diff is often used to compare two files line by line, but for binary
files you must rely on other tools. My favourite tool for this task is
&lt;a href="https://www.dettus.net/dhex/"&gt;dhex&lt;/a&gt;: I often use it to analyze data
corruptions.&lt;/p&gt;
&lt;h2&gt;Determine if two binary files are different&lt;/h2&gt;
&lt;p&gt;You can compute the checksums of the two files and compare them:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;md5sum&lt;span class="w"&gt; &lt;/span&gt;good.mp3&lt;span class="w"&gt; &lt;/span&gt;bad.mp3
&lt;span class="go"&gt;e54c63ad1efe9baea6d44a1ef836146c  good.mp3&lt;/span&gt;
&lt;span class="go"&gt;933b9d4d4323bf412ee22588db909387  bad.mp3&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But since you are not interested in the checksums, it is more simple
to invoke &lt;code&gt;diff&lt;/code&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;diff&lt;span class="w"&gt; &lt;/span&gt;good.mp3&lt;span class="w"&gt; &lt;/span&gt;bad.mp3
&lt;span class="go"&gt;Binary files good.mp3 and bad.mp3 differ&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However, a better alternative is to use &lt;code&gt;cmp&lt;/code&gt; because it tells you
where the difference starts:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;cmp&lt;span class="w"&gt; &lt;/span&gt;good.mp3&lt;span class="w"&gt; &lt;/span&gt;bad.mp3
&lt;span class="go"&gt;good.mp3 bad.mp3 differ: char 3527361, line 17610&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;View differences between binary files&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://www.dettus.net/dhex/"&gt;dhex&lt;/a&gt; is an hexadecimal editor but its
most convenient feature in my opinion is the diff mode. To enter the
diff mode, you have to invoke dhex with two files as parameters:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;dhex&lt;span class="w"&gt; &lt;/span&gt;good.mp3&lt;span class="w"&gt; &lt;/span&gt;bad.mp3
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then to jump to the first difference, you can press F3.&lt;/p&gt;
&lt;p&gt;&lt;img alt="dhex showing differing bytes between two binary files" class="img-fluid" src="https://www.enodev.fr/images/dhex-corruption.png"&gt;&lt;/p&gt;</description><category>data corruption</category><category>tools</category><guid>https://www.enodev.fr/posts/compare-binary-files.html</guid><pubDate>Sat, 05 Jul 2014 18:00:00 GMT</pubDate></item></channel></rss>