Commit 9c3234cd by heffnercj

Fixed bugs in csv log output

parent 56f5f34b
......@@ -489,8 +489,8 @@ def main():
if format_to_terminal:
bwalk.display.enable_formatting(True)
# Enable log file CSV formatting, if specified
if do_csv:
# Enable log file CSV formatting, if specified and supported for all the requested scan types
if do_csv and binwalk.Binwalk.BINCAST not in requested_scans and binwalk.Binwalk.HEXDIFF not in requested_scans:
bwalk.display.enable_csv()
# If no scan was explicitly rquested, do a binwalk scan
......
......@@ -86,13 +86,13 @@ class PrettyPrint:
self.fp = None
def _log(self, data):
def _log(self, data, raw=False):
'''
Log data to the log file.
'''
if self.fp is not None:
if self.log_csv and self.csv:
if self.log_csv and self.csv and not raw:
data = data.replace('\n', ' ')
while ' ' in data:
......@@ -219,9 +219,10 @@ class PrettyPrint:
md5sum = self._file_md5(file_name)
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if self.log_csv:
if self.csv:
nolog = True
self._pprint("%s %s %s" % (file_name, md5sum, timestamp), noprint=True)
self.csv.writerow(["FILE", "MD5SUM", "TIMESTAMP"])
self.csv.writerow([file_name, md5sum, timestamp])
self._pprint("\n")
self._pprint("Scan Time: %s\n" % timestamp, nolog=nolog)
......@@ -239,17 +240,22 @@ class PrettyPrint:
Returns None.
'''
nolog = False
if self.verbose and file_name is not None:
self.file_info(file_name)
if self.log_csv:
nolog = True
self._pprint("\n")
if not header:
self._pprint("DECIMAL \tHEX \t%s\n" % description)
self._pprint("DECIMAL \tHEX \t%s\n" % description, nolog=nolog)
else:
self._pprint(header + "\n")
self._pprint(header + "\n", nolog=nolog)
self._pprint("-" * self.HEADER_WIDTH + "\n")
self._pprint("-" * self.HEADER_WIDTH + "\n", nolog=nolog)
def footer(self, bwalk=None, file_name=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