With Ida I can press Control+Z to undo the last action
Can I do that with IdaPython?
With Ida I can press Control+Z to undo the last action
Can I do that with IdaPython?
In the IDA Pro 9.0 changelog is the entry:
SDK: published basic undo interface (create undo point, undo, redo)
And from there I found that ida_undo had been added to the Python SDK. It has the routine create_undo_point(*args). The documentation suggests it might accept two arguments bytes and size; however, this is incorrect.
There's a use in the ida-domain API of the routine:
if probe_only:
ida_undo.create_undo_point('ida_domain_flirt', 'undo_point')
ida_funcs.plan_to_apply_idasgn(str(path))
ida_auto.auto_wait()
hooks.unhook()
results = hooks.results
if probe_only:
ida_undo.perform_undo()
and details in the raw SWIG bindings.
In reality, this function seems to have the signature:
def create_undo_point(action_name: str, label: str) -> bool
I'm not sure how action_name is used, but label is used to set the "undo action label" which can be seen in the Edit→Undo... menu, and is accessible from ida_undo.get_undo_action_label() -> str.
So, programmatically, you can do something like:
ida_undo.create_undo_point("???", "yolo")
... bunch of stuff ...
while ida_undo.get_undo_action_label() != "yolo":
ida_undo.perform_undo()
Specifically, the following IDA Python script demonstrates using the undo APIs:
import ida_undo
import ida_name
ida_name.set_name(0x10001000, "foo")
assert ida_name.get_name(0x10001000) == "foo"
ida_undo.create_undo_point("???", "my_undo_point")
assert ida_undo.get_undo_action_label() == "my_undo_point"
ida_name.set_name(0x10001000, "bar")
assert ida_name.get_name(0x10001000) == "bar"
ida_undo.perform_undo()
assert ida_name.get_name(0x10001000) == "foo"