Commit e59b1483 by devttys0

Fixed python3 bug

parent 325b4424
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
import sys import sys
import binwalk import binwalk
from threading import Thread from threading import Thread
from binwalk.core.compat import user_input
def display_status(m): def display_status(m):
# Display the current scan progress when the enter key is pressed. # Display the current scan progress when the enter key is pressed.
while True: while True:
try: 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)) 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: except KeyboardInterrupt as e:
raise e raise e
...@@ -31,9 +32,7 @@ def main(): ...@@ -31,9 +32,7 @@ def main():
if len(sys.argv) == 1: if len(sys.argv) == 1:
usage(modules) usage(modules)
elif not modules.execute(): elif not modules.execute():
for module in modules.execute(*sys.argv[1:], signature=True): modules.execute(*sys.argv[1:], signature=True)
for result in module.results:
print result.description
except binwalk.ModuleException as e: except binwalk.ModuleException as e:
sys.exit(1) sys.exit(1)
...@@ -47,4 +46,5 @@ if __name__ == '__main__': ...@@ -47,4 +46,5 @@ if __name__ == '__main__':
else: else:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
print("") sys.stdout.write("\n")
...@@ -7,10 +7,7 @@ import string ...@@ -7,10 +7,7 @@ import string
PY_MAJOR_VERSION = sys.version_info[0] PY_MAJOR_VERSION = sys.version_info[0]
if PY_MAJOR_VERSION > 2: if PY_MAJOR_VERSION > 2:
import urllib.request as urllib2
string.letters = string.ascii_letters string.letters = string.ascii_letters
else:
import urllib2
def iterator(dictionary): def iterator(dictionary):
''' '''
...@@ -66,3 +63,12 @@ def string_decode(string): ...@@ -66,3 +63,12 @@ def string_decode(string):
else: else:
return string.decode('string_escape') 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)
...@@ -2,7 +2,7 @@ import ctypes ...@@ -2,7 +2,7 @@ import ctypes
import ctypes.util import ctypes.util
from binwalk.core.common import * from binwalk.core.common import *
class Plugin: class Plugin(object):
''' '''
Searches for and validates compress'd data. Searches for and validates compress'd data.
''' '''
......
class Plugin: class Plugin(object):
''' '''
Ensures that ASCII CPIO archive entries only get extracted once. Ensures that ASCII CPIO archive entries only get extracted once.
''' '''
......
...@@ -3,7 +3,7 @@ import shutil ...@@ -3,7 +3,7 @@ import shutil
from binwalk.core.compat import * from binwalk.core.compat import *
from binwalk.core.common import BlockFile from binwalk.core.common import BlockFile
class Plugin: class Plugin(object):
''' '''
Finds and extracts modified LZMA files commonly found in cable modems. 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 Based on Bernardo Rodrigues' work: http://w00tsec.blogspot.com/2013/11/unpacking-firmware-images-from-cable.html
......
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