Commit fba87c16 by heffnercj

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

parent 9c3234cd
......@@ -454,6 +454,8 @@ class Binwalk(object):
if fd is None:
fd = BlockFile(target_file, length=self.scan_length, offset=offset)
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.
#fd.seek(offset)
......
......@@ -114,17 +114,22 @@ class BlockFile(file):
@fname - Path to the file to be opened.
@mode - Mode to open the file in.
@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.
'''
self.total_read = 0
self.offset = offset
try:
self.size = file_size(fname)
except:
self.size = 0
if offset < 0:
self.offset = self.size + offset
else:
self.offset = offset
if length:
self.length = length
else:
......
......@@ -153,7 +153,7 @@ class CompressionEntropyAnalyzer(object):
if 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.binwalk = binwalk
......
......@@ -135,6 +135,7 @@ class FileEntropy(object):
self.block = self.DEFAULT_BLOCK_SIZE
self.fd = common.BlockFile(file_name, 'rb', offset=self.start, length=self.length)
self.start = self.fd.offset
self.fd.MAX_TRAILING_SIZE = 0
if self.fd.READ_BLOCK_SIZE < self.block:
self.fd.READ_BLOCK_SIZE = self.block
......
......@@ -117,6 +117,9 @@ class HexDiff(object):
fp.MAX_TRAILING_SIZE = 0
fps.append(fp)
# BlockFile handles calculation of negative offsets, if one was specified
offset = fps[0].offset
while total < size:
i = 0
for fp in fps:
......
......@@ -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.
self.fd.READ_BLOCK_SIZE = self.block
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
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