using System; using System.IO; namespace SignalEleven.CompileTime { class CompileTimeRunner { private static readonly DateTime _standardWindowsDateStartPoint = new DateTime(1970, 01, 01, 0, 0, 0); private const int OFFSET_TO_DATESTAMP = 8; private const int OFFSET_TO_e_lfanew = 60; [STAThread] static void Main(string[] args) { CompileTimeRunner app = new CompileTimeRunner(); if(args.Length == 0) { Console.WriteLine("usage: compiletime "); return; } app.Run(args[0]); } private void Run(String path) { if(path == null) { return; } byte[] fileData = new byte[2048]; using(Stream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { fileStream.Read(fileData, 0, 2048); } int offset = BitConverter.ToInt32(fileData, OFFSET_TO_e_lfanew); offset += OFFSET_TO_DATESTAMP; int secondsSince1970 = BitConverter.ToInt32(fileData, offset); DateTime exeCompilationDate = _standardWindowsDateStartPoint.AddSeconds(secondsSince1970); Console.WriteLine(exeCompilationDate.ToString()); } } /* public struct IMAGE_DOS_HEADER { public ushort e_magic; // 0 public ushort e_cblp; // 2 public ushort e_cp; // 4 public ushort e_crlc; // 6 public ushort e_cparhdr; // 8 public ushort e_minalloc; // 10 public ushort e_maxalloc; // 12 public ushort e_ss; // 14 public ushort e_sp; // 16 public ushort e_csum; // 18 public ushort e_ip; // 20 public ushort e_cs; // 22 public ushort e_lfarlc; // 24 public ushort e_ovno; // 26 public ushort[] e_res; // 28 [4] public ushort e_oemid; // 36 public ushort e_oeminfo; // 38 public ushort[] d_res2; // 40 [10] public int e_lfanew; // 60 } public struct IMAGE_NT_HEADERS32 { public uint Signature; // 0 IMAGE_FILE_HEADER FileHeader; // 4 IMAGE_OPTIONAL_HEADER32 OptionalHeader; } public struct IMAGE_FILE_HEADER { public ushort Machine; // 4 public ushort NumberOfSections; // 6 public uint TimeDateStamp; // 8 public uint PointerToSymbolTable; public uint NumberOfSymbols; public ushort SizeOfOptionalHeader; public ushort Characteristics; } */ }