Commit ebf1afc4 by devttys0

Fixed hexdiff output formatting

parent 283b1ee2
...@@ -19,6 +19,9 @@ class HexDiff(Module): ...@@ -19,6 +19,9 @@ class HexDiff(Module):
SEPERATORS = ['\\', '/'] SEPERATORS = ['\\', '/']
DEFAULT_BLOCK_SIZE = 16 DEFAULT_BLOCK_SIZE = 16
SKIPPED_LINE = "*"
CUSTOM_DISPLAY_FORMAT = "0x%.8X %s"
TITLE = "Binary Diffing" TITLE = "Binary Diffing"
CLI = [ CLI = [
...@@ -52,8 +55,8 @@ class HexDiff(Module): ...@@ -52,8 +55,8 @@ class HexDiff(Module):
Kwarg(name='enabled', default=False), Kwarg(name='enabled', default=False),
] ]
RESULT_FORMAT = "0x%.8X %s\n" RESULT_FORMAT = "%s\n"
RESULT = ['offset', 'description'] RESULT = ['display']
def _no_colorize(self, c, color="red", bold=True): def _no_colorize(self, c, color="red", bold=True):
return c return c
...@@ -113,13 +116,15 @@ class HexDiff(Module): ...@@ -113,13 +116,15 @@ class HexDiff(Module):
return (hexbyte, asciibyte) return (hexbyte, asciibyte)
def diff_files(self, target_files): def diff_files(self, target_files):
last_line = None
loop_count = 0 loop_count = 0
sep_count = 0
while True: while True:
line = "" line = ""
done_files = 0 done_files = 0
block_data = {} block_data = {}
seperator = self.SEPERATORS[loop_count % 2] seperator = self.SEPERATORS[sep_count % 2]
for fp in target_files: for fp in target_files:
block_data[fp] = fp.read(self.block) block_data[fp] = fp.read(self.block)
...@@ -152,7 +157,18 @@ class HexDiff(Module): ...@@ -152,7 +157,18 @@ class HexDiff(Module):
if fp != target_files[-1]: if fp != target_files[-1]:
line += " %s " % seperator line += " %s " % seperator
self.result(offset=(fp.offset + (self.block * loop_count)), description=line) offset = fp.offset + (self.block * loop_count)
if not self._color_filter(line):
display = line = self.SKIPPED_LINE
else:
display = self.CUSTOM_DISPLAY_FORMAT % (offset, line)
sep_count += 1
if line != self.SKIPPED_LINE or last_line != line:
self.result(offset=offset, description=line, display=display)
last_line = line
loop_count += 1 loop_count += 1
def init(self): def init(self):
...@@ -191,9 +207,6 @@ class HexDiff(Module): ...@@ -191,9 +207,6 @@ class HexDiff(Module):
else: else:
self.colorize = self._no_colorize self.colorize = self._no_colorize
def validate(self, result):
result.valid = self._color_filter(result.description)
def run(self): def run(self):
if self.hex_target_files: if self.hex_target_files:
self.header() self.header()
......
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