summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2024-01-11 14:23:54 +0800
committerXusheng <xusheng@vector35.com>2024-01-11 14:23:54 +0800
commit3ac99aa88c7019c8313304ef74dd5bbb468a74bc (patch)
treea3b32aa0810255559dafaff2319a94d9af329f3a
parent17aca5059072a5167a0d10eaee70c529083d569b (diff)
Expose the BinaryView::ForgetUndoActions API and use avoid undo actions warning in the debugger
-rw-r--r--binaryninjaapi.h12
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp6
-rw-r--r--filemetadata.cpp6
-rw-r--r--python/filemetadata.py28
5 files changed, 53 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index dbc0e68a..2c9f1582 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2615,6 +2615,12 @@ namespace BinaryNinja {
*/
void RevertUndoActions(const std::string& id);
+ /*! Forget the actions since a call to BeginUndoActions.
+
+ \param id Id of UndoEntry created by BeginUndoActions
+ */
+ void ForgetUndoActions(const std::string& id);
+
/*! \return Whether it is possible to perform an Undo
*/
bool CanUndo();
@@ -4119,6 +4125,12 @@ namespace BinaryNinja {
*/
void RevertUndoActions(const std::string& id);
+ /*! Forget the actions taken since a call to BeginUndoActions.
+
+ \param id Id of UndoEntry created by BeginUndoActions
+ */
+ void ForgetUndoActions(const std::string& id);
+
/*!
\return Whether it is possible to perform an Undo
*/
diff --git a/binaryninjacore.h b/binaryninjacore.h
index e6f8f99d..a1da4493 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -3331,7 +3331,7 @@ extern "C"
BINARYNINJACOREAPI char* BNBeginUndoActions(BNFileMetadata* file, bool anonymousAllowed);
BINARYNINJACOREAPI void BNCommitUndoActions(BNFileMetadata* file, const char* id);
BINARYNINJACOREAPI void BNRevertUndoActions(BNFileMetadata* file, const char* id);
-
+ BINARYNINJACOREAPI void BNForgetUndoActions(BNFileMetadata* file, const char* id);
BINARYNINJACOREAPI bool BNCanUndo(BNFileMetadata* file);
BINARYNINJACOREAPI bool BNUndo(BNFileMetadata* file);
diff --git a/binaryview.cpp b/binaryview.cpp
index e45fce8a..dba5bbc7 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1455,6 +1455,12 @@ void BinaryView::RevertUndoActions(const string& id)
}
+void BinaryView::ForgetUndoActions(const std::string &id)
+{
+ m_file->ForgetUndoActions(id);
+}
+
+
bool BinaryView::CanUndo()
{
return m_file->CanUndo();
diff --git a/filemetadata.cpp b/filemetadata.cpp
index 1838796d..89e759af 100644
--- a/filemetadata.cpp
+++ b/filemetadata.cpp
@@ -315,6 +315,12 @@ void FileMetadata::RevertUndoActions(const std::string& id)
}
+void FileMetadata::ForgetUndoActions(const std::string &id)
+{
+ BNForgetUndoActions(m_object, id.c_str());
+}
+
+
bool FileMetadata::CanUndo()
{
return BNCanUndo(m_object);
diff --git a/python/filemetadata.py b/python/filemetadata.py
index b21537f2..ec0e16bb 100644
--- a/python/filemetadata.py
+++ b/python/filemetadata.py
@@ -399,6 +399,34 @@ class FileMetadata:
id = ""
core.BNCommitUndoActions(self.handle, id)
+ def forget_undo_actions(self, id: Optional[str] = None) -> None:
+ """
+ ``forget_undo_actions`` removes the actions taken since a call to :py:func:`begin_undo_actions`
+ Pass as `id` the value returned by :py:func:`begin_undo_actions`. Empty values of
+ `id` will remove all changes since the last call to :py:func:`begin_undo_actions`.
+
+ :param Optional[str] id: id of undo state, from :py:func:`begin_undo_actions`
+ :rtype: None
+ :Example:
+
+ >>> bv.get_disassembly(0x100012f1)
+ 'xor eax, eax'
+ >>> state = bv.begin_undo_actions()
+ >>> bv.convert_to_nop(0x100012f1)
+ True
+ >>> bv.commit_undo_actions(state)
+ >>> bv.get_disassembly(0x100012f1)
+ 'nop'
+ >>> bv.undo()
+ >>> bv.get_disassembly(0x100012f1)
+ 'nop'
+ >>>
+ """
+
+ if id is None:
+ id = ""
+ core.BNForgetUndoActions(self.handle, id)
+
def revert_undo_actions(self, id: Optional[str] = None) -> None:
"""
``revert_undo_actions`` reverts the actions taken since a call to :py:func:`begin_undo_actions`