From 3112cd920e1d327632ab799aa1b94ed636ce4d5a Mon Sep 17 00:00:00 2001 From: lazymio Date: Sun, 6 Mar 2022 23:51:35 +0100 Subject: [PATCH] Add a test for nested uc_emu_start exits --- tests/unit/test_x86.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit/test_x86.c b/tests/unit/test_x86.c index 4c786d5a..3f203f9f 100644 --- a/tests/unit/test_x86.c +++ b/tests/unit/test_x86.c @@ -952,6 +952,35 @@ static void test_x86_eflags_reserved_bit() OK(uc_close(uc)); } +static void test_x86_nested_uc_emu_start_exits_cb(uc_engine *uc, uint64_t addr, + size_t size, void *data) +{ + OK(uc_emu_start(uc, code_start + 5, code_start + 6, 0, 0)); +} + +static void test_x86_nested_uc_emu_start_exits() +{ + uc_engine *uc; + // cmp eax, 0 + // jnz t + // nop <-- nested emu_start + // t:mov dword ptr [eax], 0 + char code[] = "\x83\xf8\x00\x75\x01\x90\xc7\x00\x00\x00\x00\x00"; + uc_hook hk; + uint32_t r_pc; + + uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_32, code, sizeof(code) - 1); + + OK(uc_hook_add(uc, &hk, UC_HOOK_CODE, test_x86_nested_uc_emu_start_exits_cb, + NULL, code_start, code_start)); + OK(uc_emu_start(uc, code_start, code_start + 5, 0, 0)); + OK(uc_reg_read(uc, UC_X86_REG_EIP, &r_pc)); + + TEST_CHECK(r_pc == code_start + 5); + + OK(uc_close(uc)); +} + TEST_LIST = { {"test_x86_in", test_x86_in}, {"test_x86_out", test_x86_out}, @@ -983,4 +1012,5 @@ TEST_LIST = { {"test_x86_nested_emu_stop", test_x86_nested_emu_stop}, {"test_x86_64_nested_emu_start_error", test_x86_64_nested_emu_start_error}, {"test_x86_eflags_reserved_bit", test_x86_eflags_reserved_bit}, + {"test_x86_nested_uc_emu_start_exits", test_x86_nested_uc_emu_start_exits}, {NULL, NULL}};