2

The way to decompile a function in Ghidra Python is:

    decomp = DecompInterface()
    decomp.openProgram(currentProgram)

    decompile = decomp.decompileFunction(func, 1000, monitor)

However, in some cases, probably due to an error or corner case situations, the decompilation takes much more than expected.

Any ideas on how is it possible to cancel a decompilation task, using any kind of timeout, in Ghidra Python? I know that it's possible in the GUI.

3

You are already passing 1000 to a decompileFunction so according to the documentation an exception should be thrown if it takes more time than that. Though, the timeout is in seconds and you set it to pretty high value - probably assuming it's in ms. Change to 1 and check if it will be cancelled with an exception if the time has passed.

Alternatively, you use the monitor object that you are passing also to the decompileFunction method. It contains cancel() function that can cancel the action it has been passed to. You can read more about this object here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.