``RepositoryManager`` Keeps track of all the repositories and keeps the enabled_plugins.json file coherent with the plugins that are installed/uninstalled enabled/disabled
| 331 | |
| 332 | |
| 333 | class RepositoryManager: |
| 334 | """ |
| 335 | ``RepositoryManager`` Keeps track of all the repositories and keeps the enabled_plugins.json file coherent with |
| 336 | the plugins that are installed/uninstalled enabled/disabled |
| 337 | """ |
| 338 | def __init__(self): |
| 339 | binaryninja._init_plugins() |
| 340 | self.handle = core.BNGetRepositoryManager() |
| 341 | |
| 342 | def __getitem__(self, repo_path: str) -> Repository: |
| 343 | for repo in self.repositories: |
| 344 | if repo_path == repo.path: |
| 345 | return repo |
| 346 | raise KeyError() |
| 347 | |
| 348 | def check_for_updates(self) -> bool: |
| 349 | """Check for updates for all managed Repository objects""" |
| 350 | return core.BNRepositoryManagerCheckForUpdates(self.handle) |
| 351 | |
| 352 | @property |
| 353 | def repositories(self) -> List[Repository]: |
| 354 | """List of Repository objects being managed""" |
| 355 | result = [] |
| 356 | count = ctypes.c_ulonglong(0) |
| 357 | repos = core.BNRepositoryManagerGetRepositories(self.handle, count) |
| 358 | assert repos is not None, "core.BNRepositoryManagerGetRepositories returned None" |
| 359 | try: |
| 360 | for i in range(count.value): |
| 361 | repo_ref = core.BNNewRepositoryReference(repos[i]) |
| 362 | assert repo_ref is not None, "core.BNNewRepositoryReference returned None" |
| 363 | result.append(Repository(repo_ref)) |
| 364 | return result |
| 365 | finally: |
| 366 | core.BNFreeRepositoryManagerRepositoriesList(repos) |
| 367 | |
| 368 | @property |
| 369 | def plugins(self) -> Dict[str, List[RepoPlugin]]: |
| 370 | """List of all RepoPlugins in each repository""" |
| 371 | plugin_list = {} |
| 372 | for repo in self.repositories: |
| 373 | plugin_list[repo.path] = repo.plugins |
| 374 | return plugin_list |
| 375 | |
| 376 | @property |
| 377 | def default_repository(self) -> Repository: |
| 378 | """Gets the default Repository""" |
| 379 | repo_handle = core.BNRepositoryManagerGetDefaultRepository(self.handle) |
| 380 | assert repo_handle is not None, "core.BNRepositoryManagerGetDefaultRepository returned None" |
| 381 | repo_handle_ref = core.BNNewRepositoryReference(repo_handle) |
| 382 | assert repo_handle_ref is not None, "core.BNNewRepositoryReference returned None" |
| 383 | return Repository(repo_handle_ref) |
| 384 | |
| 385 | def add_repository(self, url: Optional[str] = None, repopath: Optional[str] = None) -> bool: |
| 386 | """ |
| 387 | ``add_repository`` adds a new plugin repository for the manager to track. |
| 388 | |
| 389 | To remove a repository, restart Binary Ninja (and don't re-add the repository!). |
| 390 | File artifacts will remain on disk under repositories/ file in the User Folder. |