How to Tell If Two Executable (Binary) Windows Files are the same

Posted on 2011-10-17
Last Modified: 2012-05-12
I am attempting to compare two executables that are compiled from the same source code within Visual Studio 2008 and Visual Studio 2010. When I attempt to use WinMerge or PE Explorer, I can get the same source code showing several variations from one another even though they were compiled from the same source code. For instance if I were to compile executable_A at 1pm and then compile executable_B at 2pm, I would end up with several distinctions within the *.exe file itself when comparing them with WinMerge or PE Explorer. From using these programs, I have found that the date/time stamp of when the *.exe was created is different and embedded into the *.exe as well as there is something called a "magic number" that is different if you were to compile the same source code on two different computers. I was wondering if someone knew of a way to make the executables be the same throughout the entire executable file, by removing the date/time stamp or removing the "magic number" that is found when using these two applications to compare *.exe. (During the testing of these applications, I used some source code that was compiled in Visual Basic, C++, and C#. All languages ended up with the same results.)

Any help that could be provided on this issue would be greatly appreciated.
Question by:thenthorn1010
    LVL 7

    Expert Comment

    There may be a prettier way to do this, but just a couple ideas:

    1) Examine the compiler options and docs closely.  There may be switches, etc., to keep that data out, or to manually set it.
    2) Depending on exactly what is being embedded, you may be able to fake it (by rigging the system clock, e.g.).  Cheesy.
    3) If the differences are small and are written to a static header, you may be able to simply figure out where they are and ignore them (or copy from one to the other if you need to make them match).
    LVL 37

    Accepted Solution

    Since you are in Windows, you are creating PE files (.exe files) which follow a specific format regardless of the language used.
    For lots of info on the PE format, see:

    There is a timestamp as well as a linker version that go in the header. Those would naturally be different based on compiler version and time.
    LVL 37

    Assisted Solution

    The 'magic' number in the PE header is always the ASCII code for "MZ" so I'm not sure what magic number you are referring to.

    Author Comment


    Thank you for the link to the article. It did help explain a lot to me about the PE file format. I was wondering if by chance you knew how to turn off the settings for having all of the information that was mentioned above from any *.EXE that is compiled and built within Windows. (I am being forced to use legacy code on Microsoft Visual C++ version 6 to begin this project, and the person purchasing the code would like to know that they are getting the same code that they have on their FTP site from the source code that they are purchasing.)

    Thank you again for any help you can add and for all of the help that you provided.

    One question...I was under the impression that the "Magic Number" was unique to each computer because it was representative of the processor that is being that true? Or, why is the magic number the same on each computer, if I am incorrect?
    LVL 37

    Assisted Solution

    The field labelled "magic" is always 010B now (the "MZ" thing was from the old DOS format). There may be other fields that change from computer to computer. I'm not really an expert on the PE format; I've just studied it a bit for some reverse engineering and file decoding.

    The Machine field can differ in the processor is different. And all the versions (OS, Image, Subsystem, and especially Linker) could all be different depending on the compiler.

    There is no way to "turn off" those options. The only way to do that would be to go into the exe manually (or with a script) and change those values. It generally should not affect the running of the program, but it might mess with things that check compatibility (like Windows 7) because it might say it's incompatible (but it should run fine).
    LVL 37

    Assisted Solution

    That's assuming you are creating standalone exes. If you are creating and using dlls, then the linker version might matter.

    Here's the thing though. Who cares if the headers match? Tell the people who have concerns that the headers don't matter and only the image matters. So if the actual code (the non-header portion of the file called the image) is the same, then the two exes should be considered the same.

    In fact there's even an image checksum field in the header. If those are being populated and match, just compare those.

    Author Closing Comment

    Thanks for the in-depth helped me tremendously...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    This is about my first experience with programming Arduino.
    If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
    This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now