Here's a piece of code for obtaining the time when a .NET assembly was built. Note:
const int c_LinkerTimestampOffset = 8;
and later:
int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
this code extracts the TimeDateStamp member of IMAGE_FILE_HEADER structure that is stored inside the assembly. The structure is defined as follows:
typedef struct _IMAGE_FILE_HEADER {
    WORD  Machine;
    WORD  NumberOfSections;
    DWORD TimeDateStamp;
    DWORD PointerToSymbolTable;
    DWORD NumberOfSymbols;
    WORD  SizeOfOptionalHeader;
    WORD  Characteristics;
} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
and WORD is two bytes and should be two-bytes aligned. When I compile the following code with Visual C++ 10:
IMAGE_FILE_HEADER header;
char* start = (char*)&header;
char* field = (char*)(&header.TimeDateStamp);
int diff = field - start;
diff equals 4 as I personally expected.
Is that a bug in the C# code? Why is offset value of 8 used?
 
     
     
     
    