Commit 50eb5273 by devttys0

Added 3D plotting.

parent 436e5117
......@@ -2,7 +2,9 @@
import sys
import os.path
import binwalk
import binwalk.plotter
import binwalk.cmdopts
import binwalk.plotter
from binwalk.compat import *
from threading import Thread
from getopt import GetoptError, gnu_getopt as GetOpt
......@@ -72,6 +74,7 @@ def main():
matryoshka = 1
block_size = 0
failed_open_count = 0
weight = None
max_extract_size = None
quiet = False
do_comp = False
......@@ -144,6 +147,8 @@ def main():
save_plot = True
elif opt in ("-N", "--no-plot"):
show_plot = False
elif opt in ("-3", "--3D"):
requested_scans.append(binwalk.Binwalk.BINVIS)
elif opt in ("-E", "--entropy"):
requested_scans.append(binwalk.Binwalk.ENTROPY)
elif opt in ("-W", "--diff"):
......@@ -164,6 +169,8 @@ def main():
requested_scans.append(binwalk.Binwalk.STRINGS)
elif opt in ("-O", "--skip-unopened"):
ignore_failed_open = True
elif opt in ("-Z", "--weight"):
weight = binwalk.common.str2int(arg)
elif opt in ("-o", "--offset"):
offset = binwalk.common.str2int(arg)
elif opt in ("-l", "--length"):
......@@ -425,6 +432,10 @@ def main():
r = bwalk.analyze_compression(target_files, offset=offset, length=length)
bwalk.concatenate_results(results, r)
elif scan_type == binwalk.Binwalk.BINVIS:
binwalk.plotter.Plotter3D(target_files, offset=offset, length=length, weight=weight, verbose=verbose).plot()
elif scan_type == binwalk.Binwalk.ENTROPY:
if not results:
......@@ -458,8 +469,8 @@ def main():
pass
except IOError:
pass
# except Exception as e:
# print("Unexpected error: %s" % str(e))
except Exception as e:
print("Unexpected error: %s" % str(e))
bwalk.cleanup()
......
......@@ -61,12 +61,13 @@ class Binwalk(object):
# ENTROPY must be the largest value to ensure it is performed last if multiple scans are performed.
BINWALK = 0x01
BINARCH = 0x02
BINCAST = 0x04
STRINGS = 0x08
COMPRESSION = 0x10
HEXDIFF = 0x20
CUSTOM = 0x40
ENTROPY = 0x80
BINCAST = 0x03
STRINGS = 0x04
COMPRESSION = 0x05
HEXDIFF = 0x06
CUSTOM = 0x07
BINVIS = 0x08
ENTROPY = 0x09
def __init__(self, magic_files=[], flags=magic.MAGIC_NONE, log=None, quiet=False, verbose=0, ignore_smart_keywords=False, ignore_time_skews=False, load_extractor=False, load_plugins=True, exec_commands=True, max_extract_size=None):
'''
......
......@@ -5,8 +5,9 @@ import os
import sys
import binwalk.config
short_options = "AaBbCcdEeGHhIiJkLMNnOPpQqrSTtUuvWwz?D:F:f:g:j:K:o:l:m:R:s:X:x:Y:y:"
short_options = "3AaBbCcdEeGHhIiJkLMNnOPpQqrSTtUuvWwz?D:F:f:g:j:K:o:l:m:R:s:X:x:Y:y:Z:"
long_options = [
"3D",
"rm",
"help",
"green",
......@@ -41,6 +42,7 @@ long_options = [
"no-legend",
"strings",
"carve",
"weight=",
"matryoshka=",
"list-plugins",
"disable-plugins",
......@@ -103,6 +105,11 @@ def usage(fd):
fd.write("\t-J, --save-plot Save plot as an SVG (implied if multiple files are specified)\n")
fd.write("\n")
fd.write("Binary Visualization:\n")
fd.write("\t-3, --3D Generate a 3D visualization\n")
fd.write("\t-Z, --weight Manually set the cutoff weight (lower weight, more data points)\n")
fd.write("\n")
fd.write("Binary Diffing:\n")
fd.write("\t-W, --diff Hexdump / diff the specified files\n")
fd.write("\t-K, --block=<int> Number of bytes to display per line (default: %d)\n" % binwalk.hexdiff.HexDiff.DEFAULT_BLOCK_SIZE)
......
......@@ -30,6 +30,15 @@ def has_key(dictionary, key):
else:
return dictionary.has_key(key)
def get_keys(dictionary):
'''
For cross compatibility between Python 2 and Python 3 dictionaries.
'''
if PY_MAJOR_VERSION > 2:
return list(dictionary.keys())
else:
return dictionary.keys()
def str2bytes(string):
'''
For cross compatibility between Python 2 and Python 3 strings.
......
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