Commit 2b61f4f0 by Peter Wu

Fix running binwalk from build dir

This patch fixes some cases in running binwalk:

 - from build dir: src/scripts/binwalk
 - from repo dir: src/build/binwalk
 - from custom dir, but without full path: ./binwalk
   (`dirname(dirname('./binwalk'))` becomes an empty string which is
   treated as "current working directory" while the expected output is
   "..")
parent a048aca4
......@@ -7,11 +7,19 @@ from threading import Thread
# 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 make it the first entry in sys.path.
_module_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),
"lib",
# Ensure that 'src/binwalk' becomes '.' instead of an empty string
_parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
for _module_path in [
# from repo: src/scripts/ -> src/
_parent_dir,
# from build dir: build/scripts-3.4/ -> build/lib/
os.path.join(_parent_dir, "lib"),
# installed in non-default path: bin/ -> lib/python3.4/site-packages/
os.path.join(_parent_dir, "lib",
"python%d.%d" % (sys.version_info[0], sys.version_info[1]),
"site-packages")
if os.path.exists(_module_path) and _module_path not in sys.path:
]:
if os.path.exists(_module_path) and _module_path not in sys.path:
sys.path = [_module_path] + sys.path
import binwalk
......
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