summaryrefslogtreecommitdiff
path: root/python/collaboration/changeset.py
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2024-04-08 14:13:16 -0400
committerJosh Ferrell <josh@vector35.com>2024-05-13 15:06:53 -0400
commit3c28d7e6eaa84041ec0fe5352a618759c13e6cb3 (patch)
treed4115c3e663b30ea388c35add6e5fc7dbd835c11 /python/collaboration/changeset.py
parent0ace079eb70b0c999914a1e95a3eb1324a3b19d8 (diff)
Move collaboration to core
Diffstat (limited to 'python/collaboration/changeset.py')
-rw-r--r--python/collaboration/changeset.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/python/collaboration/changeset.py b/python/collaboration/changeset.py
new file mode 100644
index 00000000..931dcbe2
--- /dev/null
+++ b/python/collaboration/changeset.py
@@ -0,0 +1,94 @@
+
+import ctypes
+from typing import List
+
+from .. import _binaryninjacore as core
+from ..database import Database
+from . import file, user, util
+
+
+class Changeset:
+ """
+ Class representing a collection of snapshots in a local database
+ """
+ def __init__(self, handle: core.BNCollaborationChangesetHandle):
+ """
+ :param handle: FFI handle for internal use
+ """
+ self._handle = ctypes.cast(handle, core.BNCollaborationChangesetHandle)
+
+ def __del__(self):
+ if core is not None:
+ core.BNFreeCollaborationChangeset(self._handle)
+
+ @property
+ def database(self) -> 'Database':
+ """
+ Owning database for snapshots
+
+ :return: Database object
+ """
+ value = core.BNCollaborationChangesetGetDatabase(self._handle)
+ if value is None:
+ raise RuntimeError(util._last_error())
+ result = 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())
+ return file.RemoteFile(handle=value)
+
+ @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())
+ return user.User(handle=value)
+
+ @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)