Commit d9423b66 by devttys0

Fixed extractor bug with --swap enabled

parent 2384691e
......@@ -532,8 +532,18 @@ class Extractor(Module):
fname = unique_file_name(bname, extension)
try:
# If byte swapping is enabled, we need to start reading at a swap-size
# aligned offset, then index in to the read data appropriately.
if self.config.swap_size:
adjust = offset % self.config.swap_size
else:
adjust = 0
offset -= adjust
# Open the target file and seek to the offset
fdin = self.config.open_file(file_name, length=size, offset=offset)
fdin = self.config.open_file(file_name)
fdin.seek(offset)
# Open the output file
try:
......@@ -550,8 +560,9 @@ class Extractor(Module):
if not data:
break
else:
fdout.write(str2bytes(data[:dlen]))
total_size += dlen
fdout.write(str2bytes(data[adjust:dlen]))
total_size += (dlen-adjust)
adjust = 0
# Cleanup
fdout.close()
......
......@@ -37,3 +37,4 @@ class ZLIBExtractPlugin(binwalk.core.plugin.Plugin):
return False
return True
......@@ -14,9 +14,20 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
def scan(self, result):
# If this result is a zlib signature match, try to decompress the data
if result.file and result.description.lower().startswith('zlib'):
# If byte swapping is enabled, we need to start reading at a swap-size
# aligned offset, then index in to the read data appropriately.
if self.module.config.swap_size:
adjust = result.offset % self.module.config.swap_size
else:
adjust = 0
offset = result.offset - adjust
# Seek to and read the suspected zlib data
fd = self.module.config.open_file(result.file.name, offset=result.offset, length=self.MAX_DATA_SIZE)
data = fd.read(self.MAX_DATA_SIZE)
fd = self.module.config.open_file(result.file.name)
fd.seek(offset)
data = fd.read(self.MAX_DATA_SIZE)[adjust:]
fd.close()
# Check if this is valid zlib data. It is valid if:
......@@ -29,3 +40,4 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
# Error -5, incomplete or truncated data input
if not str(e).startswith("Error -5"):
result.valid = False
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