2

With Ida I can press Control+Z to undo the last action

Can I do that with IdaPython?

2
  • You probably should describe what you actually want to achieve and why you think undo is the answer. Commented Aug 25, 2021 at 20:47
  • > Only interactive user actions can be undone via the UI or keyboard > shortcut. This is pretty strange, because the documentation says otherwise: > UI actions or menu items registered by third party plugins will be > undoable by default, there is no need to do anything. Probably this is a bug, @Igor Skochinsky? Commented Jul 25 at 23:02

2 Answers 2

1

No. Only interactive user actions can be undone via the UI or keyboard shortcut.

1

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.