summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h4
-rw-r--r--database.cpp12
-rw-r--r--python/database.py14
4 files changed, 31 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index c9cff3cf..fe499587 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -910,6 +910,8 @@ __attribute__ ((format (printf, 1, 2)))
int64_t GetId();
std::string GetName();
bool IsAutoSave();
+ bool HasContents();
+ bool HasUndo();
Ref<Snapshot> GetFirstParent();
std::vector<Ref<Snapshot>> GetParents();
std::vector<Ref<Snapshot>> GetChildren();
diff --git a/binaryninjacore.h b/binaryninjacore.h
index c28490ab..cc277070 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -28,7 +28,7 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
-#define BN_CURRENT_CORE_ABI_VERSION 15
+#define BN_CURRENT_CORE_ABI_VERSION 16
// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
@@ -2912,6 +2912,8 @@ __attribute__ ((format (printf, 1, 2)))
BINARYNINJACOREAPI BNSnapshot** BNGetSnapshotChildren(BNSnapshot* snapshot, size_t* count);
BINARYNINJACOREAPI char* BNGetSnapshotName(BNSnapshot* snapshot);
BINARYNINJACOREAPI bool BNIsSnapshotAutoSave(BNSnapshot* snapshot);
+ BINARYNINJACOREAPI bool BNSnapshotHasContents(BNSnapshot* snapshot);
+ BINARYNINJACOREAPI bool BNSnapshotHasUndo(BNSnapshot* snapshot);
BINARYNINJACOREAPI BNDataBuffer* BNGetSnapshotFileContents(BNSnapshot* snapshot);
BINARYNINJACOREAPI BNDataBuffer* BNGetSnapshotFileContentsHash(BNSnapshot* snapshot);
BINARYNINJACOREAPI BNKeyValueStore* BNReadSnapshotData(BNSnapshot* snapshot);
diff --git a/database.cpp b/database.cpp
index 90adb8c7..3d1a5cb6 100644
--- a/database.cpp
+++ b/database.cpp
@@ -213,6 +213,18 @@ bool Snapshot::IsAutoSave()
}
+bool Snapshot::HasContents()
+{
+ return BNSnapshotHasContents(m_object);
+}
+
+
+bool Snapshot::HasUndo()
+{
+ return BNSnapshotHasUndo(m_object);
+}
+
+
Ref<Snapshot> Snapshot::GetFirstParent()
{
BNSnapshot* snap = BNGetSnapshotFirstParent(m_object);
diff --git a/python/database.py b/python/database.py
index ba6943a8..a563d99c 100644
--- a/python/database.py
+++ b/python/database.py
@@ -149,6 +149,16 @@ class Snapshot:
return core.BNIsSnapshotAutoSave(self.handle)
@property
+ def has_contents(self) -> bool:
+ """If the snapshot has contents, and has not been trimmed (read-only)"""
+ return core.BNSnapshotHasContents(self.handle)
+
+ @property
+ def has_undo(self) -> bool:
+ """If the snapshot has undo data (read-only)"""
+ return core.BNSnapshotHasUndo(self.handle)
+
+ @property
def first_parent(self) -> Optional['Snapshot']:
"""Get the first parent of the snapshot, or None if it has no parents (read-only)"""
handle = core.BNGetSnapshotFirstParent(self.handle)
@@ -189,6 +199,7 @@ class Snapshot:
@property
def file_contents(self) -> databuffer.DataBuffer:
"""Get a buffer of the raw data at the time of the snapshot (read-only)"""
+ assert self.has_contents
handle = core.BNGetSnapshotFileContents(self.handle)
assert handle is not None
return databuffer.DataBuffer(handle=handle)
@@ -196,6 +207,7 @@ class Snapshot:
@property
def file_contents_hash(self) -> databuffer.DataBuffer:
"""Get a hash of the data at the time of the snapshot (read-only)"""
+ assert self.has_contents
handle = core.BNGetSnapshotFileContentsHash(self.handle)
assert handle is not None
return databuffer.DataBuffer(handle=handle)
@@ -203,11 +215,13 @@ class Snapshot:
@property
def undo_entries(self):
"""Get a list of undo entries at the time of the snapshot (read-only)"""
+ assert self.has_undo
raise NotImplementedError("GetUndoEntries is not implemented in python")
@property
def data(self) -> KeyValueStore:
"""Get the backing kvs data with snapshot fields (read-only)"""
+ assert self.has_contents
handle = core.BNReadSnapshotData(self.handle)
assert handle is not None
return KeyValueStore(handle=handle)