Comparing checksums from two executable files built from the same exact source

I have a question regarding checking executable files compiled with visual studio using a checksum: If I create a project from src, I get an executable file, name it exec1.exe, which has some metadata. If I rebuild the exact same src later, I get another executable, say exec2.exe, it also has its own metadata section.

If I create a checksum for each of the two files, they are different because the metadata information between the two files is different. Does anyone know a way to bypass metadata when I do a checksum of files, so that regardless of the metadata, executing a checksum of two files will result in the same checksum value? Or how to compile binaries, so that while src is identical, I get the same executables?

Thanks in advance for input, Relations

+4
source share
2 answers

There is no guarantee that Visual C ++ will generate the same binary image when creating the same source files on consecutive assemblies. The checksum is not intended to be used in this way, and after a little research it seems hard to achieve. Rather, resources such as this kb article can help compare files.

Checksums are usually used to find errors that result from sending / storing data, and not to compare versions / assemblies of an executable file.

+5
source

If you have a pdb file, you can use DIA sdk to request all the source files that were used to create the executable. We basically list all the IDiaSourceFile , and each IDiaSourceFile has get_checksum . You can create a master checksum, which is a combination of all the checksums of the source files that were used to create the executable. If any checksum of any source file has changed, you can assume that the executable has also changed.

This is the same mechanism that Visual Studio uses to determine if the source file is synchronized with pdb so that it can be inserted for debugging purposes.

0
source

Source: https://habr.com/ru/post/1388232/


All Articles