3

With an eye toward extracting all of the sizes of an icon (ICO file) as PNG images from an EXE file, I noticed that Wine appears to do this automatically.

After the installation of foobar2000, Wine (I presume) had created a Desktop Entry at ~/.local/share/applications/wine/Programs/foobar2000.desktop, containing the following content:

[Desktop Entry]
Name=foobar2000
Exec=env WINEPREFIX="$HOME/.wine" wine C:\\\\windows\\\\command\\\\start.exe /Unix "$HOME/.wine/dosdevices/c:/users/Public/Start\\ Menu/Programs/foobar2000.lnk"
Type=Application
StartupNotify=true
Comment=Play, organize and tag your music.
Path=$HOME/.wine/dosdevices/c:/Program Files (x86)/foobar2000
Icon=3C17_foobar2000.0

Eventually, the Icon key caught my eye, and I discovered that it resolved according to the Icon Theme Specification. Hunting around, I found the directories ~/local/share/icons/hicolor/*/apps/ which contained the files for these icons (each folder containing 3C17_foobar2000.0.png), again which I presume Wine created.

My question is how did Wine generate these image files from the application (or shortcut file)?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
palswim
  • 4,919
  • 6
  • 37
  • 53
  • I think this is really a "how does the [Portable Executable file format](https://en.wikipedia.org/wiki/Portable_Executable) work" question (or maybe a programming/library one?). – Michael Homer Mar 29 '19 at 04:33

1 Answers1

4

Wine includes a winemenubuilder program which takes care of this: it takes a Windows shortcut, and creates a matching FDO (FreeDesktop.Org) .desktop file. Icon extraction is part of this, handled by the open_module_icon and related functions. To extract icons, winemenubuilder finds the executable corresponding to the shortcut (optionally waiting for it to be created, if necessary), and loads the resources it contains using Wine’s LoadResource function, finds the icons, and converts them to an appropriate image format.

wine winemenubuilder /path/to/link.lnk

will convert the link to a .desktop file, in ~/.local/share/applications/wine/Programs, and extract the available icons, convert them, and store them in the appropriate subdirectories of ~/.local/share/icons. (I think /path/to/link.lnk has to be accessible using Wine’s drive mappings; it works well with .lnk files which have been installed in Wine.)

wine winemenubuilder -t /path/to/link.lnk /path/to/icon.png

will extract the first icon in the executable pointed at by link.lnk to icon.png.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164