diff --git a/cle/backends/pe/pe.py b/cle/backends/pe/pe.py index f9b72b03..25b7d57f 100644 --- a/cle/backends/pe/pe.py +++ b/cle/backends/pe/pe.py @@ -9,7 +9,11 @@ import archinfo import pefile -import pyxdia + +try: + import pyxdia +except ImportError: + pyxdia = None from cle.address_translator import AT from cle.backends.backend import Backend, FunctionHint, FunctionHintSource, register_backend @@ -215,6 +219,10 @@ def load_symbols_from_pdb(self, pdb_path): """ Load available symbols from PDB at `pdb_path` """ + if pyxdia is None: + log.warning("PDB support is unavailable because pyxdia is not installed") + return + log.debug("Loading symbols from %s", pdb_path) try: pdb = pyxdia.PDB(pdb_path) diff --git a/cle/backends/uefi_firmware.py b/cle/backends/uefi_firmware.py index c93525d2..8301ab92 100644 --- a/cle/backends/uefi_firmware.py +++ b/cle/backends/uefi_firmware.py @@ -8,7 +8,11 @@ from uuid import UUID import archinfo -import uefi_firmware + +try: + import uefi_firmware +except ImportError: + uefi_firmware = None from cle.errors import CLEUnknownFormatError @@ -50,11 +54,15 @@ def _to_bytes(cls, fileobj: io.IOBase): @classmethod def is_compatible(cls, stream): + if uefi_firmware is None: + return False buffer = cls._to_bytes(stream) parser = uefi_firmware.AutoParser(buffer) return parser.type() != "unknown" def __init__(self, *args, **kwargs) -> None: + if uefi_firmware is None: + raise ImportError("The UEFI backend requires the uefi-firmware package") super().__init__(*args, **kwargs) # hack: we are using a loader internal method in a non-kosher way which will cause our children to be diff --git a/pyproject.toml b/pyproject.toml index 54985f3e..0e3f8921 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,9 +25,9 @@ dependencies = [ "pyelftools>=0.29", "pyvex==9.3.1.dev0", "pyxbe~=1.0.3", - "pyxdia~=0.1", + "pyxdia~=0.1; sys_platform != 'emscripten'", "sortedcontainers>=2.0", - "uefi-firmware~=1.16", + "uefi-firmware~=1.16; sys_platform != 'emscripten'", ] [project.readme]