diff --git a/utils/dependencies.py b/utils/dependencies.py index e595103..7dbb046 100644 --- a/utils/dependencies.py +++ b/utils/dependencies.py @@ -1,10 +1,11 @@ from __future__ import annotations -import logging -import os -import shutil -import subprocess -from typing import Any +import logging +import os +import platform +import shutil +import subprocess +from typing import Any logger = logging.getLogger('intercept.dependencies') @@ -17,12 +18,26 @@ def check_tool(name: str) -> bool: return get_tool_path(name) is not None -def get_tool_path(name: str) -> str | None: - """Get the full path to a tool, checking standard PATH and extra locations.""" - # First check standard PATH - path = shutil.which(name) - if path: - return path +def get_tool_path(name: str) -> str | None: + """Get the full path to a tool, checking standard PATH and extra locations.""" + # Prefer native Homebrew binaries on Apple Silicon to avoid mixing Rosetta + # /usr/local tools with arm64 Python/runtime. + if platform.system() == 'Darwin': + machine = platform.machine().lower() + preferred_paths: list[str] = [] + if machine in {'arm64', 'aarch64'}: + preferred_paths.append('/opt/homebrew/bin') + preferred_paths.append('/usr/local/bin') + + for base in preferred_paths: + full_path = os.path.join(base, name) + if os.path.isfile(full_path) and os.access(full_path, os.X_OK): + return full_path + + # First check standard PATH + path = shutil.which(name) + if path: + return path # Check additional paths (e.g., /usr/sbin for aircrack-ng on Debian) for extra_path in EXTRA_TOOL_PATHS: