Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 40

Thread: Is there a Linux application that can compare two binary files?

  1. #21
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: Is there a Linux application that can compare two binary files?

    I don't think so... However you do bring up a very interesting feature that could be added to a binary differing tool... Especially with assembly... That would probably be very helpful!

    Good idea.

    This inspires me to work on a small toolkit for dealing with binary files...

    jblebrun, do you mind if I steal your idea?

  2. #22
    Join Date
    Dec 2006
    Location
    Sacramento, CA
    Beans
    284
    Distro
    Ubuntu 6.10 Edgy

    Re: Is there a Linux application that can compare two binary files?

    Quote Originally Posted by Wybiral View Post
    I don't think so... However you do bring up a very interesting feature that could be added to a binary differing tool... Especially with assembly... That would probably be very helpful!

    Good idea.

    This inspires me to work on a small toolkit for dealing with binary files...

    jblebrun, do you mind if I steal your idea?
    Go for it! I stole it from the way text diffing works, anyway. If you do a diff on a text file, it can detect inserted or removed lines... I just transfered that concept to individual bytes. I never come up with my own ideas... I just shuffle other people's ideas around

  3. #23
    Join Date
    Aug 2005
    Location
    The Local Group
    Beans
    631

    Re: Is there a Linux application that can compare two binary files?

    Quote Originally Posted by jblebrun View Post
    Ok, so I have a question. I haven't really used any of these binary differencing tools/libraries. Consider a case like this:

    File 1:
    01 45 6a 89 12 46 78 99

    File 2:
    45 6a 89 12 45 ff 78 99

    Do the differencing tools have a method for reporting a "missing" or "added" byte?

    Showing how file 2 is different from file 1 would be:
    1 -01
    5 -46 +45
    6 +ff
    That problem has a name: "edit distance." The edit distance between two strings is the minimum number of character insertions, deletions, and mutations required to transform one into the other. IIRC, computational biologists make good use of this to compare DNA sequences.

    edit: As a workaround, you can use a combination of diff and hexdump to detect inserted and deleted bytes:
    hexdump -e "1 1 \"%02x\n\"" file1 > temp1
    hexdump -e "1 1 \"%02x\n\"" file2 > temp2
    diff temp1 temp2
    Last edited by Lux Perpetua; January 27th, 2007 at 10:50 PM.

  4. #24
    Join Date
    Dec 2006
    Location
    Sacramento, CA
    Beans
    284
    Distro
    Ubuntu 6.10 Edgy

    Re: Is there a Linux application that can compare two binary files?

    Quote Originally Posted by Lux Perpetua View Post
    That problem has a name: "edit distance." The edit distance between two strings is the minimum number of character insertions, deletions, and mutations required to transform one into the other. IIRC, computational biologists make good use of this to compare DNA sequences.
    Thanks for giving me the official name for that. Defining a metric like edit distance makes the problem much more clear!

    I'm gonna guess that you recalled correctly: if you ask me, it sounds like a problem that's 100% applicable to DNA.

  5. #25
    Join Date
    Jan 2007
    Beans
    1

    Re: Is there a Linux application that can compare two binary files?

    The answer sort of depends what you want to know about the files, and how large they are.

    If all you care about is whether they differ at all, then use the md5sum program to compute a hash of each file, and compare the hashes.

    diff will compare binary files, but like the md5sum approach only tells you if they differ.

    cmp will- if called with -l- tell you where and how the files differ.

  6. #26
    Join Date
    Jan 2008
    Beans
    47

    Re: Is there a Linux application that can compare two binary files?

    I need to compare very large files. Which need several hour. diff don't print any progress. I wrote a very simple java program to do the thing.

    Code:
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    
    public class Test {
    
    	public static void main(String[] args) throws Exception {
    		String name = "backup.part1.rar";
    		File file1 = new File("/home/bak/1/" + name);
    		File file2 = new File("/mnt/" + name);
    		java.io.BufferedInputStream fi1 = new BufferedInputStream(
    				new FileInputStream(file1));
    		java.io.BufferedInputStream fi2 = new BufferedInputStream(
    				new FileInputStream(file2));
    		byte[] bs1 = new byte[1024 * 1024];
    		byte[] bs2 = new byte[1024 * 1024];
    		long pos = 0;
    		while (true) {
    			System.out.format("%,d\n", pos);
    			int len1 = fi1.read(bs1);
    			int len2 = fi2.read(bs2);
    			if (len1 != len2)
    				throw new Error();
    			if (len1 < 0)
    				break;
    			for (int i = 0; i < bs1.length; i++) {
    				if (bs1[i] != bs2[i]) {
    					System.out.println(pos + i);
    					throw new Error();
    				}
    			}
    			pos += len1;
    		}
    		fi1.close();
    		fi2.close();
    	}
    }

  7. #27
    Join Date
    Jan 2006
    Beans
    1,237
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Is there a Linux application that can compare two binary files?

    I recently needed to compare binary files to reverse engineer a homebrew file format. What I needed was a program to find big blocks that are same in each file. For binary, a line by line comparison like diff doesn't mean much. But then again, it may be what you need

  8. #28
    Join Date
    Feb 2007
    Location
    New York
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Is there a Linux application that can compare two binary files?

    Edit and compare giant binary files with lfhex

    http://www.linux.com/feature/135690

    (Edit: After installing 80 MB of dependencies, it still won't install. I give up.)


    My application is two almost-identical .wav files that I created a long time ago and stored in different places. They are not binary-equal, though, so some errors must have occurred in transmission or storage. I want to see if I can figure out which is the original.

    Code:
    cmp -l Untitled.wav Untitled2.wav 
      4973185 125 135
     93124225 155 145
     93212289 361 371
    100802177 274 264
    So they only differ in four places, by single bits?
    Last edited by Endolith; July 12th, 2008 at 02:22 AM.
    "Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct

  9. #29
    Join Date
    Aug 2006
    Beans
    4

    Thumbs down Re: Is there a Linux application that can compare two binary files?

    VBINDIFF(1) Christopher J. Madsen VBINDIFF(1)

    NAME
    vbindiff - hexadecimal file display and comparison

    SYNOPSIS
    vbindiff file1 [ file2 ]

    DESCRIPTION
    Visual Binary Diff (VBinDiff) displays files in hexadecimal and ASCII (or EBCDIC). It can also display two files at once, and highlight the differences between them. Unlike diff, it works well with large files (up to 4 GB).


  10. #30
    Join Date
    Jun 2008
    Location
    New York, USA
    Beans
    781

    Re: Is there a Linux application that can compare two binary files?

    Quote Originally Posted by jbus View Post
    What I need is a hex editor type application that can take two binary files and show the difference between the two files. Does such an application exist for Linux?
    Hey... look at this thread. It *might* be what you need.

    http://ubuntuforums.org/showthread.php?t=1075459

    -- Roger
    Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Page 3 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •