unicorn-engine / unicorn

Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)
http://www.unicorn-engine.org
GNU General Public License v2.0
7.67k stars 1.35k forks source link

Unicorn does not recover from an invalid instruction hook #2047

Open elicn opened 4 weeks ago

elicn commented 4 weeks ago

Hooking invalid instructions is essential for various purposes, however Unicorn would not recover from a hooked invalid instruction. The UC_HOOK_INSN_INVALID hook handler returns a boolean which supposed to indicate whether the incident has been handled successfully, however it seems that Unicorn ignores that return value and throws an exception either way.

Unicorn is expected to honor the return value and resume emulation if it got an indication that the incident has been handled, while the handler is expected to modify the PC appropriately before returning.

Attached here is a regress test file that may placed in the regress folder to test this behavior (note the .txt extension). invalid_insn.py.txt