Commit 60b3873b by heffnercj

Fixed dict iterators in python3; next: string decoding

parent d6298471
#!/usr/bin/env python
from __future__ import print_function
import sys
import os.path
import binwalk
from binwalk.compat import *
from threading import Thread
from getopt import GetoptError, gnu_getopt as GetOpt
......@@ -352,7 +352,7 @@ def main():
print('NAME TYPE ENABLED DESCRIPTION')
print('-' * 115)
with binwalk.Binwalk() as bw:
for (key, info) in binwalk.plugins.Plugins(bw).list_plugins().iteritems():
for (key, info) in iterator(binwalk.plugins.Plugins(bw).list_plugins()):
for module_name in info['modules']:
print('%-16s %-10s %-10s %s' % (module_name, key, info['enabled'][module_name], info['descriptions'][module_name]))
print ('')
......
......@@ -653,7 +653,7 @@ class Binwalk(object):
Returns None.
'''
for (new_file_name, new_data) in new.iteritems():
for (new_file_name, new_data) in iterator(new):
if not results.has_key(new_file_name):
results[new_file_name] = new_data
else:
......
......@@ -9,3 +9,12 @@ if sys.version_info.major > 2:
string.letters = string.ascii_letters
else:
import urllib2
def iterator(obj):
'''
For cross compatibility between Python 2 and Python 3 dictionaries.
'''
if sys.version_info.major > 2:
return obj.items()
else:
return obj.iteritems()
......@@ -470,7 +470,7 @@ class Entropy(object):
if self.binwalk and self.load_plugins:
self.plugins = plugins.Plugins(self.binwalk, whitelist=self.whitelist, blacklist=self.blacklist)
for (file_name, overlay) in self.files.iteritems():
for (file_name, overlay) in iterator(self.files):
if self.plugins:
self.plugins._load_plugins()
......
......@@ -2,7 +2,6 @@
import os
import sys
import string
import curses
import platform
import binwalk.common as common
......
......@@ -256,7 +256,7 @@ class MagicParser:
'''
signature_set = []
for (offset, sigs) in self.signatures.iteritems():
for (offset, sigs) in iterator(self.signatures):
for sig in sigs:
if sig == self.WILDCARD:
sig = re.compile('.')
......
......@@ -132,7 +132,7 @@ class SmartSignature:
if quoted_data and self.KEYWORD_DELIM_START in quoted_data:
# If so, check to see if the quoted data contains any of our keywords.
# If any keywords are found inside of quoted data, consider the keywords invalid.
for (name, keyword) in self.KEYWORDS.iteritems():
for (name, keyword) in iterator(self.KEYWORDS):
if keyword in quoted_data:
return False
return True
......@@ -251,7 +251,7 @@ class SmartSignature:
Returns a sanitized string.
'''
if not self.ignore_smart_signatures:
for (name, keyword) in self.KEYWORDS.iteritems():
for (name, keyword) in iterator(self.KEYWORDS):
start = data.find(keyword)
if start != -1:
end = data[start:].find(self.KEYWORD_DELIM_END)
......
import string
import binwalk.entropy as entropy
import binwalk.plugins as plugins
import binwalk.common as common
......@@ -205,7 +204,7 @@ class FileStrings(object):
Returns True if the ratio of special characters in data is too high, otherwise returns False.
'''
# If an open bracket exists, we expect a close bracket as well
for (key, value) in self.BRACKETED.iteritems():
for (key, value) in iterator(self.BRACKETED):
if key in data and not value in data:
return True
......
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