/** * Unicorn x86_32 self-modifying unit test * * This test demonstrates the flushing of instruction translation cache * after a self-modification of Intel's x8's "IMUL Gv,Ev,Ib" instruction. */ #include "unicorn_test.h" #include #include #include #include #include "unicorn/unicorn.h" #define RIP_NEXT_TO_THE_SELFMODIFY_OPCODE (1) // Demostration of a self-modifying "IMUL eax,mem,Ib" opcode // And the QEMU's ability to flush the translation buffer properly #define MIN(a, b) (a < b? a: b) #define CODE_SPACE (2 * 1024 * 1024) #define PHY_STACK_REGION (0x60000000) /* Called before every test to set up a new instance */ static int setup(void **state) { uc_engine *uc; uc_assert_success(uc_open(UC_ARCH_X86, UC_MODE_64, &uc)); *state = uc; return 0; } /* Called after every test to clean up */ static int teardown(void **state) { uc_engine *uc = *state; uc_assert_success(uc_close(uc)); *state = NULL; return 0; } static void dump_stack_mem(uc_engine *uc, const struct stat info) { uint8_t tmp[256]; uint32_t size; size = sizeof(info.st_size); if (size > 255) size = 255; if (!uc_mem_read(uc, PHY_STACK_REGION, tmp, size)) { uint32_t i; printf("Stack region dump"); for (i=0; i