Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w # # Simple program to extract and dump the version information from a PE +/COFF file # (mostly for Win32 executables, crude implementation) # # I use this program to automagically create ZIP files with the right # filename depending on the version of the executable packaged in them +. # Of course it would be (under Win32) better to question the version A +PI about # the file version, but I am lazy and this is even cross-platform like + that :) # # The whole thing could be made into a module, but again, I wrote this + thing as # a one-off script and only use it in one place... # # This code was written for Perl 5.005 and thus dosen't use # the new (and not completely ironed out) Unicode features # of Perl 5.6. sub MakeUnicode { my ($S) = @_; $S =~ s/(.)/$1\x00/g; return $S; }; sub MakeASCII { my ($S) = @_; $S =~ s/(.)\x00/$1/g; return $S; }; # This is the routine that actually reads the version information into + a hash sub dumpfile { my ($Filename) = @_; my $SearchString = "......" . MakeUnicode("StringFileInfo") . "(?:\x00\x00)+((..)..\x00\x00(?:[0-9A-F]\x00)+?(? +:\x00\x00)+?)". "(.*)"; my %Result = (); open EXE, "< $Filename" or die "Error opening $Filename : $!\n"; binmode EXE; undef $/; $ExeData = <EXE>; # sluuuuurp close EXE; if ($ExeData =~ /$SearchString/gms) { my ($Crap, $Len, $Info) = ($1,$2,$3); undef $ExeData; $Len = unpack( "v", $Len ); $Len = $Len - length( $Crap ) +2; $Info = substr( $Info, 0, $Len ); while ($Info) { my $Sublen; my ($Next, $Value, $Type) = unpack("vvv", substr( $Info, 0, 6 )) +; $Sublen = $Next - 6; while ($Next % 4) { $Next++ }; last unless $Next; my $Item = substr($Info,6,$Sublen); my (@Info) = (); # Extract the key : $Item =~ s/^((?:..)+?)(\x00\x00)+//sm; my ($Key) = MakeASCII( $1 ); while ($Item =~ s/^((?:..)+?)(\x00\x00)+//sm) { push @Info, MakeASCII( $1 ); }; $Result{$Key} = $Info[0]; shift @Info; if ($Next != length( $Info )) { $Info = substr( $Info, $Next ); } else { $Info = ""; }; }; } else { print "StringFileInfo not found in $Filename"; }; return \%Result; }; while ($fn = shift) { $Data = dumpfile( $fn ); print $Data->{ProductVersion} };

In reply to Retrieve Win32 Executable Version information by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2014-09-22 03:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (178 votes), past polls