From e59b1483da2f9a4c0ffbddfd80b557bed5968d93 Mon Sep 17 00:00:00 2001 From: devttys0 <heffnercj@gmail.com> Date: Fri, 20 Dec 2013 16:23:19 -0500 Subject: [PATCH] Fixed python3 bug --- src/bin/binwalk | 10 +++++----- src/binwalk/core/compat.py | 12 +++++++++--- src/binwalk/plugins/compressd.py | 2 +- src/binwalk/plugins/cpio.py | 2 +- src/binwalk/plugins/lzmamod.py | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/bin/binwalk b/src/bin/binwalk index 694899b..8cd2c46 100755 --- a/src/bin/binwalk +++ b/src/bin/binwalk @@ -3,12 +3,13 @@ import sys import binwalk from threading import Thread +from binwalk.core.compat import user_input def display_status(m): # Display the current scan progress when the enter key is pressed. while True: try: - raw_input() + user_input() sys.stderr.write("Progress: %.2f%% (%d / %d)\n\n" % (((float(m.status.completed) / float(m.status.total)) * 100), m.status.completed, m.status.total)) except KeyboardInterrupt as e: raise e @@ -31,9 +32,7 @@ def main(): if len(sys.argv) == 1: usage(modules) elif not modules.execute(): - for module in modules.execute(*sys.argv[1:], signature=True): - for result in module.results: - print result.description + modules.execute(*sys.argv[1:], signature=True) except binwalk.ModuleException as e: sys.exit(1) @@ -47,4 +46,5 @@ if __name__ == '__main__': else: main() except KeyboardInterrupt: - print("") + sys.stdout.write("\n") + diff --git a/src/binwalk/core/compat.py b/src/binwalk/core/compat.py index 6546c98..5359892 100644 --- a/src/binwalk/core/compat.py +++ b/src/binwalk/core/compat.py @@ -7,10 +7,7 @@ import string PY_MAJOR_VERSION = sys.version_info[0] if PY_MAJOR_VERSION > 2: - import urllib.request as urllib2 string.letters = string.ascii_letters -else: - import urllib2 def iterator(dictionary): ''' @@ -66,3 +63,12 @@ def string_decode(string): else: return string.decode('string_escape') +def user_input(prompt=''): + ''' + For getting raw user input in Python 2 and 3. + ''' + if PY_MAJOR_VERSION > 2: + return input(prompt) + else: + return raw_input(prompt) + diff --git a/src/binwalk/plugins/compressd.py b/src/binwalk/plugins/compressd.py index 348bbbd..07ae666 100644 --- a/src/binwalk/plugins/compressd.py +++ b/src/binwalk/plugins/compressd.py @@ -2,7 +2,7 @@ import ctypes import ctypes.util from binwalk.core.common import * -class Plugin: +class Plugin(object): ''' Searches for and validates compress'd data. ''' diff --git a/src/binwalk/plugins/cpio.py b/src/binwalk/plugins/cpio.py index e53fe85..78c65c2 100644 --- a/src/binwalk/plugins/cpio.py +++ b/src/binwalk/plugins/cpio.py @@ -1,4 +1,4 @@ -class Plugin: +class Plugin(object): ''' Ensures that ASCII CPIO archive entries only get extracted once. ''' diff --git a/src/binwalk/plugins/lzmamod.py b/src/binwalk/plugins/lzmamod.py index 12633dd..5ad732d 100644 --- a/src/binwalk/plugins/lzmamod.py +++ b/src/binwalk/plugins/lzmamod.py @@ -3,7 +3,7 @@ import shutil from binwalk.core.compat import * from binwalk.core.common import BlockFile -class Plugin: +class Plugin(object): ''' Finds and extracts modified LZMA files commonly found in cable modems. Based on Bernardo Rodrigues' work: http://w00tsec.blogspot.com/2013/11/unpacking-firmware-images-from-cable.html -- libgit2 0.26.0