Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3112cd9

Browse files
committedMar 6, 2022
Add a test for nested uc_emu_start exits
1 parent 2a4e42f commit 3112cd9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎tests/unit/test_x86.c

+30
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,35 @@ static void test_x86_eflags_reserved_bit()
952952
OK(uc_close(uc));
953953
}
954954

955+
static void test_x86_nested_uc_emu_start_exits_cb(uc_engine *uc, uint64_t addr,
956+
size_t size, void *data)
957+
{
958+
OK(uc_emu_start(uc, code_start + 5, code_start + 6, 0, 0));
959+
}
960+
961+
static void test_x86_nested_uc_emu_start_exits()
962+
{
963+
uc_engine *uc;
964+
// cmp eax, 0
965+
// jnz t
966+
// nop <-- nested emu_start
967+
// t:mov dword ptr [eax], 0
968+
char code[] = "\x83\xf8\x00\x75\x01\x90\xc7\x00\x00\x00\x00\x00";
969+
uc_hook hk;
970+
uint32_t r_pc;
971+
972+
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_32, code, sizeof(code) - 1);
973+
974+
OK(uc_hook_add(uc, &hk, UC_HOOK_CODE, test_x86_nested_uc_emu_start_exits_cb,
975+
NULL, code_start, code_start));
976+
OK(uc_emu_start(uc, code_start, code_start + 5, 0, 0));
977+
OK(uc_reg_read(uc, UC_X86_REG_EIP, &r_pc));
978+
979+
TEST_CHECK(r_pc == code_start + 5);
980+
981+
OK(uc_close(uc));
982+
}
983+
955984
TEST_LIST = {
956985
{"test_x86_in", test_x86_in},
957986
{"test_x86_out", test_x86_out},
@@ -983,4 +1012,5 @@ TEST_LIST = {
9831012
{"test_x86_nested_emu_stop", test_x86_nested_emu_stop},
9841013
{"test_x86_64_nested_emu_start_error", test_x86_64_nested_emu_start_error},
9851014
{"test_x86_eflags_reserved_bit", test_x86_eflags_reserved_bit},
1015+
{"test_x86_nested_uc_emu_start_exits", test_x86_nested_uc_emu_start_exits},
9861016
{NULL, NULL}};

0 commit comments

Comments
 (0)
Please sign in to comment.