Package icoextract
Windows Portable Executable (PE) icon extractor.
For help on icoextract's frontend scripts, see icoextract --help and icolist --help.
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
Classes
- class IconExtractor (filename=None, data=None)
- 
Loads an executable from the given filenameordata(raw bytes). As with pefile, if bothfilenameanddataare given,filenametakes precedence.If the executable has contains no icons, this will raise NoIconsAvailableError.Methods- def export_icon(self, filename, num=0, resource_id=None)
- 
Exports ICO data for the requested group icon to filename.Icons can be selected by index ( num) or resource ID. By default, the first icon in the binary is exported.
- def get_icon(self, num=0, resource_id=None) ‑> _io.BytesIO
- 
Exports ICO data for the requested group icon as a io.BytesIOinstance.Icons can be selected by index ( num) or resource ID. By default, the first icon in the binary is exported.
- def list_group_icons(self) ‑> list[tuple[int, int]]
- 
Returns all group icon entries as a list of (resource ID, offset) tuples. 
 
- class IconExtractorError (*args, **kwargs)
- 
Superclass for exceptions raised by IconExtractor. Ancestors- builtins.Exception
- builtins.BaseException
 Subclasses
- class IconNotFoundError (*args, **kwargs)
- 
Exception raised when extracting an icon index or resource ID that does not exist. Ancestors- IconExtractorError
- builtins.Exception
- builtins.BaseException
 
- class InvalidIconDefinitionError (*args, **kwargs)
- 
Exception raised when the input program has an invalid icon resource. Ancestors- IconExtractorError
- builtins.Exception
- builtins.BaseException
 
- class NoIconsAvailableError (*args, **kwargs)
- 
Exception raised when the input program has no icon resources. Ancestors- IconExtractorError
- builtins.Exception
- builtins.BaseException