1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import sys
from threading import Thread
try:
import binwalk
except ImportError:
# If installed to a custom prefix directory, binwalk may not be in
# the default module search path(s). Try to resolve the prefix module
# path and add it to sys.path.
import os
module_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),
"lib",
"python%d.%d" % (sys.version_info[0], sys.version_info[1]),
"site-packages")
sys.path.append(module_path)
import binwalk
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:
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
except Exception:
pass
def usage(modules):
sys.stderr.write(modules.help())
sys.exit(1)
def main():
modules = binwalk.Modules()
# Start the display_status function as a daemon thread.
t = Thread(target=display_status, args=(modules,))
t.setDaemon(True)
t.start()
try:
if len(sys.argv) == 1:
usage(modules)
elif not modules.execute():
modules.execute(*sys.argv[1:], signature=True)
except binwalk.ModuleException as e:
sys.stderr.write(str(e) + '\n')
sys.exit(1)
if __name__ == '__main__':
try:
# Special options for profiling the code. For debug use only.
if '--profile' in sys.argv:
import cProfile
sys.argv.pop(sys.argv.index('--profile'))
cProfile.run('main()')
else:
main()
except IOError:
pass
except KeyboardInterrupt:
sys.stdout.write("\n")