Set emulation_done to true if and only if we exit the outer uc_emu_start
Or we may lost uc_emu_stop wrongly
This commit is contained in:
@ -873,6 +873,41 @@ static void test_x86_nested_emu_start()
|
|||||||
OK(uc_close(uc));
|
OK(uc_close(uc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_x86_nested_emu_stop_cb(uc_engine *uc, uint64_t addr,
|
||||||
|
size_t size, void *data)
|
||||||
|
{
|
||||||
|
OK(uc_emu_start(uc, code_start + 1, code_start + 2, 0, 0));
|
||||||
|
// ecx shouldn't be changed!
|
||||||
|
OK(uc_emu_stop(uc));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_x86_nested_emu_stop()
|
||||||
|
{
|
||||||
|
uc_engine *uc;
|
||||||
|
// INC ecx; DEC edx; DEC edx;
|
||||||
|
char code[] = "\x41\x4a\x4a";
|
||||||
|
int r_ecx = 0x1234;
|
||||||
|
int r_edx = 0x7890;
|
||||||
|
uc_hook h;
|
||||||
|
|
||||||
|
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_32, code, sizeof(code) - 1);
|
||||||
|
OK(uc_reg_write(uc, UC_X86_REG_ECX, &r_ecx));
|
||||||
|
OK(uc_reg_write(uc, UC_X86_REG_EDX, &r_edx));
|
||||||
|
// Emulate DEC in the nested hook.
|
||||||
|
OK(uc_hook_add(uc, &h, UC_HOOK_CODE, test_x86_nested_emu_stop_cb, NULL,
|
||||||
|
code_start, code_start));
|
||||||
|
|
||||||
|
OK(uc_emu_start(uc, code_start, code_start + 3, 0, 0));
|
||||||
|
|
||||||
|
OK(uc_reg_read(uc, UC_X86_REG_ECX, &r_ecx));
|
||||||
|
OK(uc_reg_read(uc, UC_X86_REG_EDX, &r_edx));
|
||||||
|
|
||||||
|
TEST_CHECK(r_ecx == 0x1234);
|
||||||
|
TEST_CHECK(r_edx == 0x788f);
|
||||||
|
|
||||||
|
OK(uc_close(uc));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_LIST = {{"test_x86_in", test_x86_in},
|
TEST_LIST = {{"test_x86_in", test_x86_in},
|
||||||
{"test_x86_out", test_x86_out},
|
{"test_x86_out", test_x86_out},
|
||||||
{"test_x86_mem_hook_all", test_x86_mem_hook_all},
|
{"test_x86_mem_hook_all", test_x86_mem_hook_all},
|
||||||
@ -900,4 +935,5 @@ TEST_LIST = {{"test_x86_in", test_x86_in},
|
|||||||
{"test_x86_hook_tcg_op", test_x86_hook_tcg_op},
|
{"test_x86_hook_tcg_op", test_x86_hook_tcg_op},
|
||||||
{"test_x86_cmpxchg", test_x86_cmpxchg},
|
{"test_x86_cmpxchg", test_x86_cmpxchg},
|
||||||
{"test_x86_nested_emu_start", test_x86_nested_emu_start},
|
{"test_x86_nested_emu_start", test_x86_nested_emu_start},
|
||||||
|
{"test_x86_nested_emu_stop", test_x86_nested_emu_stop},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}};
|
||||||
|
8
uc.c
8
uc.c
@ -804,8 +804,13 @@ uc_err uc_emu_start(uc_engine *uc, uint64_t begin, uint64_t until,
|
|||||||
|
|
||||||
uc->vm_start(uc);
|
uc->vm_start(uc);
|
||||||
|
|
||||||
// emulation is done
|
uc->nested_level--;
|
||||||
|
|
||||||
|
// emulation is done if and only if we exit the outer uc_emu_start
|
||||||
|
// or we may lost uc_emu_stop
|
||||||
|
if (uc->nested_level == 0) {
|
||||||
uc->emulation_done = true;
|
uc->emulation_done = true;
|
||||||
|
}
|
||||||
|
|
||||||
// remove hooks to delete
|
// remove hooks to delete
|
||||||
clear_deleted_hooks(uc);
|
clear_deleted_hooks(uc);
|
||||||
@ -815,7 +820,6 @@ uc_err uc_emu_start(uc_engine *uc, uint64_t begin, uint64_t until,
|
|||||||
qemu_thread_join(&uc->timer);
|
qemu_thread_join(&uc->timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uc->nested_level--;
|
|
||||||
return uc->invalid_error;
|
return uc->invalid_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user