From 2beb8f74a3fcb2034183b4a56c2dceef9b1d138f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 17 Oct 2023 22:08:34 +0200 Subject: [PATCH] cli: check if helper tools are available --- software/script/chameleon_cli_main.py | 1 + software/script/chameleon_cli_unit.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/software/script/chameleon_cli_main.py b/software/script/chameleon_cli_main.py index beec263..337ca14 100755 --- a/software/script/chameleon_cli_main.py +++ b/software/script/chameleon_cli_main.py @@ -94,6 +94,7 @@ class ChameleonCLI: raise Exception("This script requires at least Python 3.9") self.print_banner() + chameleon_cli_unit.check_tools() cmd_strs = [] while True: if cmd_strs: diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index ec6b5b4..3c7f795 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -37,12 +37,21 @@ type_id_SAK_dict = {0x00: "MIFARE Ultralight Classic/C/EV1/Nano | NTAG 2xx", 0x38: "SmartMX with MIFARE Classic 4K", } -if getattr(sys, 'frozen', False): +if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): # in pyinstaller - default_cwd = str(Path(sys._MEIPASS) / "bin") + default_cwd = Path.cwd() / Path(sys._MEIPASS) / "bin" else: # from source - default_cwd = str(Path(__file__).parent.parent / "bin") + default_cwd = Path.cwd() / Path(__file__).parent.parent / "bin" + + +def check_tools(): + tools = ['staticnested', 'nested', 'darkside', 'mfkey32v2'] + if sys.platform == "win32": + tools = [x+'.exe' for x in tools] + missing_tools = [tool for tool in tools if not (default_cwd / tool).exists()] + if len(missing_tools) > 0: + print(f'{CR}Warning, tools {", ".join(missing_tools)} not found. Corresponding commands will not work as intended.{C0}') class BaseCLIUnit: