Source code for binaryninja.collaboration.changeset


import ctypes
from typing import List, Optional

import binaryninja

from . import _collaboration as core
from . import file, user, util


[docs] class Changeset: """ Class representing a collection of snapshots in a local database """ def __init__( self, database: Optional['binaryninja.Database'] = None, file: Optional['file.RemoteFile'] = None, snapshot_ids: Optional[List[int]] = None, author: Optional['user.User'] = None, handle=None ): """ Construct a new changeset from a given list of snapshots :param database: Owning database :param file: Relevant remote File :param snapshot_ids: Ids of local snapshots in changeset :param author: Remote author User of changeset :param handle: FFI handle for internal use """ if handle is None: assert database is not None assert file is not None assert snapshot_ids is not None assert author is not None snapshot_ids_api = (ctypes.c_int64 * len(snapshot_ids))() for i in range(len(snapshot_ids)): snapshot_ids_api[i] = snapshot_ids[i] self._handle = core.BNCollaborationChangesetCreate(database.handle, file._handle, snapshot_ids_api, len(snapshot_ids), author._handle) else: self._handle = core.BNCollaborationChangesetCopy(handle) def __del__(self): core.BNCollaborationChangesetFree(self._handle) @property def database(self) -> 'binaryninja.Database': """ Owning database for snapshots :return: Database object """ value = core.BNCollaborationChangesetGetDatabase(self._handle) if value is None: raise RuntimeError(util._last_error()) result = binaryninja.Database(handle=value) return result @property def file(self) -> 'file.RemoteFile': """ Relevant remote File object :return: File object """ value = core.BNCollaborationChangesetGetFile(self._handle) if value is None: raise RuntimeError(util._last_error()) result = file.RemoteFile(handle=value) core.BNCollaborationFileFree(value) return result @property def snapshot_ids(self) -> List[int]: """ List of snapshot ids in the database :return: Snapshot id list """ count = ctypes.c_size_t() snapshot_ids = core.BNCollaborationChangesetGetSnapshotIds(self._handle, count) if snapshot_ids is None: raise RuntimeError(util._last_error()) result = [] for i in range(count.value): result.append(snapshot_ids[i]) core.BNCollaborationFreeSnapshotIdList(snapshot_ids, count.value) return result @property def author(self) -> 'user.User': """ Relevant remote author User :return: Author User """ value = core.BNCollaborationChangesetGetAuthor(self._handle) if value is None: raise RuntimeError(util._last_error()) result = user.User(handle=value) core.BNCollaborationUserFree(value) return result @property def name(self) -> str: """ Changeset name :return: Name string """ return core.BNCollaborationChangesetGetName(self._handle) @name.setter def name(self, name: str): """ Set the name of the changeset, e.g. in a name changeset function. :param name: New changeset name """ core.BNCollaborationChangesetSetName(self._handle, name)