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

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 filename or data (raw bytes). As with pefile, if both filename and data are given, filename takes precedence.

If the executable has contains no icons, this will raise NoIconsAvailableError.

Methods

def export_icon(self, filename, num=0)

Exports ICO data for the requested group icon (num) to filename.

def get_icon(self, num=0)

Exports ICO data for the requested group icon (num) as a io.BytesIO instance.

def list_group_icons(self)

Returns all group icon entries as a list of (name, offset) tuples.

class IconExtractorError (*args, **kwargs)

Superclass for exceptions raised by IconExtractor.

Ancestors

  • builtins.Exception
  • builtins.BaseException

Subclasses

class InvalidIconDefinitionError (*args, **kwargs)

Exception raised when the input program has an invalid icon resource.

Ancestors

class NoIconsAvailableError (*args, **kwargs)

Exception raised when the input program has no icon resources.

Ancestors