binaryninja-finder 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trail of Bits
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: binaryninja-finder
3
+ Version: 0.2.0
4
+ Summary: Find and install Binary Ninja's Python API
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.9
8
+ Project-URL: Issues, https://github.com/trailofbits/binaryninja-finder/issues
9
+ Project-URL: Source, https://github.com/trailofbits/binaryninja-finder
10
+ Description-Content-Type: text/markdown
11
+
12
+ # binaryninja-finder
13
+
14
+ Automatically finds and adds Binary Ninja's Python API to `sys.path` at interpreter startup.
15
+
16
+ ## Installation
17
+
18
+ ```
19
+ pip install git+https://github.com/trailofbits/binaryninja-finder
20
+ ```
21
+
22
+ Or with [uv](https://docs.astral.sh/uv/):
23
+
24
+ ```
25
+ uv add git+https://github.com/trailofbits/binaryninja-finder
26
+ ```
27
+
28
+ Once installed, `import binaryninja` will work in any script or REPL that uses the same Python environment.
29
+
30
+ ## How it works
31
+
32
+ The package installs a `.pth` file that runs automatically when Python starts. It checks whether `binaryninja` is already importable and, if not, searches for a local Binary Ninja installation and adds its `python/` directory to `sys.path`.
33
+
34
+ The search order is:
35
+
36
+ 1. **`BN_INSTALL_DIR`** environment variable — points to the BN installation root
37
+ 2. **`lastrun` file** — in the BN user config directory (written by Binary Ninja on launch)
38
+ 3. **Common platform paths** — e.g. `/Applications/Binary Ninja.app` on macOS, `/opt/binaryninja` on Linux, `C:\Program Files\Vector35\BinaryNinja` on Windows
39
+
40
+ ## Configuration
41
+
42
+ | Environment variable | Description |
43
+ |---|---|
44
+ | `BN_INSTALL_DIR` | Override the Binary Ninja installation directory |
45
+ | `BN_USER_DIRECTORY` | Override the Binary Ninja user config directory (where `lastrun` is stored) |
46
+
47
+ ## License
48
+
49
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,38 @@
1
+ # binaryninja-finder
2
+
3
+ Automatically finds and adds Binary Ninja's Python API to `sys.path` at interpreter startup.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ pip install git+https://github.com/trailofbits/binaryninja-finder
9
+ ```
10
+
11
+ Or with [uv](https://docs.astral.sh/uv/):
12
+
13
+ ```
14
+ uv add git+https://github.com/trailofbits/binaryninja-finder
15
+ ```
16
+
17
+ Once installed, `import binaryninja` will work in any script or REPL that uses the same Python environment.
18
+
19
+ ## How it works
20
+
21
+ The package installs a `.pth` file that runs automatically when Python starts. It checks whether `binaryninja` is already importable and, if not, searches for a local Binary Ninja installation and adds its `python/` directory to `sys.path`.
22
+
23
+ The search order is:
24
+
25
+ 1. **`BN_INSTALL_DIR`** environment variable — points to the BN installation root
26
+ 2. **`lastrun` file** — in the BN user config directory (written by Binary Ninja on launch)
27
+ 3. **Common platform paths** — e.g. `/Applications/Binary Ninja.app` on macOS, `/opt/binaryninja` on Linux, `C:\Program Files\Vector35\BinaryNinja` on Windows
28
+
29
+ ## Configuration
30
+
31
+ | Environment variable | Description |
32
+ |---|---|
33
+ | `BN_INSTALL_DIR` | Override the Binary Ninja installation directory |
34
+ | `BN_USER_DIRECTORY` | Override the Binary Ninja user config directory (where `lastrun` is stored) |
35
+
36
+ ## License
37
+
38
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,3 @@
1
+ # Keep this filename alphabetically after binaryninja_finder.pth. Editable
2
+ # installs need that file to add the module to sys.path before this hook runs.
3
+ import binaryninja_finder; binaryninja_finder._setup()
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.28,<0.12.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "binaryninja-finder"
7
+ version = "0.2.0"
8
+ description = "Find and install Binary Ninja's Python API"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.9"
13
+
14
+ [project.urls]
15
+ Issues = "https://github.com/trailofbits/binaryninja-finder/issues"
16
+ Source = "https://github.com/trailofbits/binaryninja-finder"
17
+
18
+ [tool.uv.build-backend]
19
+ data = { purelib = "_pth" }
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib.util
4
+ import os
5
+ import sys
6
+ from pathlib import Path
7
+
8
+
9
+ def _user_dir() -> Path:
10
+ bn_user_dir = os.environ.get("BN_USER_DIRECTORY")
11
+ if bn_user_dir:
12
+ return Path(bn_user_dir)
13
+ if sys.platform == "darwin":
14
+ return Path.home() / "Library" / "Application Support" / "Binary Ninja"
15
+ if sys.platform == "win32":
16
+ appdata = os.environ.get("APPDATA") or str(Path.home() / "AppData" / "Roaming")
17
+ return Path(appdata) / "Binary Ninja"
18
+ return Path.home() / ".binaryninja"
19
+
20
+
21
+ def _common_paths() -> list[Path]:
22
+ if sys.platform == "linux":
23
+ return [
24
+ Path("/opt/binaryninja/python"),
25
+ Path.home() / "binaryninja" / "python",
26
+ ]
27
+ if sys.platform == "darwin":
28
+ return [Path("/Applications/Binary Ninja.app/Contents/Resources/python")]
29
+ if sys.platform == "win32":
30
+ return [Path("C:/Program Files/Vector35/BinaryNinja/python")]
31
+ return []
32
+
33
+
34
+ def _python_dir(install_dir: Path) -> Path:
35
+ if sys.platform == "darwin":
36
+ return install_dir / "Contents" / "Resources" / "python"
37
+ return install_dir / "python"
38
+
39
+
40
+ def _find_binary_ninja(*, validate: bool = True) -> Path | None:
41
+ """Find the Binary Ninja Python API directory."""
42
+ candidates: list[Path] = []
43
+
44
+ env_install = os.environ.get("BN_INSTALL_DIR")
45
+ if env_install:
46
+ p = Path(env_install)
47
+ candidates.append(_python_dir(p))
48
+
49
+ try:
50
+ install_dir = Path((_user_dir() / "lastrun").read_text().strip())
51
+ candidates.append(_python_dir(install_dir))
52
+ except OSError:
53
+ pass
54
+
55
+ for path in candidates:
56
+ if not validate or (path / "binaryninja" / "__init__.py").is_file():
57
+ return path
58
+
59
+ for path in _common_paths():
60
+ if (path / "binaryninja" / "__init__.py").is_file():
61
+ return path
62
+
63
+ return None
64
+
65
+
66
+ def _setup() -> None:
67
+ if importlib.util.find_spec("binaryninja") is not None:
68
+ return
69
+ if (path := _find_binary_ninja()) is not None:
70
+ sys.path.append(str(path))