Add test for ensuring hooks are get called only once

This commit is contained in:
2022-05-07 00:23:04 +02:00
parent 345b63ee96
commit f4f726d7fc

View File

@@ -187,6 +187,38 @@ static void test_map_big_memory(void)
OK(uc_close(uc));
}
static void test_mem_protect_remove_exec_callback(uc_engine *uc, uint64_t addr,
size_t size, void *data)
{
uint64_t *p = (uint64_t *)data;
(*p)++;
OK(uc_mem_protect(uc, 0x2000, 0x1000, UC_PROT_READ));
}
static void test_mem_protect_remove_exec(void)
{
uc_engine *uc;
char code[] = "\x90\xeb\x00\x90";
uc_hook hk;
uint64_t called_count = 0;
OK(uc_open(UC_ARCH_X86, UC_MODE_64, &uc));
OK(uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_ALL));
OK(uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_ALL));
OK(uc_mem_write(uc, 0x1000, code, sizeof(code) - 1));
OK(uc_hook_add(uc, &hk, UC_HOOK_BLOCK,
test_mem_protect_remove_exec_callback, (void *)&called_count,
1, 0));
OK(uc_emu_start(uc, 0x1000, 0x1000 + sizeof(code) - 1, 0, 0));
TEST_CHECK(called_count == 2);
OK(uc_close(uc));
}
TEST_LIST = {{"test_map_correct", test_map_correct},
{"test_map_wrapping", test_map_wrapping},
{"test_mem_protect", test_mem_protect},
@@ -196,4 +228,5 @@ TEST_LIST = {{"test_map_correct", test_map_correct},
{"test_map_at_the_end", test_map_at_the_end},
{"test_map_wrap", test_map_wrap},
{"test_map_big_memory", test_map_big_memory},
{"test_mem_protect_remove_exec", test_mem_protect_remove_exec},
{NULL, NULL}};