mpmcgill has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I am using pp (with the latest version of Strawberry perl 5.24 64bit on Windows) to build an executable out of my code. There are various references to the ability to set the Windows executable header with 10 specific resource tags including LegalCopyright and ProductVersion. One of the references is here: http://search.cpan.org/~autrijus/PAR-0.85_01/script/pp I have installed the latest version of pp and this feature which the docs say is invoked using --info does not exist in my pp.

pp itself works well and produces functional executable for systems without perl installed, but my employer wants the LegalCopyright and ProductVersion to be set. I have tried various external tools like "Resource Hacker", but they seem to mess up the generated executable and I get many of the following messages:

at -e line 631. format error: bad signature: 0x08000000 at offset 11057307 in file my-executable.exe

I suspect the errors have to to with the compressed nature of a pp generated executable, but the bottom line is I need a way of setting these Windows executable resource tags.

Thanks in advance,

Michael McGill
  • Comment on pp and setting Windows LegalCopyright in executable header

Replies are listed 'Best First'.
Re: pp and setting Windows LegalCopyright in executable header
by stevieb (Canon) on Dec 06, 2016 at 19:49 UTC

    Note that the link to the pp software is for version 0.85_01 (which is a trial version and very old), and the most recent version (pp) doesn't have the --info flag.

    There's a note in this entry in the Changes file that states that option was removed. Perhaps you could try installing a version that's less than version 1.018 where that change was introduced?

    update: Here's a link to the 1.017 version tarball file that does contain the --info flag.

Re: pp and setting Windows LegalCopyright in executable header
by Marshall (Canon) on Dec 06, 2016 at 22:45 UTC
    I think what you want to do is add info to the Windows Info that you will get by right clicking..then selecting Properties on an exe file. I played with some of my Win .exe files just to see what kind of Info is in there...Mileage varies.

    I investigated this further for my own edification. The most promising and direct way that I found was at stackoverflow version info for a dll.

    The most relevant post says:

    While it's not a batch process, Visual Studio can also add/edit file resources. Just use File->Open->File on the .EXE or .DLL. This is handy for fixing version information post-build, or adding it to files that don't have these resources to begin with.
    I do not have Visual Studio on the machine I'm using for this message. But that looks like a a hint to an extremely promising way to modify the .exe header so that Windows can read it. I don't know what went wrong with "Resource Hacker", but if MS Visual Studio can do this, that is the way to go. After all this is an MS format! Wish you well! Let us know if this idea works...
Re: pp and setting Windows LegalCopyright in executable header
by mpmcgill (Novice) on Dec 07, 2016 at 13:21 UTC

    Marshall is right. What I want is to have information displayed when viewing the properties from Windows explorer. I have tried most of the options suggested in the stackoverflow "version info for dll" post with little success.

    I agree that the problem is in Win32::Exe which, as noted above, has not been updated since 2011. I also agree that the Windows PE (Portable Executable) format is complicated. The reason the --info feature was removed from pp is because it did not work which is because Win32::Exe breaks the executable when used.

    I was using ActiveStates PDK which does work very well, but I am trying to find a purely open source solution. As to Visual Studio, I hate to use MS software on a perl project

      Sounds to my like you've tried all the "usual suspects".

      I was going to suggest the Active State PDK (Perl Dev Kit), but I went to the AS website and evidently they no longer sell licenses as a standalone product. That vastly increases the cost. I bought a license 15+ years ago, sure hope that I can continue to get updates because this thing works amazingly well with many features that the open source packaging tools don't have.

      I think you are probably aware of this, but for others, here is the official link to the PE spec: MS PE/COFF specification. Yes, it is complex. I suspect that some sort of checksum or what MS calls the Authenticode PE Image Hash is not being updated correctly. That sounds it would cause the "exe actually works, but throws a bunch of error msgs" problem.

      There is a report from stevieb that VS 2013 has some sort of issue with modifying the .exe header information. That surprised me. Whether or not VS would work in your situation probably has to do with the compiler,linker,etc that you are using to generate the .exe.

      I don't know how interested you are (meaning how much work you want to put into this), but since the specs are public information, an effort to update the appropriate Perl module would in theory succeed. I would be willing to assist.

      I am not sure if you are aware, and I am def not up to par on PE formatting, but I do think there is some form of checksum and by modifying just one byte of the exectuable will can render it useless.

      I just attempted to modify this information in a pp'd binary with Visual Studio 2013 by opening the exe and attempting to edit the VERSION tag information. It works when you check properties of the file, but the file becomes corrupted and no longer Does The Right Thing.

        That is the behaviour I have seen with all the tools for changing the exe header I have tried. The properties change, but the executable becomes corrupted with messages that look like:

        format error: bad signature: 0x00004000 at offset 5069472 in file <my-file>

        Oddly the executable appears to work, but these messages are a problem and may indicate a larger underlying issue.

Re: pp and setting Windows LegalCopyright in executable header
by Anonymous Monk on Dec 07, 2016 at 02:20 UTC
    Its "simple", fix Win32::Exe, then use exe_update.pl :)
      Good Joke. I looked at the .exe format and it is not so easy to muck around with!

        Good Joke. I looked at the .exe format and it is not so easy to muck around with!

        :) its not a joke, thats the module PAR used for those features, and it hasn't been updated since 2011

Re: pp and setting Windows LegalCopyright in executable header
by james28909 (Deacon) on Dec 07, 2016 at 03:41 UTC
    There is also the PDK (perl Dev Kit) from Active State Perl. I use the heck out of it all the time and it has never failed me. Unfortunately it is not free though. I do have it and if you want, I can pack up your script for you and add these infos too. If your interested shoot me message and ill get back to you asap.

      Your post has been considered: "invitation to piracy? If so, vote reap." (see "Nodes to consider").

      I didn't think piracy was your intent and voted "edit"; however, having done so, I found I was alone in this and all other votes were "reap".

      To avoid having your post removed altogether, I'd recommend you edit the "pack it up" part in such a way that it doesn't suggest packing up the PDK but rather the OP's executable. I believed that was your intent and this was reinforced by the fact that you were offering to do the work yourself: "i can ... add these infos for you.".

      The reason I voted "edit", instead of "keep", was mainly because you'd included your email address. Please remove it and replace with "/msg" or similar. Whatever information (email addresses, phone numbers, etc.) that you choose to share in a private message is your business. See "How (Not) To Ask A Question: Don't Give Us Your Email Address" for further details about this.

      By the way, I upvoted your post. I thought it was a nice offer (albeit, perhaps, badly worded).

      — Ken

        I do apologize. In no way was I saying I was going to share or give any software. I were referring to packaging up the script for the OP to have an executable and NOT referring to packaging up the PDK. I think the OP ended up going another route anyway. Sorry for the confusion, I'll go back and edit the post to make it clear.