views:

241

answers:

2

Is there a way to force the same code to produce the same binary in Visual C++? Turn off the timestamp in the PE or force the timestamp in the PE to be some fixed value, in other words?

+3  A: 

I suppose you could write a utility to open the PE, set the checksum to 0, set the timestamp to what you like, recompute the crc, then write it back out. It would be nice if there were an official way to ensure perfect binary reproducibility, though.

For more information: http://msdn.microsoft.com/en-us/magazine/cc301805.aspx

Dedrick Duckett
+2  A: 

It's not only a timestamp - there's an embedded GUID used for PDB matching - as John Robbins explains.

Even beyond that, there's just no way to force the compiler to generate consistent results, as Jim Griesmer explains -

compiler writers are far more interested in generating correctly functioning code and generating it quickly than ensuring that whatever is generated is laid out identically on your hard drive. Due to the numerous and varied methods and implementations for optimizing code, it is always possible that one build ended up with a little more time to do something extra or different than another build did. Thus, the final result could be a different set of bits for what is the same functionality.

Thus, function and section order are not guaranteed to be consistently ordered in the resulting PE. An example is at the link.

Ofek Shilon