Commit 54ad5c58 by devttys0

Consolidated warning messages

parent 30216cc8
...@@ -25,6 +25,18 @@ def debug(msg): ...@@ -25,6 +25,18 @@ def debug(msg):
sys.stderr.write("DEBUG: " + msg + "\n") sys.stderr.write("DEBUG: " + msg + "\n")
sys.stderr.flush() 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): def file_md5(file_name):
''' '''
Generate an MD5 hash of the specified file. Generate an MD5 hash of the specified file.
......
...@@ -2,6 +2,7 @@ import io ...@@ -2,6 +2,7 @@ import io
import re import re
import os.path import os.path
import tempfile import tempfile
import binwalk.core.common
from binwalk.core.compat import * from binwalk.core.compat import *
from binwalk.core.filter import FilterType from binwalk.core.filter import FilterType
...@@ -150,7 +151,7 @@ class MagicParser(object): ...@@ -150,7 +151,7 @@ class MagicParser(object):
if os.path.exists(fname): if os.path.exists(fname):
self.parse_file(fname) self.parse_file(fname)
else: 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) self.fd.seek(0)
return self.fd.name return self.fd.name
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
import sys import sys
import imp import imp
import inspect import inspect
import binwalk.core.common
import binwalk.core.settings import binwalk.core.settings
from binwalk.core.compat import * from binwalk.core.compat import *
...@@ -124,7 +125,7 @@ class Plugins(object): ...@@ -124,7 +125,7 @@ class Plugins(object):
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as 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): def _find_plugin_class(self, plugin):
for (name, klass) in inspect.getmembers(plugin, inspect.isclass): for (name, klass) in inspect.getmembers(plugin, inspect.isclass):
...@@ -186,7 +187,7 @@ class Plugins(object): ...@@ -186,7 +187,7 @@ class Plugins(object):
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as 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 plugins[key]['enabled'][module] = False
try: try:
...@@ -243,7 +244,7 @@ class Plugins(object): ...@@ -243,7 +244,7 @@ class Plugins(object):
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as 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): def pre_scan_callbacks(self, obj):
return self._call_plugins(self.pre_scan, None) return self._call_plugins(self.pre_scan, None)
......
...@@ -4,6 +4,7 @@ import sys ...@@ -4,6 +4,7 @@ import sys
import shlex import shlex
import tempfile import tempfile
import subprocess import subprocess
import binwalk.core.common
from binwalk.core.compat import * from binwalk.core.compat import *
from binwalk.core.module import Module, Option, Kwarg from binwalk.core.module import Module, Option, Kwarg
from binwalk.core.common import file_size, unique_file_name, BlockFile from binwalk.core.common import file_size, unique_file_name, BlockFile
...@@ -539,7 +540,7 @@ class Extractor(Module): ...@@ -539,7 +540,7 @@ class Extractor(Module):
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as 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: else:
# If not in verbose mode, create a temporary file to redirect stdout and stderr to # If not in verbose mode, create a temporary file to redirect stdout and stderr to
if not self.config.verbose: if not self.config.verbose:
...@@ -560,7 +561,7 @@ class Extractor(Module): ...@@ -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 # 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. # annoying to see this spammed out to the console every time.
if self.config.verbose or (not hasattr(e, 'errno') or e.errno != 2): 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 retval = None
if tmp is not None: if tmp is not None:
......
...@@ -190,7 +190,7 @@ class HashMatch(Module): ...@@ -190,7 +190,7 @@ class HashMatch(Module):
else: else:
return self.lib.fuzzy_compare(hash1, hash2) return self.lib.fuzzy_compare(hash1, hash2)
except Exception as e: 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 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