diff options
| author | Jordan Wiens <github@psifertex.com> | 2025-11-10 23:22:31 -0500 |
|---|---|---|
| committer | Jordan Wiens <github@psifertex.com> | 2025-11-10 23:27:25 -0500 |
| commit | ac909374541f32697a065c43e7e12c5d6916f937 (patch) | |
| tree | ab253b65d3e0bcc73320968c6a0cfbbbd4b7b7d4 | |
| parent | 36d99ad88aed9889c741f34bddd045405a68369b (diff) | |
fix coreversion info and add docs
| -rw-r--r-- | docs/dev/cookbook.md | 26 | ||||
| -rw-r--r-- | python/__init__.py | 15 |
2 files changed, 40 insertions, 1 deletions
diff --git a/docs/dev/cookbook.md b/docs/dev/cookbook.md index df6074d1..5a457806 100644 --- a/docs/dev/cookbook.md +++ b/docs/dev/cookbook.md @@ -375,6 +375,32 @@ context = FileContext(data.file, data, '') execute_on_main_thread(lambda: UIContext.activeContext().openFileContext(context)) ``` +## Version Checking + +### Checking Binary Ninja version + +Plugins often need to check the Binary Ninja version to ensure compatibility or conditionally enable features. Use [`core_version_info()`](https://api.binary.ninja/#binaryninja.core_version_info) and [`CoreVersionInfo`](https://api.binary.ninja/#binaryninja.CoreVersionInfo) for clean version comparisons: + +```python +from binaryninja import core_version_info, CoreVersionInfo + +# Check minimum version requirement +if core_version_info() >= CoreVersionInfo(5, 1, 8104): + # Use API only available in 5.1.8104 and later + print("New API is available") +else: + # Fall back to older API + print("Using legacy API") + +# Parse and compare against a version string +if core_version_info() >= CoreVersionInfo("4.2.0"): + print("Version 4.2.0 or later detected") + +# Access individual version components +version = core_version_info() +print(f"Running Binary Ninja {version.major}.{version.minor}.{version.build}-{version.channel}") +``` + ## Debuging & Logging ### Logging diff --git a/python/__init__.py b/python/__init__.py index 02703972..efc655d0 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -127,6 +127,19 @@ class CoreVersionInfo: Structure representing the Binary Ninja Version. Use :py:func:`core_version_info` to look up the current version of Binary Ninja loaded. + + :Example: + + >>> from binaryninja import core_version_info, CoreVersionInfo + >>> # Check if the current version meets minimum requirements for a plugin + >>> if core_version_info() >= CoreVersionInfo(5, 1, 8104): + ... print("Using new API available in 5.1.8104 and later") + >>> # Parse and compare against a version string + >>> if core_version_info() >= CoreVersionInfo("4.2.0"): + ... print("Version 4.2.0 or later detected") + >>> # Get individual version components + >>> version = core_version_info() + >>> print(f"Running Binary Ninja {version.major}.{version.minor}.{version.build}") """ major: int @@ -151,7 +164,7 @@ class CoreVersionInfo: self.major = core_version_info.major self.minor = core_version_info.minor self.build = core_version_info.build - if core_version_info.channel is not None: + if core_version_info._channel is not None: self.channel = core_version_info.channel else: self.major = major |
