Commit fba87c16 by heffnercj

All scans now accept negative offsets for the --offset parameter

parent 9c3234cd
...@@ -454,7 +454,9 @@ class Binwalk(object): ...@@ -454,7 +454,9 @@ class Binwalk(object):
if fd is None: if fd is None:
fd = BlockFile(target_file, length=self.scan_length, offset=offset) fd = BlockFile(target_file, length=self.scan_length, offset=offset)
i_opened_fd = True i_opened_fd = True
# If offset is negative (bytes from EOF), BlockFile class will autmoatically calculate the right offset
offset = fd.offset
# Seek to the starting offset. # Seek to the starting offset.
#fd.seek(offset) #fd.seek(offset)
......
...@@ -114,17 +114,22 @@ class BlockFile(file): ...@@ -114,17 +114,22 @@ class BlockFile(file):
@fname - Path to the file to be opened. @fname - Path to the file to be opened.
@mode - Mode to open the file in. @mode - Mode to open the file in.
@length - Maximum number of bytes to read from the file via self.block_read(). @length - Maximum number of bytes to read from the file via self.block_read().
@offset - Offset at which to start reading from the file.
Returns None. Returns None.
''' '''
self.total_read = 0 self.total_read = 0
self.offset = offset
try: try:
self.size = file_size(fname) self.size = file_size(fname)
except: except:
self.size = 0 self.size = 0
if offset < 0:
self.offset = self.size + offset
else:
self.offset = offset
if length: if length:
self.length = length self.length = length
else: else:
......
...@@ -153,7 +153,7 @@ class CompressionEntropyAnalyzer(object): ...@@ -153,7 +153,7 @@ class CompressionEntropyAnalyzer(object):
if self.fp.READ_BLOCK_SIZE < self.BLOCK_SIZE: if self.fp.READ_BLOCK_SIZE < self.BLOCK_SIZE:
self.fp.READ_BLOCK_SIZE = self.BLOCK_SIZE self.fp.READ_BLOCK_SIZE = self.BLOCK_SIZE
self.start = start self.start = self.fp.offset
self.length = length self.length = length
self.binwalk = binwalk self.binwalk = binwalk
......
...@@ -135,6 +135,7 @@ class FileEntropy(object): ...@@ -135,6 +135,7 @@ class FileEntropy(object):
self.block = self.DEFAULT_BLOCK_SIZE self.block = self.DEFAULT_BLOCK_SIZE
self.fd = common.BlockFile(file_name, 'rb', offset=self.start, length=self.length) self.fd = common.BlockFile(file_name, 'rb', offset=self.start, length=self.length)
self.start = self.fd.offset
self.fd.MAX_TRAILING_SIZE = 0 self.fd.MAX_TRAILING_SIZE = 0
if self.fd.READ_BLOCK_SIZE < self.block: if self.fd.READ_BLOCK_SIZE < self.block:
self.fd.READ_BLOCK_SIZE = self.block self.fd.READ_BLOCK_SIZE = self.block
......
...@@ -117,6 +117,9 @@ class HexDiff(object): ...@@ -117,6 +117,9 @@ class HexDiff(object):
fp.MAX_TRAILING_SIZE = 0 fp.MAX_TRAILING_SIZE = 0
fps.append(fp) fps.append(fp)
# BlockFile handles calculation of negative offsets, if one was specified
offset = fps[0].offset
while total < size: while total < size:
i = 0 i = 0
for fp in fps: for fp in fps:
......
...@@ -79,6 +79,7 @@ class FileStrings(object): ...@@ -79,6 +79,7 @@ class FileStrings(object):
# TODO: This is not optimal. We should read in larger chunks and process it into self.block chunks. # TODO: This is not optimal. We should read in larger chunks and process it into self.block chunks.
self.fd.READ_BLOCK_SIZE = self.block self.fd.READ_BLOCK_SIZE = self.block
self.fd.MAX_TRAILING_SIZE = 0 self.fd.MAX_TRAILING_SIZE = 0
self.start = self.fd.offset
# Set the total_scanned and scan_length values for plugins and status display messages # Set the total_scanned and scan_length values for plugins and status display messages
self.binwalk.total_scanned = 0 self.binwalk.total_scanned = 0
......
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