Commit a0c46694 by devttys0

Updated entropy arguments; fixed entropy trigger bugs

parent 77685bb0
...@@ -43,24 +43,24 @@ class Entropy(Module): ...@@ -43,24 +43,24 @@ class Entropy(Module):
long='save', long='save',
kwargs={'save_plot' : True}, kwargs={'save_plot' : True},
description='Save plot as a PNG'), description='Save plot as a PNG'),
Option(short='Q',
long='nlegend',
kwargs={'show_legend' : False},
description='Omit the legend from the entropy plot graph'),
Option(short='N', Option(short='N',
long='nplot', long='nplot',
kwargs={'do_plot' : False}, kwargs={'do_plot' : False},
description='Do not generate an entropy plot graph'), description='Do not generate an entropy plot graph'),
Option(short='H', Option(short='H',
long='high', long='high',
type=int, type=float,
kwargs={'trigger_high' : DEFAULT_TRIGGER_HIGH}, kwargs={'trigger_high' : DEFAULT_TRIGGER_HIGH},
description='Set the rising edge entropy trigger threshold (default: %.2f)' % DEFAULT_TRIGGER_HIGH), description='Set the rising edge entropy trigger threshold (default: %.2f)' % DEFAULT_TRIGGER_HIGH),
Option(short='L', Option(short='L',
long='low', long='low',
type=int, type=float,
kwargs={'trigger_low' : DEFAULT_TRIGGER_LOW}, kwargs={'trigger_low' : DEFAULT_TRIGGER_LOW},
description='Set the falling edge entropy trigger threshold (default: %.2f)' % DEFAULT_TRIGGER_LOW), description='Set the falling edge entropy trigger threshold (default: %.2f)' % DEFAULT_TRIGGER_LOW),
Option(short='Q',
long='nlegend',
kwargs={'show_legend' : False},
description='Omit the legend from the entropy plot graph'),
] ]
KWARGS = [ KWARGS = [
...@@ -133,7 +133,10 @@ class Entropy(Module): ...@@ -133,7 +133,10 @@ class Entropy(Module):
pg.exit() pg.exit()
def calculate_file_entropy(self, fp): def calculate_file_entropy(self, fp):
# Tracks the last displayed rising/falling edge (0 for falling, 1 for rising, None if nothing has been printed yet)
last_edge = None last_edge = None
# Auto-reset the trigger; if True, an entropy above/below self.trigger_high/self.trigger_low will be printed
trigger_reset = True
# Clear results from any previously analyzed files # Clear results from any previously analyzed files
self.clear(results=True) self.clear(results=True)
...@@ -162,18 +165,25 @@ class Entropy(Module): ...@@ -162,18 +165,25 @@ class Entropy(Module):
description = "%f" % entropy description = "%f" % entropy
if not self.config.verbose: if not self.config.verbose:
if last_edge in [None, 0] and entropy > self.trigger_high: if trigger_reset and entropy >= self.trigger_high:
description = "Rising entropy edge (%f)" % entropy description = "Rising entropy edge (%f)" % entropy
display = self.display_results display = self.display_results
last_edge = 1 last_edge = 1
elif last_edge in [None, 1] and entropy < self.trigger_low: trigger_reset = False
elif trigger_reset and entropy <= self.trigger_low:
description = "Falling entropy edge (%f)" % entropy description = "Falling entropy edge (%f)" % entropy
display = self.display_results display = self.display_results
last_edge = 0 last_edge = 0
trigger_reset = False
else: else:
display = False display = False
description = "%f" % entropy description = "%f" % entropy
if last_edge in [None, 0] and entropy > self.trigger_low:
trigger_reset = True
elif last_edge in [None, 1] and entropy < self.trigger_high:
trigger_reset = True
r = self.result(offset=(file_offset + i), r = self.result(offset=(file_offset + i),
file=fp, file=fp,
entropy=entropy, entropy=entropy,
......
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