CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2005
    Posts
    281

    Comparing 2 Files?

    Hey I'm trying to compare 2 binaries, like when a project is updated. I want to the comparer to be able to see what % of the bytes are different than from before. Would I be able to do something like comparing a text file? I know the contents of a exe are far different from that of a text, but I'm not entirely sure how I could go about this.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Comparing 2 Files?

    You just open both files in binary mode and compare every byte.
    Of course, reading byte per byte is slow, so better is to read a block of bytes, say 256KB into a memory buffer and then compare the memory buffers.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Nov 2005
    Posts
    281

    Re: Comparing 2 Files?

    Thank you for the help! It cleared everything up for me.

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Comparing 2 Files?

    Comparing the exe contents is not a good idea, reason is, if the exe just have updated for new constant variable string the exe format would push down the stuf and then you would find 90&#37; of difference, but actually only few bytes were added.

    Instead, compare the creation time stamp. Why do you need to compare binaries by the way ?
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Comparing 2 Files?

    You are right, but it just depends on how you interpret "difference". When I replied I assumed "difference" meant the real different bytes. So, even if your exe has just an updated constant variable string and pushes 90&#37; of the rest of the exe down, this means that 90% of the bytes are different, even thought they are just move a bit, it's still different.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured