Reading/Parsing an EXE file with Java

Hey guys,Is there a way (in Java) to parse an EXE file and get its version, description, etc? (mostly the information in the VERSION tab inside the file properties window).Thanks.
[200 byte] By [Severus_a] at [2007-11-26 17:46:13]
# 1

Easily. Just use the I/O classes (ByteArrayInputStream) to read the data. I think the real question here is "does anyone know the .EXE file format".

I'd suggest a bit of "Googling" to find the file format; heres one I found without looking too hard http://www.delorie.com/djgpp/doc/exe/ and then using that info to know which bytes to use to create the info you need.

simonkent1a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 2
I guess when I googled my keywords weren't specific enough..Thanks :)Hmm. But how do I get the byte array from a file?And, where's the description and stuff?Message was edited by: Severus_
Severus_a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 3
nvm, I saw -FileInputStream- that seems to do that.But I still don't know how to get the data from the bytes :\
Severus_a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 4
if you have a byte array containing the, say, version then new String(byte[]) will give you a String you can use
simonkent1a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 5
Well yes, but that gives me the same result if I go to notepad and drag the EXE there... I get mixed code that says nothing :\
Severus_a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 6
[url= http://www.windowsitlibrary.com/Content/356/11/1.html]look here[/url] perhaps
georgemca at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 7

> Well yes, but that gives me the same result if I go

> to notepad and drag the EXE there... I get mixed code

> that says nothing :\

Kind of. Except you have know idea what bits to get. With the file format, you need to know where the bits of data you need are structured. Usually, the file will contain some header which gives offsets to other structural 'chunks' of data, one of which will be of interest to you. Read this in and find the offset, move to that offset and read in the 'chunk'. This will contain the data you want. Read in the bytes from the chunk which represent the info you want and pass those bytes into a String. This will then be the version or filename or whatever 'chunk' you have read.

The really hard bit is working out the file format and where your info lies in it. Once you know that, reading the stuff is a breeze.

simonkent1a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 8

I'm sure there are Windows API functions to do this, rather than reinventing the wheel. I'm sure you don't need to read the file in the raw - you're going down the wrong path.

I'm not going to do the research for you though on what the API function(s) are, however I am just giving you a hint that I'm positive they exist. It would be the same API that the properties window uses.

To use that API you'd have to write a C / C++ / other more native language piece of code, which if desired you could wrap in JNI and access it from Java.

warnerjaa at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 9
I found [url= http://www.heaventools.com/]this[/url] and it lets me explore EXE files and get data from them, though I can't find the addresses and all the other stuff on how to get the data manually.I guess using a Windows API will be best. I'll try it and return with results :)
Severus_a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 10

I can't find a thing about that. :(

Perhaps I'll tell you what I need that for:

I got tired of rearranging my start menu and drag-n-droppin' every time I install a new program, so I wanted to create an application that scans a folder of my choice (i.e. c:/progra~1) and creates a folder in the start menu with shortcuts to all of the EXEs in the folder and in its subfolders, arranged by application name (some applications have more than one EXE, including uninstall or update programs) and usage (that I'll do at the end, basing on rules and lists I'll create from DOWNLOAD.COM, for instance). I've done everything but the usage types filtering (putting it into folders: "system", "media", "internet", etc).

So my problem was, that the shortcuts' names are ugly most of the times, and I can't tell the full name of an application just from its filename. For example, Google Earth's main EXE is "googleearth.exe". A shortcut that says "Googleearth" isn't so nice to look at. also, with this kind of name you can know what it does, but what about other filenames that don't exactly say what that file does?

I needed a way to get the -true- name of the application file, and the only way I see is through the properties, in the "Description" field under "Version".

But alas, that's not so simple :P

I thought about simply getting the name from the folder the EXE's in, but then there are more than one EXE per folder.

Any other suggestions will be great.

Thanks again, guys.

Severus_a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...
# 11
What about FileView? Can it be used to get the description of the file?
Severus_a at 2007-7-9 0:14:18 > top of Java-index,Java Essentials,Java Programming...