Commit 5a52a5a8 by devttys0

Cleaned up smart.Signature code, fixed Python3 ctypes bugs.

parent 881f0c18
import re
import binwalk.core.common as common
from binwalk.core.smart import SmartSignature
from binwalk.core.smart import Signature
from binwalk.core.compat import *
class Filter:
......@@ -32,7 +32,7 @@ class Filter:
self.grep_filters = []
self.show_invalid_results = show_invalid_results
self.exclusive_filter = False
self.smart = SmartSignature(self)
self.smart = Signature(self)
def include(self, match, exclusive=True):
'''
......@@ -134,7 +134,7 @@ class Filter:
# Don't include quoted strings or keyword arguments in this search, as
# strings from the target file may legitimately contain the INVALID_RESULT text.
if self.INVALID_RESULT in common.strip_quoted_strings(self.smart._strip_tags(data)):
if self.INVALID_RESULT in common.strip_quoted_strings(self.smart.strip_tags(data)):
return False
# There should be no non-printable characters in any of the data
......
......@@ -3,6 +3,7 @@
import os
import ctypes
import ctypes.util
from binwalk.core.compat import str2bytes
from binwalk.core.module import Option, Kwarg, Module
class Deflate(object):
......@@ -46,7 +47,7 @@ class Deflate(object):
def decompress(self, data):
description = None
decomp_size = self.tinfl.is_deflated(data, len(data), 0)
decomp_size = self.tinfl.is_deflated(str2bytes(data), len(data), 0)
if decomp_size >= self.MIN_DECOMP_SIZE:
description = self.DESCRIPTION + ', uncompressed size >= %d' % decomp_size
......
......@@ -48,8 +48,8 @@ class Signature(Module):
VERBOSE_HEADER_FORMAT = "%s %d"
def init(self):
# Create SmartSignature and MagicParser class instances. These are mostly for internal use.
self.smart = binwalk.core.smart.SmartSignature(self.config.filter, ignore_smart_signatures=self.dumb_scan)
# Create Signature and MagicParser class instances. These are mostly for internal use.
self.smart = binwalk.core.smart.Signature(self.config.filter, ignore_smart_signatures=self.dumb_scan)
self.parser = binwalk.core.parser.MagicParser(self.config.filter, self.smart)
# If a raw byte sequence was specified, build a magic file from that instead of using the default magic files
......
import ctypes
import ctypes.util
from binwalk.core.compat import str2bytes
from binwalk.core.common import BlockFile
class Plugin(object):
......@@ -23,9 +24,9 @@ class Plugin(object):
# If this result is a zlib signature match, try to decompress the data
if self.tinfl and result.file and result.description.lower().startswith('zlib'):
# Seek to and read the suspected zlib data
fd = self.module.config.open_file(result.file.name, offset=result.offset)
#BlockFile(result.file.name, offset=result.offset, swap=self.module.config.swap_size)
data = fd.read(self.MAX_DATA_SIZE)
fd = self.module.config.open_file(result.file.name, offset=result.offset, length=self.MAX_DATA_SIZE)
# Python3 ctypes needs a bytes object, not a str
data = str2bytes(fd.read(self.MAX_DATA_SIZE))
fd.close()
# Check if this is valid zlib data
......
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