|
| 1 | +# BinAssist on Windows - Installation Guide |
| 2 | + |
| 3 | +This guide covers the steps required to get BinAssist and BinAssistMCP plugins working on Windows with Binary Ninja. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Binary Ninja installed (typically at `C:\Program Files\Vector35\BinaryNinja\`) |
| 8 | +- Plugins cloned to `%APPDATA%\Binary Ninja\plugins\` |
| 9 | + - `BinAssist\` |
| 10 | + - `BinAssistMCP\` |
| 11 | + |
| 12 | +## The Problem |
| 13 | + |
| 14 | +Binary Ninja on Windows uses a bundled Python environment, but: |
| 15 | +1. It doesn't fully process `.pth` files during site initialization |
| 16 | +2. The `mcp` library requires `pywin32`, which needs special DLL handling on Windows |
| 17 | +3. Packages must be installed to Binary Ninja's user site-packages, not the system Python |
| 18 | + |
| 19 | +## Step 1: Configure Binary Ninja Python Environment |
| 20 | + |
| 21 | +In Binary Ninja, go to **Settings → Python** and configure: |
| 22 | +- **Python Environment**: `C:\Program Files\Vector35\BinaryNinja\plugins\python\python310.dll` |
| 23 | +- **Site-packages**: `C:/Users/<username>/AppData/Roaming/Binary Ninja/python310/site-packages` |
| 24 | + |
| 25 | +This ensures packages are installed to a user-writable location. |
| 26 | + |
| 27 | +## Step 2: Install pywin32 DLLs (Administrator Required) |
| 28 | + |
| 29 | +The `pywin32` package includes DLLs that must be accessible at runtime. Copy them to the Binary Ninja installation folder. |
| 30 | + |
| 31 | +Open **Command Prompt as Administrator** and run: |
| 32 | + |
| 33 | +```cmd |
| 34 | +copy "C:\Users\<username>\AppData\Roaming\Binary Ninja\python310\site-packages\pywin32_system32\*.dll" "C:\Program Files\Vector35\BinaryNinja\" |
| 35 | +``` |
| 36 | + |
| 37 | +Or if pywin32 is in the Program Files site-packages: |
| 38 | + |
| 39 | +```cmd |
| 40 | +copy "C:\Program Files\Vector35\BinaryNinja\plugins\python\Lib\site-packages\pywin32_system32\*.dll" "C:\Program Files\Vector35\BinaryNinja\" |
| 41 | +``` |
| 42 | + |
| 43 | +This copies `pythoncom310.dll` and `pywintypes310.dll` to a location on the DLL search path. |
| 44 | + |
| 45 | +## Step 3: Install Plugin Dependencies |
| 46 | + |
| 47 | +Install all required packages to Binary Ninja's user site-packages using `--target`: |
| 48 | + |
| 49 | +**Install pywin32:** |
| 50 | +```cmd |
| 51 | +"C:\Program Files\Vector35\BinaryNinja\plugins\python\python.exe" -m pip install --target "C:\Users\<username>\AppData\Roaming\Binary Ninja\python310\site-packages" pywin32 |
| 52 | +``` |
| 53 | + |
| 54 | +**Install BinAssist dependencies:** |
| 55 | +```cmd |
| 56 | +"C:\Program Files\Vector35\BinaryNinja\plugins\python\python.exe" -m pip install --target "C:\Users\<username>\AppData\Roaming\Binary Ninja\python310\site-packages" -r "C:\Users\<username>\AppData\Roaming\Binary Ninja\plugins\BinAssist\requirements.txt" |
| 57 | +``` |
| 58 | + |
| 59 | +**Install BinAssistMCP dependencies:** |
| 60 | +```cmd |
| 61 | +"C:\Program Files\Vector35\BinaryNinja\plugins\python\python.exe" -m pip install --target "C:\Users\<username>\AppData\Roaming\Binary Ninja\python310\site-packages" -r "C:\Users\<username>\AppData\Roaming\Binary Ninja\plugins\BinAssistMCP\requirements.txt" |
| 62 | +``` |
| 63 | + |
| 64 | +> **Note:** Replace `<username>` with your actual Windows username, or use `%APPDATA%` in the path (though `--target` may not expand environment variables). |
| 65 | +
|
| 66 | +## Step 4: Restart Binary Ninja |
| 67 | + |
| 68 | +Close all Binary Ninja instances and restart. The plugins should now load correctly. |
| 69 | + |
| 70 | +## Verification |
| 71 | + |
| 72 | +In Binary Ninja's Python console, verify the imports work: |
| 73 | + |
| 74 | +```python |
| 75 | +import pywintypes |
| 76 | +print("pywintypes OK") |
| 77 | + |
| 78 | +import mcp |
| 79 | +print("mcp OK") |
| 80 | +``` |
| 81 | + |
| 82 | +## Notes: pywin32 Path Fix (Already Applied - For Reference Only) |
| 83 | + |
| 84 | +Binary Ninja doesn't process `.pth` files, so the `win32` and `win32\lib` directories aren't automatically added to `sys.path`. |
| 85 | + |
| 86 | +Both plugins include a fix in their `__init__.py` that adds these paths before importing the `mcp` library: |
| 87 | + |
| 88 | +```python |
| 89 | +# Fix pywin32 paths on Windows (required for mcp library) |
| 90 | +# Binary Ninja doesn't process .pth files, so we add the paths manually |
| 91 | +import sys |
| 92 | +import os |
| 93 | +if sys.platform == 'win32': |
| 94 | + _site_packages = os.path.join(os.environ.get('APPDATA', ''), 'Binary Ninja', 'python310', 'site-packages') |
| 95 | + _win32_paths = [ |
| 96 | + os.path.join(_site_packages, 'win32'), |
| 97 | + os.path.join(_site_packages, 'win32', 'lib'), |
| 98 | + os.path.join(_site_packages, 'Pythonwin'), |
| 99 | + ] |
| 100 | + for _p in _win32_paths: |
| 101 | + if _p not in sys.path and os.path.isdir(_p): |
| 102 | + sys.path.insert(0, _p) |
| 103 | +``` |
| 104 | + |
| 105 | +This code is already included in the plugin source. |
| 106 | + |
| 107 | + |
| 108 | +## Troubleshooting |
| 109 | + |
| 110 | +### "ModuleNotFoundError: No module named 'pywintypes'" |
| 111 | + |
| 112 | +- Ensure the DLLs were copied to `C:\Program Files\Vector35\BinaryNinja\` |
| 113 | +- Verify the path fix is in `__init__.py` and runs before any mcp imports |
| 114 | +- Check that `win32\lib\pywintypes.py` exists in your site-packages |
| 115 | + |
| 116 | +### "Access is denied" when installing packages |
| 117 | + |
| 118 | +- Use the `--target` flag to install to the roaming site-packages |
| 119 | +- Or run the command prompt as Administrator |
| 120 | + |
| 121 | +### Packages installing to wrong location |
| 122 | + |
| 123 | +- Always use the full path to Binary Ninja's Python: |
| 124 | + ``` |
| 125 | + "C:\Program Files\Vector35\BinaryNinja\plugins\python\python.exe" |
| 126 | + ``` |
| 127 | +- Use `--target` to explicitly specify the destination |
| 128 | + |
| 129 | +### Check sys.path |
| 130 | + |
| 131 | +In Binary Ninja's Python console: |
| 132 | + |
| 133 | +```python |
| 134 | +import sys |
| 135 | +print('\n'.join(sys.path)) |
| 136 | +``` |
| 137 | + |
| 138 | +Ensure your roaming site-packages and the win32 subdirectories are listed. |
0 commit comments