From 97b437be866c80fecb4866edf87756c8b1ce8b45 Mon Sep 17 00:00:00 2001 From: aaronatp <58194911+aaronatp@users.noreply.github.com> Date: Mon, 13 Nov 2023 22:02:31 -0800 Subject: [PATCH] Function for handling Unsupported Exceptions --- capa/helpers.py | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/capa/helpers.py b/capa/helpers.py index 38f94b028..a9fd3f8dc 100644 --- a/capa/helpers.py +++ b/capa/helpers.py @@ -126,33 +126,28 @@ def new_print(*args, **kwargs): inspect.builtins.print = old_print # type: ignore -def log_unsupported_format_error(): - logger.error("-" * 80) - logger.error(" Input file does not appear to be a PE or ELF file.") - logger.error(" ") - logger.error( - " capa currently only supports analyzing PE and ELF files (or shellcode, when using --format sc32|sc64)." - ) - logger.error(" If you don't know the input file type, you can try using the `file` utility to guess it.") - logger.error("-" * 80) - - -def log_unsupported_os_error(): - logger.error("-" * 80) - logger.error(" Input file does not appear to target a supported OS.") - logger.error(" ") - logger.error( - " capa currently only supports analyzing executables for some operating systems (including Windows and Linux)." - ) - logger.error("-" * 80) - - -def log_unsupported_arch_error(): - logger.error("-" * 80) - logger.error(" Input file does not appear to target a supported architecture.") - logger.error(" ") - logger.error(" capa currently only supports analyzing x86 (32- and 64-bit).") - logger.error("-" * 80) +def raise_log_unsupported_error(e): + if e = UnsupportedFormatError: + logger.error("-" * 80) + logger.error(" Input file does not appear to be a PE or ELF file.") + logger.error(" ") + logger.error(" capa currently only supports analyzing PE and ELF files (or shellcode, when using --format sc32|sc64).") + logger.error(" If you don't know the input file type, you can try using the `file` utility to guess it.") + return E_INVALID_FILE_TYPE + + if e = UnsupportedArchError: + logger.error("-" * 80) + logger.error(" Input file does not appear to target a supported architecture.") + logger.error(" ") + logger.error(" capa currently only supports analyzing x86 (32- and 64-bit).") + return E_INVALID_FILE_ARCH + + if e = UnsupportedOSError: + logger.error("-" * 80) + logger.error(" Input file does not appear to target a supported OS.") + logger.error(" ") + logger.error(" capa currently only supports analyzing executables for some operating systems (including Windows and Linux).") + return E_INVALID_FILE_OS def log_unsupported_runtime_error():