|
pefile: parsing version information from the resources directory
A while ago I got some inquiries on how to go about reading the version information stored in PE files. I had an idea of it being just a bunch of unicode strings without much of a structure but to follow along the rest of the PE file format, it does indeed have some structure. The only inconvenient was to find proper resources on how to parse it as Microsofts docs mainly amount to, understandably, "just use the API". I eventually found a couple of references where a parser for the version information stored with a Portable Executables resources directory was implemented. After finally understanding how that information was stored, I added support in pefile so now a dictionary is conveniently returned whenever parseable version information exists in a PE file. Some of the links in which I based my parsing implementation are:
From those last two links one can follow into definitions for the other structures. Now, before I forget how this all goes. The version info structure in composed of a list of substructures. Those substructures can be of StringFileInfo or VarFileInfo type. The former contains the usual textual information that can be seen on the Version tab on the Properties dialog for a PE image. The later specifies version information in a way that does not depend on the language and codepage. ![]() StringFileInfo contains a list of StringTable structures and each of those contains a String structure. This last structure contains the Key, Value pairs that make for the textual version information. VarFileInfo contains a list of Var structures (although normally is only one) and each of those contains a list of pairs of Word values with version information.
ExampleIf the file has version information, the following attributes will exist in the PE instance returned.
This should come quite handy, for instance, to people interested in creating databases of version information of collections of DLLs and EXEs... Comments
| ||||||||