diff options
| author | Josh F <josh@vector35.com> | 2022-07-21 16:30:49 -0400 |
|---|---|---|
| committer | Josh F <josh@vector35.com> | 2022-07-21 16:30:49 -0400 |
| commit | bd79cde9742b0fa7b5f38f7b820180f57ba2f55e (patch) | |
| tree | 49340453f264ce4baceb0b2d462381ecb1d0cc58 | |
| parent | 2fbd5289025ef1263c40b72f68de1e7bbe7e5fc5 (diff) | |
Add FileMetadata::GetLast{Undo,Redo}Entry, add valid field to BNUndoEntry
| -rw-r--r-- | binaryninjaapi.h | 2 | ||||
| -rw-r--r-- | binaryninjacore.h | 3 | ||||
| -rw-r--r-- | filemetadata.cpp | 46 |
3 files changed, 51 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 1c33f70b..692c6901 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1079,6 +1079,8 @@ namespace BinaryNinja { std::vector<Ref<User>> GetUsers(); std::vector<UndoEntry> GetUndoEntries(); std::vector<UndoEntry> GetRedoEntries(); + std::optional<UndoEntry> GetLastUndoEntry(); + std::optional<UndoEntry> GetLastRedoEntry(); void ClearUndoEntries(); bool OpenProject(); diff --git a/binaryninjacore.h b/binaryninjacore.h index be051b50..6c830729 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1940,6 +1940,7 @@ extern "C" struct BNUndoEntry { + bool valid; BNUser* user; char* hash; BNUndoAction* actions; @@ -3164,6 +3165,8 @@ extern "C" BINARYNINJACOREAPI BNUndoEntry* BNGetUndoEntries(BNFileMetadata* file, size_t* count); BINARYNINJACOREAPI BNUndoEntry* BNGetRedoEntries(BNFileMetadata* file, size_t* count); + BINARYNINJACOREAPI BNUndoEntry BNGetLastUndoEntry(BNFileMetadata* file); + BINARYNINJACOREAPI BNUndoEntry BNGetLastRedoEntry(BNFileMetadata* file); BINARYNINJACOREAPI void BNFreeUndoEntries(BNUndoEntry* entries, size_t count); BINARYNINJACOREAPI void BNClearUndoEntries(BNFileMetadata* file); diff --git a/filemetadata.cpp b/filemetadata.cpp index 9d9b2a3a..5d01c3b0 100644 --- a/filemetadata.cpp +++ b/filemetadata.cpp @@ -364,6 +364,8 @@ vector<UndoEntry> FileMetadata::GetUndoEntries() result.reserve(numEntries); for (size_t i = 0; i < numEntries; i++) { + if (!entries[i].valid) + continue; UndoEntry temp; temp.timestamp = entries[i].timestamp; temp.hash = entries[i].hash; @@ -390,6 +392,8 @@ vector<UndoEntry> FileMetadata::GetRedoEntries() result.reserve(numEntries); for (size_t i = 0; i < numEntries; i++) { + if (!entries[i].valid) + continue; UndoEntry temp; temp.timestamp = entries[i].timestamp; temp.hash = entries[i].hash; @@ -407,6 +411,48 @@ vector<UndoEntry> FileMetadata::GetRedoEntries() } +std::optional<UndoEntry> FileMetadata::GetLastUndoEntry() +{ + BNUndoEntry bnEntry = BNGetLastUndoEntry(m_object); + + if (!bnEntry.valid) + return {}; + + UndoEntry entry; + entry.timestamp = bnEntry.timestamp; + entry.hash = bnEntry.hash; + entry.user = new User(BNNewUserReference(bnEntry.user)); + size_t actionCount = bnEntry.actionCount; + for (size_t actionIndex = 0; actionIndex < actionCount; actionIndex++) + { + entry.actions.emplace_back(bnEntry.actions[actionIndex]); + } + + return entry; +} + + +std::optional<UndoEntry> FileMetadata::GetLastRedoEntry() +{ + BNUndoEntry bnEntry = BNGetLastRedoEntry(m_object); + + if (!bnEntry.valid) + return {}; + + UndoEntry entry; + entry.timestamp = bnEntry.timestamp; + entry.hash = bnEntry.hash; + entry.user = new User(BNNewUserReference(bnEntry.user)); + size_t actionCount = bnEntry.actionCount; + for (size_t actionIndex = 0; actionIndex < actionCount; actionIndex++) + { + entry.actions.emplace_back(bnEntry.actions[actionIndex]); + } + + return entry; +} + + void FileMetadata::ClearUndoEntries() { BNClearUndoEntries(m_object); |
