Closed Thread Icon

Topic awaiting preservation: Me again, looking for a way to extract .ico and convert to an web based image format (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=9057" title="Pages that link to Topic awaiting preservation: Me again, looking for a way to extract .ico and convert to an web based image format (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Me again, looking for a way to extract .ico and convert to an web based image format <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 04-01-2004 02:54

Hi peeps,

Well if anybody has been following my recent posts they will know that I have been fiddling around with JScript and Windows Scripting Host in order to develop some added functionality for an intranet I'm working on. I've nailed what I was previously asking about so no probs there.

But I still need to find a way (if possible) to extract the icon from a target exe (it may already be a .ico in some cases, not always an exe), and then convert it to gif, jpeg, png, bmp for display within an HTML page - pretty simple task, many software apps availble to do this. HOWEVER, to make it stupidly more complex the method for extraction and conversion has to be done with some script or application that can run clientside within the context of an HTML page without involving the user having to actively download anything lol.

My original thought was to get the icon location using the built in 'iconLocation' method in 'fileSystemObject', then parse the data stream and convert the resulting mess into a different mess which when saved to the local temp folder with the extension .gif (or whatever) would then be a fully fledged gif I could load into my HTML page. However I don't think this is possible within the confines of the WSH and JScript - I might be wrong, but I can't figure out how it'd work exactly.

So I'm probing your minds for your opinions - could and embedded java applet have the power and technology at it's disposal to extract icons and convert them? Any other ideas? This is a real challenge, and if it's anything like my last thread I probably will get responses

I have to try tho lol.

Thanks guys,

Jon

<A HREF="http://www.cryokinesis.co.uk" TARGET=_blank>visit

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-01-2004 03:20

smonkey: My question may be stupid, why do you want to convert the icons to another format ? The IMG tag supports to have a .ICO file in the SRC attribute. So if you can already find the icon(s) in any file it shouldn't be that hard to extract it in an external file. At worst you'll probably need to retrieve the file size of the .ICO by hand. To do so I suggest you to read the Icons in Win32 article by John Hornick.

If you don't want to, or can not, convert the icons to another format on client side, you could use a sort of remote scripting trick. Put the content of the icon ressource in an hidden textarea and send the form in POST to a PHP script that will convert it with GD and voilà.

Anyway, whenever you serach an information about a file format, have a look at http://www.wotsit.org .

Hope that helps.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 04-01-2004 13:04

Hi Poi,

That was some useful tips you gave, firstly me being a little stupid, I didn't realise that the src attribute of the img tag supports the .ico format (duh), so that is useful, although some icons don't appear particularly attractively in the page (it appears that sometimes ie shows the icons mask rather than the icon itself and Ijust get a weird b/w image).

Also the John Hornick article was interesting although I didn't understand it all that well - is that C code? I couldn't see a way to access icon resources using anything else in that article but, correct me if I'm wrong, C can't be embedded into a web page in any way can it? I dunno exactly how ActiveX controls are created but maybe they can use C? hmmm. Could you explain what it was I was supposed to pick up from that article or was there nothing imparticular, just some general icon resource info?

So anyway, the state of play is that I can embed .ico in pages or if I want better results I could throw them back at the server, convert them (you say GD does this?) and them throw them back. Ok that is good. But what about icons in exe or dll files? any ideas there?

Thanks Poi, I'm glad I did get a response and that it was a positive one.

P.S. how is your site coming along? I keep checking but it is still not up

<A HREF="http://www.cryokinesis.co.uk" TARGET=_blank>visit

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-01-2004 13:13

I wouldn't bet on .ico files being displayed on a mac though. or on linux for that matter.

On the other hand, icos are pretty simple to decode 'by hand' - for example with a php script that could in turn write a bitmap using gd.

Edit: .ico's are simple. Getting icons out of exes and dlls is not so simple.

[This message has been edited by Tyberius Prime (edited 04-01-2004).]

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-01-2004 13:48

Tyberius Prime: Yep, it's quite likely that the putting a .ICO in an IMG tag is not well supported on a Mac but due to the specific aspect of smonkey's project ( an intranet using Jscript, WSH... ) it shouldn't be a problem. Anyway that good to warn about eventual compatibility problems.

smonkey: Yes, indeed that's some C/C++ code in John Hornick's article. But the most important are the 3 first chunks of code describing the data structure of an .ICO file.

code:
typedef struct
{
WORD idReserved; // Reserved (must be 0)
WORD idType; // Resource Type (1 for icons)
[b]WORD idCount; // How many images?
ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) [/b]
} ICONDIR, *LPICONDIR;

typedef struct
{
BYTE bWidth; // Width, in pixels, of the image
BYTE bHeight; // Height, in pixels, of the image
BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
BYTE bReserved; // Reserved ( must be 0)
WORD wPlanes; // Color Planes
WORD wBitCount; // Bits per pixel
[b]DWORD dwBytesInRes; // How many bytes in this resource?
DWORD dwImageOffset; // Where in the file is this image? [/b]
} [b]ICONDIRENTRY [/b], *LPICONDIRENTRY;

typdef struct
{
BITMAPINFOHEADER icHeader; // DIB header
RGBQUAD icColors[1]; // Color table
BYTE icXOR[1]; // DIB bits for XOR mask
BYTE icAND[1]; // DIB bits for AND mask
} ICONIMAGE, *LPICONIMAGE;

With that it should be 'easy' to read the datas of an .ICO file ( even if it's embedded in an .EXE or a .DLL ) and extract the icon you want to do whatever you want in the end. Either save it locally or send its datas to a server side script to convert it to a more common file format like PNG, or GIF.

[edit]

quote:
it appears that sometimes ie shows the icons mask rather than the icon itself and Ijust get a weird b/w image

You're not without knowing that .EXE and .DLL can have an .ICL ( ICon Library ). The iconLocation function returns the position where the ICOs starts in the .EXE or .DLL, but it's quite likely that the first icons are in lower resolution and probably even in 2 colors, or you retrieved the mask of the icon instead of the icon itself. Anyway, with the infos about the .ICO file format all those troubles could be solved.


[/edit]


Regarding my site, some friends pushed me to play Dark Age Of Camelot ( a MMORPG ) so I didn't slept nor worked very much during the last weeks. I did a break recently to finish a poject. I should profit of the occasion to work on my own site It'd rock if I could release the project and my site at the same time.


Cheers,



[This message has been edited by poi (edited 04-01-2004).]

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 04-01-2004 13:49

"I wouldn't bet on .ico files being displayed on a mac though. or on linux for that matter."

No problem, it's a windows only network intranet


"On the other hand, icos are pretty simple to decode 'by hand' - for example with a php script that could in turn write a bitmap using gd."

Well decoding icos and making bitmaps is all good and well, although I'd prefer to have done it clientside utilising any methods available to the JScript/VBScript/WSH I'm starting to believe this isn't possible . Any thoughts on my embedded Java Applet idea? is that a possibility even? I know nothing about Java or Java applets.

Any tips on pulling icos out of an exe or dll clientside tho? I can't really be sending dlls and exes to the intranet server to be processed.

****EDIT****

Poi types fast, post wasn't there a minute ago.

Ok I see the data structure, but that is plain text, and icos or exes are always 'encoded/compressed' in some way, so how do I get to a stage where I can read the plain text structure? I'm sorry if I keep asking dumb questions, but this isn't my area of expertise (I'm not sure exactly what is my area lol, I just know a little bit of lots of things, but not this lol)

Thanks for the continued help, it is really appreciated, I'm close to the end now


[This message has been edited by smonkey (edited 04-01-2004).]

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-01-2004 14:06



According to your first post I assume you can read an .EXE file byte per byte. So you could open an .EXE file, seek to the iconLocation, then read it byte per byte ( or word per word ... ) and decode it accordingly to the .ICO file format.

The 2 first words ( 4 first bytes ) should be : 00 00 01 00
The next word gives the number of icons.
Then you have an array of ICONDIRENTRY ( the thing described in the second typedef struct ).
...


[edit] oops, I'll never get used to the little endian mode [/edit]


[This message has been edited by poi (edited 04-01-2004).]

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 04-01-2004 15:47

Poi, not sure I can read an exe byte per byte - it was something I was hoping was possible with JScript or VBScript but wasn't sure on, should have explained that, d'oh.

I know it can read text streams, but that wont be any good I don't think (this is especially designed for text based files obviously).

The iconLocation method merely returns what file the icon is in and it's position within that files icon library/directory (as far as I understand). It'd look something like this:

C:/path to wherever/myicon.ico,2 (meaning it's the 2 icon in the directory list)

or

C:/path to wherever/myapp.exe,4 (meaning it's the 4 icon in the directory list that is embedded in the exe)

Sometimes it returns no path or position whatsoever I assume that means there is only a single icon embedded in the exe which for some reason can't be located by this method.

But this isn't hugely helpful not to me at least.

Hmm any more ideas?

LOL

Thanks Poi


****EDIT/UPDATE***

Ok after a little chat with a friend two options have presented themselves - the first is Visual Basic, there is code available that can apparently extract icons and make bitmaps:

http://www.freevbcode.com/ShowCode.Asp?ID=374

http://www.freevbcode.com/ShowCode.Asp?ID=5484

http://www.freevbcode.com/ShowCode.Asp?ID=872

http://www.freevbcode.com/ShowCode.Asp?ID=4437

http://www.freevbcode.com/ShowCode.Asp?ID=3367

The problem here is that this code would need to be turned into an ActiveX control that can be installed along with a webpage (prompts aren't a problem). Anybody think this is a real possibility and who also knows a bit about making ActiveX controls?

The second option is basically this:

code:
<iframe src="C:\Documents and Settings\All Users\Start Menu\Programs" width="400" height="400"></iframe>


which creates a direct explorer window in internet explorer - I haven't be able to try this across a network yet tho, and I'm not sure of any possible bugs with it (it apparently sucks in os's other than xp so if anybody is using W2k or NT I woud appreciate a test). Also this method doesn't look brilliant since it has the left 'info' panel that is in most explorer windows. So any ideas on customising this at all would be cool.

Thanks guys

[This message has been edited by smonkey (edited 04-01-2004).]

[This message has been edited by smonkey (edited 04-01-2004).]

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 04-01-2004 21:23

Poi,

Byte by byte you say? if I can convert the app to binary code stream would that be byte per byte?

I have found a VBScript function or few that can do this apparently. It uses a .dll that needs to be registered firts but supplies a VBScript to register the .dll anyway, so I'm thinking I could copy the .dll to teh system directroy using teh methods I already know, then I could register it using the supplied vbscript using methods I already know then it should just be a matter of sending the file to the function and a binary stream should return, and then I can convert back afetr too I think so does that mean I can find the icons in the exes and extract them? (the functions are on www.jsware.net if anyone wants to look)

I would post more examples, but my webhosting has expired and I can't afford anymore - you know any good hosts that might sponsor a young poor student who likes to practice developing and also runs a community art site (or did do until my hosting expired)

Thanks again guys, for a Frenchman Poi you really are pretty cool

****EDIT****
The link more specifically is http://www.jsware.net/jsware/scripts.html#jsbin <---- for the binary vbs functions, I would appreciate somebody who nows a little about binary taking a look since I know nothing about this stuff whatsoever, if anybody cares to explain the jsbin stuff in a bit more detail for me that would be very much appreciated too. Thanks guys, I really really think a lot of you guys, I know I'm a pest at times but please stick with me.

[This message has been edited by smonkey (edited 04-01-2004).]

« BackwardsOnwards »

Show Forum Drop Down Menu