Commit 9eb5c3f2 by heffnercj

Updated tinfl.c to return the number of decompressed bytes; zlib/deflate plugins…

Updated tinfl.c to return the number of decompressed bytes; zlib/deflate plugins now report this in scan output.
parent 8f06d72b
......@@ -600,7 +600,7 @@ int is_deflated(char *buf, size_t buf_size, int includes_zlib_header)
flags) >= 0 && out_buf_size > 0)
{
//printf("%d => %d DATA: '%s'\n", in_buf_size, out_buf_size, out_buf);
return 1;
return (int) out_buf_size;
}
return 0;
......
......@@ -12,6 +12,7 @@ class Plugin:
ENABLED = False
SIZE = 64*1024
MIN_DECOMP_SIZE = 1
DESCRIPTION = "Deflate compressed data stream"
def __init__(self, binwalk):
......@@ -22,7 +23,7 @@ class Plugin:
# Add an extraction rule
if self.binwalk.extractor.enabled:
self.binwalk.extractor.add_rule(regex=self.DESCRIPTION.lower(), extension="deflate", cmd=self._extractor)
self.binwalk.extractor.add_rule(regex='^%s' % self.DESCRIPTION.lower(), extension="deflate", cmd=self._extractor)
def pre_scan(self, fp):
self._deflate_scan(fp)
......@@ -48,15 +49,17 @@ class Plugin:
break
for i in range(0, dlen):
if self.tinfl.is_deflated(data[i:], dlen-i, 0):
decomp_size = self.tinfl.is_deflated(data[i:], dlen-i, 0)
if decomp_size >= self.MIN_DECOMP_SIZE:
loc = fp.offset + current_total + i
# Update total_scanned here for immediate progress feedback
self.binwalk.total_scanned = current_total + i
self.binwalk.display.easy_results(loc, self.DESCRIPTION)
description = self.DESCRIPTION + ', uncompressed size >= %d' % decomp_size
self.binwalk.display.easy_results(loc, description)
# Extract the file
if self.binwalk.extractor.enabled:
self.binwalk.extractor.extract(loc, self.DESCRIPTION, fp.name, (fp.size - loc))
self.binwalk.extractor.extract(loc, description, fp.name, (fp.size - loc))
if (current_total + i) > self.binwalk.scan_length:
break
......
......@@ -7,6 +7,7 @@ class Plugin:
Searches for and validates zlib compressed data.
'''
MIN_DECOMP_SIZE = 1
MAX_DATA_SIZE = 33 * 1024
def __init__(self, binwalk):
......@@ -32,7 +33,10 @@ class Plugin:
data = self.fd.read(self.MAX_DATA_SIZE)
# Check if this is valid zlib data
if not self.tinfl.is_deflated(data, len(data), 1):
decomp_size = self.tinfl.is_deflated(data, len(data), 1)
if decomp_size > 0:
result['description'] += ", uncompressed size >= %d" % decomp_size
else:
return (PLUGIN_NO_DISPLAY | PLUGIN_NO_EXTRACT)
return PLUGIN_CONTINUE
......
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