Commit 54ad5c58 by devttys0

Consolidated warning messages

parent 30216cc8
......@@ -25,6 +25,18 @@ def debug(msg):
sys.stderr.write("DEBUG: " + msg + "\n")
sys.stderr.flush()
def warning(msg):
'''
Prints warning messages to stderr
'''
sys.stderr.write("\nWARNING: " + msg + "\n\n")
def error(msg):
'''
Prints error messages to stderr
'''
sys.stderr.write("\nERROR: " + msg + "\n\n")
def file_md5(file_name):
'''
Generate an MD5 hash of the specified file.
......
......@@ -2,6 +2,7 @@ import io
import re
import os.path
import tempfile
import binwalk.core.common
from binwalk.core.compat import *
from binwalk.core.filter import FilterType
......@@ -150,7 +151,7 @@ class MagicParser(object):
if os.path.exists(fname):
self.parse_file(fname)
else:
sys.stdout.write("WARNING: Magic file '%s' does not exist!\n" % fname)
binwalk.core.common.warning("Magic file '%s' does not exist!" % fname)
self.fd.seek(0)
return self.fd.name
......
......@@ -2,6 +2,7 @@ import os
import sys
import imp
import inspect
import binwalk.core.common
import binwalk.core.settings
from binwalk.core.compat import *
......@@ -124,7 +125,7 @@ class Plugins(object):
except KeyboardInterrupt as e:
raise e
except Exception as e:
sys.stderr.write("WARNING: %s.%s failed: %s\n" % (callback.__module__, callback.__name__, e))
binwalk.common.core.warning("%s.%s failed: %s" % (callback.__module__, callback.__name__, e))
def _find_plugin_class(self, plugin):
for (name, klass) in inspect.getmembers(plugin, inspect.isclass):
......@@ -186,7 +187,7 @@ class Plugins(object):
except KeyboardInterrupt as e:
raise e
except Exception as e:
sys.stderr.write("WARNING: Error loading plugin '%s': %s\n" % (file_name, str(e)))
binwalk.common.core.warning("Error loading plugin '%s': %s" % (file_name, str(e)))
plugins[key]['enabled'][module] = False
try:
......@@ -243,7 +244,7 @@ class Plugins(object):
except KeyboardInterrupt as e:
raise e
except Exception as e:
sys.stderr.write("WARNING: Failed to load plugin module '%s': %s\n" % (module, str(e)))
binwalk.common.core.warning("Failed to load plugin module '%s': %s" % (module, str(e)))
def pre_scan_callbacks(self, obj):
return self._call_plugins(self.pre_scan, None)
......
......@@ -4,6 +4,7 @@ import sys
import shlex
import tempfile
import subprocess
import binwalk.core.common
from binwalk.core.compat import *
from binwalk.core.module import Module, Option, Kwarg
from binwalk.core.common import file_size, unique_file_name, BlockFile
......@@ -539,7 +540,7 @@ class Extractor(Module):
except KeyboardInterrupt as e:
raise e
except Exception as e:
sys.stderr.write("WARNING: Extractor.execute failed to run internal extractor '%s': %s\n" % (str(cmd), str(e)))
binwalk.core.common.warning("Extractor.execute failed to run internal extractor '%s': %s" % (str(cmd), str(e)))
else:
# If not in verbose mode, create a temporary file to redirect stdout and stderr to
if not self.config.verbose:
......@@ -560,7 +561,7 @@ class Extractor(Module):
# making the switch to the new firmware mod kit directory structure. We handle this elsewhere, but it's
# annoying to see this spammed out to the console every time.
if self.config.verbose or (not hasattr(e, 'errno') or e.errno != 2):
sys.stderr.write("WARNING: Extractor.execute failed to run external extrator '%s': %s\n" % (str(cmd), str(e)))
binwalk.core.common.warning("Extractor.execute failed to run external extrator '%s': %s" % (str(cmd), str(e)))
retval = None
if tmp is not None:
......
......@@ -190,7 +190,7 @@ class HashMatch(Module):
else:
return self.lib.fuzzy_compare(hash1, hash2)
except Exception as e:
print ("WARNING: Exception while doing fuzzy hash: %s" % e)
binwalk.core.common.warning("Exception while doing fuzzy hash: %s" % str(e))
return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment