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 import binwalk.core.plugin
from binwalk.core.common import BlockFile from binwalk.core.common import BlockFile
...@@ -8,18 +9,8 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin): ...@@ -8,18 +9,8 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
''' '''
MODULES = ['Signature'] MODULES = ['Signature']
MIN_DECOMP_SIZE = 16 * 1024
MAX_DATA_SIZE = 33 * 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): def scan(self, result):
# If this result is a gzip signature match, try to decompress the data # If this result is a gzip signature match, try to decompress the data
if result.file and result.description.lower().startswith('gzip'): if result.file and result.description.lower().startswith('gzip'):
...@@ -40,8 +31,13 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin): ...@@ -40,8 +31,13 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
offset += 1 offset += 1
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) # Check if this is valid deflate data (no zlib header)
decomp_size = self.tinfl.is_deflated(data[offset:], len(data[offset:]), 0) try:
if decomp_size <= 0: zlib.decompress(binwalk.core.compat.str2bytes(data))
result.valid = False 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 import binwalk.core.plugin
from binwalk.core.common import BlockFile from binwalk.core.common import BlockFile
...@@ -8,18 +9,8 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin): ...@@ -8,18 +9,8 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
''' '''
MODULES = ['Signature'] MODULES = ['Signature']
MIN_DECOMP_SIZE = 16 * 1024
MAX_DATA_SIZE = 33 * 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): def scan(self, result):
# If this result is a zlib signature match, try to decompress the data # If this result is a zlib signature match, try to decompress the data
if result.file and result.description.lower().startswith('zlib'): if result.file and result.description.lower().startswith('zlib'):
...@@ -28,10 +19,13 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin): ...@@ -28,10 +19,13 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
data = fd.read(self.MAX_DATA_SIZE) data = fd.read(self.MAX_DATA_SIZE)
fd.close() fd.close()
# Check if this is valid zlib data # Check if this is valid zlib data. It is valid if:
decomp_size = self.tinfl.is_deflated(data, len(data), 1) #
if decomp_size > 0: # 1. It decompresses without error
result.description += ", uncompressed size >= %d" % decomp_size # 2. Decompression fails only because of truncated input
else: try:
result.valid = False 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 @@ ...@@ -136,16 +136,6 @@
>4 ledate x %s >4 ledate x %s
>4 lelong x \b{file-epoch:%d} >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 # Supplementary magic data for the file(1) command to support
# rzip(1). The format is described in magic(5). # 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