views:

922

answers:

3

I need to parse the file version and product version from windows exe and msi files.

Could you point me to the file specification or the library (preferably in Java) that does that?

UPDATE:

It turns out I cannot use winapi, as the code needs to run on linux as well...

+1  A: 

You could use GetFileVersionInfoSize and GetFileVersionInfo functions to get file version and product version. I'm not guru in Java but as far as I know there is the possibility to use WinAPI functions.

Kirill V. Lyadvinsky
I thought about it, but would like to avoid that...
ya23
A: 

I have a Delphi program which can analyze PE/NE headers in Windows EXE files - but not right here. I think it can be ported to Java easily as it does a binary analysis of the files.

Of course, using a JNA calls to Windows API could do the trick on Windows.

Edit: I found it, but there are some minor glitches:

  • The original aim of the program was to extract resources from EXE (PE/NE) files, as at the time the available resource editors only worked with the PE format (NE is used by Win3.1)
  • The UI does not display the version info, but the record structure is there for it
  • The UI is entirely in Hungarian, I can provide translation if needed
  • Some of the code comments are in Hungarian, except some record structure descriptions, which are in English
  • I don't know if it compiles or not by its own today.
  • The ZIP includes a compiled Win32 RESXPLOR.EXE
  • The code has some buffer overrun bugs here or there - should be easily to fix it in Java
kd304
Did you write it? If so, which spec did you use? Yeah, porting from Delphi wouldn't be a problem.
ya23
100% own code, but since I moved to Java 4 years ago, I don't keep my old stuff in a fast reachable place. It was developed around 2001 I think, and I read the file format specifications on various sites (wotsit.org, etc.). It was not just the analizer but the attached tree-viewed GUI. I can get it for you but only about 10 hours from now. And if you port it to java, consider making it open-source.
kd304
A: 

with JNA is straightforward using GetFileVersionInfo.
Check this tutorial to get started.

dfa