Compiled date to string


Author: Dave
Date: 05.03.12 - 2:43am



Quick example of turning the time stamp embedded in an executable into a human readable string using vb6.

This code has just been integrated into my pe editor classes as well.
Private Sub Form_Load()
    Dim s, s2, d As Date
    s = timeStampToDate(&H5E1FC7C2) '= Jan 16 2020 2:17:38
    d = CDate(s)
    s2 = Hex(DatetoTimeStamp(d)) '= &H5E1FC7C2
End Sub

Property Get timeStampToDate(timestamp As Long) As String

    On Error Resume Next
    Dim base As Date
    Dim compiled As Date
    
    base = DateSerial(1970, 1, 1)
    compiled = DateAdd("s", timestamp, base)
    timeStampToDate = Format(compiled, "mmm d yyyy h:nn:ss")

End Property

Function DatetoTimeStamp(d As Date) As Long

    On Error Resume Next
    Dim base As Date
    Dim compiled As Date
    
    base = DateSerial(1970, 1, 1)
    DatetoTimeStamp = DateDiff("s", base, d)

End Function


Of for a standalone version: (x64 safe)

Function GetCompileTime(Optional ByVal exe As String) As String
    
    Dim f As Long, i As Integer
    Dim stamp As Long, e_lfanew As Long
    Dim base As Date, compiled As Date

    On Error GoTo errExit
    
    If Len(exe) = 0 Then
        exe = App.Path & "" & App.EXEName & ".exe"
    End If
    
    FileLen exe 'throw error if not exist
    
    f = FreeFile
    Open exe For Binary Access Read As f
    Get f, , i
    
    If i <> &H5A4D Then GoTo errExit 'MZ check
     
    Get f, 60 + 1, e_lfanew
    Get f, e_lfanew + 1, i
    
    If i <> &H4550 Then GoTo errExit 'PE check
    
    Get f, e_lfanew + 9, stamp
    Close f
    
    base = DateSerial(1970, 1, 1)
    compiled = DateAdd("s", stamp, base)
    GetCompileTime = Format(compiled, "ddd, mmm d yyyy, h:nn:ss ")
    
    Exit Function
errExit:
    Close f
        
End Function





Comments: (1)

On 03.19.20 - 11:27am qvb6 wrote:
Thread: Epoch Time to VB6 Date

Because your code takes a Long, it will stop working on Jan 19, 2038 when the number of seconds exceeds 2G limit(2^31-1=2147483647), but its easy to modify to accept a Double or a Variant with Decimal sub type. Also, DateAdd/DateDiff never takes into account daylight saving, but you are dealing with UTC, which is fine.

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 39 + 36 = ? followed by the letter: A 



About Me
More Blogs
Main Site
Posts: (All)
2020 ( 2 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 ( 22 )
2015 ( 16 )
2014 ( 25 )
2013 ( 4 )
2012 (10)
     VC 2008 Bit Fields
     Speed trap
     C# Db Class Generator
     VB6 vrs .NET (again)
     FireFox Whois Extension
     git and vb6
     Code Additions
     Compiled date to string
     C# ListView Sorter
     VB6 Wish List
2011 (7)
     C# Process Injection
     CAPTCHA Bots
     C# PE Offset Calculator
     VB6 Async Download
     Show Desktop
     coding philosophy
     Code release
2010 ( 11 )
2009 ( 3 )