Commit d19aae0b by devttys0

Updated zlib plugins to use Python's zlib module instead of libtinfl

parent 679c9485
import binwalk.core.C
import zlib
import binwalk.core.compat
import binwalk.core.plugin
from binwalk.core.common import BlockFile
......@@ -8,18 +9,8 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
'''
MODULES = ['Signature']
MIN_DECOMP_SIZE = 16 * 1024
MAX_DATA_SIZE = 33 * 1024
TINFL = "tinfl"
TINFL_FUNCTIONS = [
binwalk.core.C.Function(name="is_deflated", type=int),
]
def init(self):
# Load libtinfl.so
self.tinfl = binwalk.core.C.Library(self.TINFL, self.TINFL_FUNCTIONS)
def scan(self, result):
# If this result is a gzip signature match, try to decompress the data
if result.file and result.description.lower().startswith('gzip'):
......@@ -40,8 +31,13 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
offset += 1
offset += 1
# Append basic zlib header to the beginning of the compressed data
data = "\x78\x9C" + data[offset:]
# Check if this is valid deflate data (no zlib header)
decomp_size = self.tinfl.is_deflated(data[offset:], len(data[offset:]), 0)
if decomp_size <= 0:
result.valid = False
try:
zlib.decompress(binwalk.core.compat.str2bytes(data))
except zlib.error as e:
if not str(e).startswith("Error -5"):
result.valid = False
import binwalk.core.C
import zlib
import binwalk.core.compat
import binwalk.core.plugin
from binwalk.core.common import BlockFile
......@@ -8,18 +9,8 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
'''
MODULES = ['Signature']
MIN_DECOMP_SIZE = 16 * 1024
MAX_DATA_SIZE = 33 * 1024
TINFL = "tinfl"
TINFL_FUNCTIONS = [
binwalk.core.C.Function(name="is_deflated", type=int),
]
def init(self):
# Load libtinfl.so
self.tinfl = binwalk.core.C.Library(self.TINFL, self.TINFL_FUNCTIONS)
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'):
......@@ -28,10 +19,13 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
data = fd.read(self.MAX_DATA_SIZE)
fd.close()
# Check if this is valid zlib data
decomp_size = self.tinfl.is_deflated(data, len(data), 1)
if decomp_size > 0:
result.description += ", uncompressed size >= %d" % decomp_size
else:
result.valid = False
# Check if this is valid zlib data. It is valid if:
#
# 1. It decompresses without error
# 2. Decompression fails only because of truncated input
try:
zlib.decompress(binwalk.core.compat.str2bytes(data))
except zlib.error as e:
# Error -5, incomplete or truncated data input
if not str(e).startswith("Error -5"):
result.valid = False
......@@ -136,16 +136,6 @@
>4 ledate x %s
>4 lelong x \b{file-epoch:%d}
# Zlib signatures
# Too short to be useful on their own; see:
#
# o src/binwalk/magic/zlib
# o src/binwalk/plugins/zlib.py
#
#0 beshort 0x789C zlib compressed data
#0 beshort 0x78DA zlib compressed data
#0 beshort 0x7801 zlib compressed data
# Supplementary magic data for the file(1) command to support
# rzip(1). The format is described in magic(5).
#
......
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