Commit ab7c40b9 by devttys0

Added --show-grids command line option

parent c975737a
......@@ -2,7 +2,6 @@
import sys
import os.path
import binwalk
import binwalk.plotter
import binwalk.cmdopts
import binwalk.plotter
from binwalk.compat import *
......@@ -87,6 +86,7 @@ def main():
do_csv = False
save_plot = False
show_plot = True
show_grids = False
show_legend = True
entropy_scan = False
enable_plugins = True
......@@ -151,6 +151,8 @@ def main():
save_plot = True
elif opt in ("-N", "--no-plot"):
show_plot = False
elif opt in ("-V", "--show-grids"):
show_grids = True
elif opt in ("-3", "--3D", "--3d"):
requested_scans.append(binwalk.Binwalk.BINVIS)
elif opt in ("-E", "--entropy"):
......@@ -440,7 +442,7 @@ def main():
# Always enable verbose mode; generating the plot can take some time for large files,
# and without verbose mode enabled it looks like binwalk is just sitting there doing nothing.
bwalk.plot3d(target_files, offset=offset, length=length, weight=weight, verbose=True)
bwalk.plot3d(target_files, offset=offset, length=length, weight=weight, show_grids=show_grids, verbose=True)
elif scan_type == binwalk.Binwalk.ENTROPY:
......@@ -475,8 +477,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()
......
......@@ -288,7 +288,7 @@ class Binwalk(object):
return data
def plot3d(self, target_files, offset=0, length=0, weight=None, verbose=False):
def plot3d(self, target_files, offset=0, length=0, weight=None, show_grids=False, verbose=False):
'''
Generates a 3D data plot of the specified target files.
......@@ -296,6 +296,7 @@ class Binwalk(object):
@offset - Starting offset at which to start the scan.
@length - Number of bytes to scan. Specify 0 to scan the entire file(s).
@weight - A data point must occur at least this many times before being plotted (default: auto-detect).
@show_grids - Set to True to show axis grids in the 3D plot.
@verbose - Set to True to enable verbose output.
Returns None.
......@@ -303,8 +304,7 @@ class Binwalk(object):
if not isinstance(target_files, type([])):
target_files = [target_files]
Plotter3D(target_files, offset=offset, length=length, weight=weight, verbose=verbose).plot()
#PlotFiles(target_files, offset=offset, length=length, weight=weight, verbose=verbose)
Plotter3D(target_files, offset=offset, length=length, weight=weight, show_grids=show_grids, verbose=verbose).plot()
def scan(self, target_files, offset=0, length=0, show_invalid_results=False, callback=None, start_callback=None, end_callback=None, base_dir=None, matryoshka=1, plugins_whitelist=[], plugins_blacklist=[]):
'''
......
......@@ -5,7 +5,7 @@ import os
import sys
import binwalk.config
short_options = "3AaBbCcdEeGHhIiJkLMNnOPpQqrSTtUuvWwz?D:F:f:g:j:K:o:l:m:R:s:X:x:Y:y:Z:"
short_options = "3AaBbCcdEeGHhIiJkLMNnOPpQqrSTtUuVvWwz?D:F:f:g:j:K:o:l:m:R:s:X:x:Y:y:Z:"
long_options = [
"3D",
"3d",
......@@ -24,6 +24,7 @@ long_options = [
"binwalk",
"keep-going",
"show-invalid",
"show-grids",
"ignore-time-skew",
"honor-footers",
"profile",
......@@ -109,6 +110,7 @@ def usage(fd):
fd.write("Binary Visualization:\n")
fd.write("\t-3, --3D Generate a 3D binary visualization\n")
fd.write("\t-Z, --weight Manually set the cutoff weight (lower weight, more data points)\n")
fd.write("\t-V, --show-grids Display the x-y-z grids in the resulting plot\n")
fd.write("\n")
fd.write("Binary Diffing:\n")
......
......@@ -7,11 +7,12 @@ class Plotter(object):
DIMENSIONS = 3
VIEW_DISTANCE = 1024
def __init__(self, files, offset=0, length=0, weight=None, verbose=False):
def __init__(self, files, offset=0, length=0, weight=None, show_grids=False, verbose=False):
import pyqtgraph.opengl as gl
from pyqtgraph.Qt import QtGui
self.verbose = verbose
self.show_grids = show_grids
self.files = files
self.weight = weight
self.offset = offset
......@@ -132,8 +133,28 @@ class Plotter(object):
return scatter_plot
def plot(self, wait=True):
import pyqtgraph.opengl as gl
self.window.show()
if self.show_grids:
xgrid = gl.GLGridItem()
ygrid = gl.GLGridItem()
zgrid = gl.GLGridItem()
self.window.addItem(xgrid)
self.window.addItem(ygrid)
self.window.addItem(zgrid)
# Rotate x and y grids to face the correct direction
xgrid.rotate(90, 0, 1, 0)
ygrid.rotate(90, 1, 0, 0)
# Scale grids to the appropriate dimensions
xgrid.scale(12.8, 12.8, 12.8)
ygrid.scale(12.8, 12.8, 12.8)
zgrid.scale(12.8, 12.8, 12.8)
for file_name in self.files:
(data_points, data_weights) = self._generate_data_points(file_name)
......@@ -183,25 +204,6 @@ class Plotter2D(Plotter):
elif self.plane_count == 2:
return (ord(data[0]), ord(data[1]), 0)
class PlotFiles(object):
def __init__(self, files, offset=0, length=0, weight=None, verbose=False, overlay=False):
if overlay:
Plotter3D(files, offset=offset, length=length, weight=weight, verbose=verbose).plot(wait=True)
else:
objs = []
for f in files:
p = Plotter3D(files, offset=offset, length=length, weight=weight, verbose=verbose)
p.plot(wait=False)
objs.append(p)
for obj in objs:
obj.wait()
if __name__ == '__main__':
import sys
......
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