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.33k stars 1.31k forks source link

Add UC_HOOK_INSN support for UC_X86_INS_RDTSC and UC_X86_INS_RDRAND #1902

Open Z4ee opened 8 months ago

Z4ee commented 8 months ago

The current version of the Unicorn Engine does not provide hook support for the UC_X86_INS_RDTSC and UC_X86_INS_RDRAND instructions. These instructions are crucial for applications requiring precise time measurement or random number generation. This proposal suggests adding hook support for these instructions, allowing users to have more flexible control over code execution.

uc_hook_add(uc, &hook, UC_HOOK_INSN, hook_rdtsc, nullptr, 1, 0, UC_X86_INS_RDTSC); // Return: UC_ERR_HOOK
uc_hook_add(uc, &hook, UC_HOOK_INSN, hook_rdrand, nullptr, 1, 0, UC_X86_INS_RDRAND); // Return: UC_ERR_HOOK