in reply to Getting compile time out of Windows binary (exe and dll) files

Update: A somewhat more robust version. It correctly handles all but a dozen or so of the 6000+ exes and dlls on my system, though a couple of dozen more have timestamps well in the future (which is noted).

#! perl -slw use strict; open EXE, '<:raw', $ARGV[0] or die "$ARGV[0] : $!"; my $dos = do{ local $/ = \65536; <EXE> }; die "$ARGV[0] is not a .exe or .dll (sig='${ \substr $dos, 0, 2 }')" unless substr( $dos, 0, 2 ) eq 'MZ'; my $coffoff = 8+ unpack 'x60 V', $dos; read( EXE, $dos, $coffoff - 65536 + 4, 65536 ) or die $! if $coffoff > 65536; my $ts = unpack "x$coffoff V", $dos; print "$ARGV[0] : ", scalar( localtime $ts) || "has unfathomable times +tamp value $ts" );

Try this

#! perl -slw use strict; open EXE, '<:raw', $ARGV[0] or die "$ARGV[0] : $!"; my $dos = do{ local $/ = \1024; <EXE> }; die "$ARGV[0] is not a .exe or .dll" unless substr( $dos, 0, 2 ) eq 'M +Z'; my $coffoff = 8+ unpack 'x60 V', $dos; my $ts = unpack "x$coffoff V", $dos; print scalar localtime $ts; __END__ C:\cl>p:exetime.pl atlprov.dll Sat Jan 5 11:46:16 2002 C:\cl>p:exetime.pl cl.exe Sat Jan 5 10:48:19 2002

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Getting compile time out of Windows binary (exe and dll) files
by jira0004 (Monk) on Aug 17, 2005 at 16:13 UTC

    Thanks alot this is really very helpful. This extracts that embedded time stamp just like I wanted!

    Thanks, again,

    Sincerely

    Peter Jirak

    jira0004@yahoo.com