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

Setting RIP inside callback doesn't change execution flow #1952

Closed user1342234 closed 6 months ago

user1342234 commented 7 months ago

Hello! I place a hook on UC_MEM_FETCH_PROT. Inside the hook, I overwrite UC_X86_REG_RIP to a different address and return true to change the flow of execution. Instead, the code keeps executing at the previous RIP. It even leaves UC_X86_REG_RIP unchanged as it's executing. Is this normal behavior?

wtdcode commented 6 months ago

Could you provide a reproduction?

user1342234 commented 6 months ago

Hi. I think this was due to the fact that the RIP register is only synced at certain points. Instead, i just catch the error from uc_emu_start and set the RIP there and restart emulation.