icoextract
icoextract is an icon extractor library for Windows executables (.exe/.dll/.mun). It also includes a thumbnailer script (exe-thumbnailer) for Linux desktops.
This project is inspired by extract-icon-py, icoutils, and others.
Installation
Dependencies
- Python 3.10+
- pefile
- Pillow - optional, for exe-thumbnailer
- nefile - optional, for Win16 / NE EXE support
Installing from source
You can install the project via pip: pip3 install icoextract[thumbnailer], or
the Git repo at https://github.com/jlu5/icoextract
On Linux, you can enable the thumbnailer by copying exe-thumbnailer.thumbnailer into the thumbnailers directory:
/usr/local/share/thumbnailers/if you installed icoextract globally~/.local/share/thumbnailersif you installed icoextract for your user only
The thumbnailer should work with any file manager that implements the Freedesktop Thumbnails Standard: this includes Nautilus, Caja, Nemo, Thunar (when Tumbler is installed), and PCManFM. KDE / Dolphin uses a different architecture and is not supported here.
Distribution packages
You can install icoextract from any of these distribution repositories:
Usage
Note: recent versions of Windows (Windows 10 1903+) have moved icons from system libraries (shell32.dll, etc.) into a new C:\Windows\SystemResources folder. icoextract can extract these .mun files natively, but the .dlls themselves no longer contain icons.
icoextract CLI
icoextract ships icoextract and icolist scripts to extract and list icon resources inside a file.
usage: icoextract [-h] [-V] [-n NUM] [-i ID] [-v] input output
Windows executable icon extractor.
positional arguments:
input input filename (.exe/.dll/.mun)
output output filename (.ico)
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-n, --num NUM index of icon to extract
-i, --id ID resource ID of icon to extract
-v, --verbose enables debug logging
usage: icolist [-h] [-V] [-v] input
Lists group icons present in a program.
positional arguments:
input input filename
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-v, --verbose enables debug logging
Using icoextract as a Library
from icoextract import IconExtractor, IconExtractorError
try:
extractor = IconExtractor('/path/to/your.exe')
# Export the first group icon to a .ico file
extractor.export_icon('/path/to/your.ico', num=0)
# Or read the .ico into a buffer, to pass it into other code
data = extractor.get_icon(num=0)
from PIL import Image
im = Image.open(data)
# ... manipulate a copy of the icon
# In icoextract 0.2.0+, you can also extract icons by resource ID
extractor.export_icon('/path/to/your.ico', resource_id=1234)
except IconExtractorError:
# No icons available, or the icon resource is malformed
pass
IconExtractor factory function.
When exe_type is set to AUTO, this will return an icoextract.pe_extractor.PEIconExtractor
for Win32/Win64 PE executables and an icoextract.ne_extractor.NEIconExtractor for Win16 NE
executables.
Superclass for exceptions raised by IconExtractor.
Exception raised when extracting an icon index or resource ID that does not exist.
Exception raised when the input program has no icon resources.
Exception raised when the input program has an invalid icon resource.
Exception raised when the executable type is invalid or not supported.
Enum for supported executable formats.