From d26897afca6bc229e870ece63487e427a5cc7583 Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Mon, 6 May 2024 12:35:53 +0200 Subject: [PATCH] capabilities: don't show progress bar when stderr is redirected to a file --- capa/capabilities/dynamic.py | 5 +++++ capa/capabilities/static.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/capa/capabilities/dynamic.py b/capa/capabilities/dynamic.py index 9cc8e2f4..717fe248 100644 --- a/capa/capabilities/dynamic.py +++ b/capa/capabilities/dynamic.py @@ -6,6 +6,7 @@ # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. +import sys import logging import itertools import collections @@ -146,6 +147,10 @@ def find_dynamic_capabilities( # to disable progress completely def pbar(s, *args, **kwargs): return s + elif not sys.stderr.isatty(): + # don't display progress bar when stderr is redirected to a file + def pbar(s, *args, **kwargs): + return s processes = list(extractor.get_processes()) diff --git a/capa/capabilities/static.py b/capa/capabilities/static.py index 3f2f3c25..a66aa842 100644 --- a/capa/capabilities/static.py +++ b/capa/capabilities/static.py @@ -6,6 +6,7 @@ # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. +import sys import time import logging import itertools @@ -155,6 +156,10 @@ def find_static_capabilities( # to disable progress completely def pbar(s, *args, **kwargs): return s + elif not sys.stderr.isatty(): + # don't display progress bar when stderr is redirected to a file + def pbar(s, *args, **kwargs): + return s functions = list(extractor.get_functions()) n_funcs = len(functions)