Repository: mandiant/capa
File: capa/main.py (Python)

Code before:
                    + "https://github.com/mandiant/capa/blob/master/doc/installation.md#method-2-using-capa-as-a-python-library."
                )
                raise IOError(f"signatures path {sigs_path} does not exist or cannot be accessed")
        else:
            sigs_path = Path(args.signatures)
            logger.debug("using signatures path: %s", sigs_path)

        args.signatures = sigs_path


def simple_message_exception_handler(exctype, value: BaseException, traceback: TracebackType):
    """
    prints friendly message on unhandled exceptions to regular users (debug mode shows regular stack trace)

    args:
      # TODO(aaronatp): Once capa drops support for Python 3.8, move the exctype type annotation to
      # the function parameters and remove the "# type: ignore[assignment]" from the relevant place
      # in the main function, see (https://github.com/mandiant/capa/issues/1896)
      exctype (type[BaseException]): exception class
    """

    print(
        f"Unexpected exception raised: {exctype}. Please run capa in debug mode (-d/--debug) "
        + "to see the stack trace. Please also report your issue on the capa GitHub page so we "
        + "can improve the code! (https://github.com/mandiant/capa/issues)"
    )


def main(argv: Optional[List[str]] = None):
    if sys.version_info < (3, 8):
        raise UnsupportedRuntimeError("This version of capa can only be used with Python 3.8+")

    if argv is None:
        argv = sys.argv[1:]

    desc = "The FLARE team's open-source tool to identify capabilities in executable files."
    epilog = textwrap.dedent(
        """
        By default, capa uses a default set of embedded rules.
        You can see the rule set here:
          https://github.com/mandiant/capa-rules

        To provide your own rule set, use the `-r` flag:
          capa  --rules /path/to/rules  suspicious.exe
          capa  -r      /path/to/rules  suspicious.exe

        examples:
          identify capabilities in a binary
            capa suspicious.exe

          identify capabilities in 32-bit shellcode, see `-f` for all supported formats

Review comment (bug):
```suggestion
    if exctype is KeyboardInterrupt:
        print("KeyboardInterrupt detected, program terminated")
    else:
        print(
            f"Unexpected exception raised: {exctype}. Please run capa in debug mode (-d/--debug) "
            + "to see the stack trace. Please also report your issue on the capa GitHub page so we "
            + "can improve the code: https://github.com/mandiant/capa/issues"
        )
```

Code after:
                    + "https://github.com/mandiant/capa/blob/master/doc/installation.md#method-2-using-capa-as-a-python-library."
                )
                raise IOError(f"signatures path {sigs_path} does not exist or cannot be accessed")
        else:
            sigs_path = Path(args.signatures)
            logger.debug("using signatures path: %s", sigs_path)

        args.signatures = sigs_path


def simple_message_exception_handler(exctype, value: BaseException, traceback: TracebackType):
    """
    prints friendly message on unexpected exceptions to regular users (debug mode shows regular stack trace)

    args:
      # TODO(aaronatp): Once capa drops support for Python 3.8, move the exctype type annotation to
      # the function parameters and remove the "# type: ignore[assignment]" from the relevant place
      # in the main function, see (https://github.com/mandiant/capa/issues/1896)
      exctype (type[BaseException]): exception class
    """

    if exctype is KeyboardInterrupt:
        print("KeyboardInterrupt detected, program terminated")
    else:
        print(
            f"Unexpected exception raised: {exctype}. Please run capa in debug mode (-d/--debug) "
            + "to see the stack trace. Please also report your issue on the capa GitHub page so we "
            + "can improve the code! (https://github.com/mandiant/capa/issues)"
        )


def main(argv: Optional[List[str]] = None):
    if sys.version_info < (3, 8):
        raise UnsupportedRuntimeError("This version of capa can only be used with Python 3.8+")

    if argv is None:
        argv = sys.argv[1:]

    desc = "The FLARE team's open-source tool to identify capabilities in executable files."
    epilog = textwrap.dedent(
        """
        By default, capa uses a default set of embedded rules.
        You can see the rule set here:
          https://github.com/mandiant/capa-rules

        To provide your own rule set, use the `-r` flag:
          capa  --rules /path/to/rules  suspicious.exe
          capa  -r      /path/to/rules  suspicious.exe

        examples:
          identify capabilities in a binary