diff --git a/scripts/retdec-decompiler.py b/scripts/retdec-decompiler.py index 50e7fcfc2..a0297fa6f 100644 --- a/scripts/retdec-decompiler.py +++ b/scripts/retdec-decompiler.py @@ -17,6 +17,7 @@ retdec_unpacker = importlib.import_module('retdec-unpacker') utils = importlib.import_module('retdec-utils') utils.check_python_version() +utils.ensure_script_is_being_run_from_installed_retdec() SigFromLib = retdec_signature_from_library_creator.SigFromLib Unpacker = retdec_unpacker.Unpacker diff --git a/scripts/retdec-fileinfo.py b/scripts/retdec-fileinfo.py index 4b9aa87e0..290f47809 100644 --- a/scripts/retdec-fileinfo.py +++ b/scripts/retdec-fileinfo.py @@ -15,6 +15,7 @@ config = importlib.import_module('retdec-config') utils = importlib.import_module('retdec-utils') utils.check_python_version() +utils.ensure_script_is_being_run_from_installed_retdec() retdec_archive_decompiler = importlib.import_module('retdec-archive-decompiler') ArchiveDecompiler = retdec_archive_decompiler.ArchiveDecompiler diff --git a/scripts/retdec-signature-from-library-creator.py b/scripts/retdec-signature-from-library-creator.py index 3aa5e6c83..e1b3c0f8a 100644 --- a/scripts/retdec-signature-from-library-creator.py +++ b/scripts/retdec-signature-from-library-creator.py @@ -15,6 +15,7 @@ config = importlib.import_module('retdec-config') utils = importlib.import_module('retdec-utils') utils.check_python_version() +utils.ensure_script_is_being_run_from_installed_retdec() CmdRunner = utils.CmdRunner sys.stdout = utils.Unbuffered(sys.stdout) diff --git a/scripts/retdec-tests-runner.py b/scripts/retdec-tests-runner.py index e822841b2..b0b05fff9 100644 --- a/scripts/retdec-tests-runner.py +++ b/scripts/retdec-tests-runner.py @@ -11,6 +11,7 @@ import importlib utils = importlib.import_module('retdec-utils') utils.check_python_version() +utils.ensure_script_is_being_run_from_installed_retdec() try: import colorama diff --git a/scripts/retdec-unpacker.py b/scripts/retdec-unpacker.py index b23920571..fb44ded3b 100644 --- a/scripts/retdec-unpacker.py +++ b/scripts/retdec-unpacker.py @@ -28,6 +28,7 @@ config = importlib.import_module('retdec-config') utils = importlib.import_module('retdec-utils') utils.check_python_version() +utils.ensure_script_is_being_run_from_installed_retdec() CmdRunner = utils.CmdRunner sys.stdout = utils.Unbuffered(sys.stdout) diff --git a/scripts/retdec-utils.py b/scripts/retdec-utils.py index 50c01d5b3..bc1156bf3 100644 --- a/scripts/retdec-utils.py +++ b/scripts/retdec-utils.py @@ -282,6 +282,17 @@ def check_python_version(): if sys.version_info < (3,4): print_error_and_die('Cannot use Python version {} ({}). Use at least Python 3.4.'.format(platform.python_version(), sys.executable)) +def ensure_script_is_being_run_from_installed_retdec(): + # Use this function to assist our users when they try to run the scripts + # from the 'retdec/scripts' directory instead of from an installed RetDec. + # See https://github.com/avast-tl/retdec/issues/418 + if not os.path.dirname(__file__).endswith('bin'): + print_error_and_die( + 'You need to build and install RetDec first and then run the installed script via ' + '`python $RETDEC_INSTALL_DIR/bin/retdec-decompiler.py`.\n' + 'For more details, see https://github.com/avast-tl/retdec#installation-and-use' + ) + def tool_exists(tool_name): return shutil.which(tool_name) is not None