Tests for jump hook address
This commit is contained in:
parent
55b2950cac
commit
a3ed8bbce5
@ -981,6 +981,91 @@ static void test_x86_nested_uc_emu_start_exits(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
static void test_x86_correct_address_in_small_jump_hook_callback(uc_engine *uc, int type, uint64_t address, int size, int64_t value, void *user_data)
|
||||
{
|
||||
// Check registers
|
||||
uint64_t r_rax = 0x0;
|
||||
uint64_t r_rip = 0x0;
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RAX, &r_rax));
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RIP, &r_rip));
|
||||
TEST_CHECK(r_rax == 0x7F00);
|
||||
TEST_CHECK(r_rip == 0x7F00);
|
||||
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7F00);
|
||||
}
|
||||
|
||||
static void test_x86_correct_address_in_small_jump_hook(void)
|
||||
{
|
||||
uc_engine *uc;
|
||||
// movabs $0x7FFFFFFFFEFBEC9C, %rax
|
||||
// jmp *%rax
|
||||
char code[] = "\x48\xb8\x00\x7F\x00\x00\x00\x00\x00\x00\xff\xe0";
|
||||
|
||||
uint64_t r_rax = 0x0;
|
||||
uint64_t r_rip = 0x0;
|
||||
uc_hook hook;
|
||||
|
||||
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_x86_correct_address_in_small_jump_hook_callback, NULL, 1, 0));
|
||||
|
||||
|
||||
uc_assert_err(
|
||||
UC_ERR_FETCH_UNMAPPED,
|
||||
uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
|
||||
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RAX, &r_rax));
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RIP, &r_rip));
|
||||
TEST_CHECK(r_rax == 0x7F00);
|
||||
TEST_CHECK(r_rip == 0x7F00);
|
||||
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
static void test_x86_correct_address_in_long_jump_hook_callback(uc_engine *uc, int type, uint64_t address, int size, int64_t value, void *user_data)
|
||||
{
|
||||
// Check registers
|
||||
uint64_t r_rax = 0x0;
|
||||
uint64_t r_rip = 0x0;
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RAX, &r_rax));
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RIP, &r_rip));
|
||||
TEST_CHECK(r_rax == 0x7FFFFFFFFFFFFF00);
|
||||
TEST_CHECK(r_rip == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7FFFFFFFFFFFFF00);
|
||||
}
|
||||
|
||||
static void test_x86_correct_address_in_long_jump_hook(void)
|
||||
{
|
||||
uc_engine *uc;
|
||||
// movabs $0x7FFFFFFFFEFBEC9C, %rax
|
||||
// jmp *%rax
|
||||
char code[] = "\x48\xb8\x00\xff\xff\xff\xff\xff\xff\x7f\xff\xe0";
|
||||
|
||||
uint64_t r_rax = 0x0;
|
||||
uint64_t r_rip = 0x0;
|
||||
uc_hook hook;
|
||||
|
||||
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_x86_correct_address_in_long_jump_hook_callback, NULL, 1, 0));
|
||||
|
||||
|
||||
uc_assert_err(
|
||||
UC_ERR_FETCH_UNMAPPED,
|
||||
uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
|
||||
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RAX, &r_rax));
|
||||
OK(uc_reg_read(uc, UC_X86_REG_RIP, &r_rip));
|
||||
TEST_CHECK(r_rax == 0x7FFFFFFFFFFFFF00);
|
||||
TEST_CHECK(r_rip == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
|
||||
TEST_LIST = {
|
||||
{"test_x86_in", test_x86_in},
|
||||
{"test_x86_out", test_x86_out},
|
||||
@ -1013,4 +1098,6 @@ TEST_LIST = {
|
||||
{"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},
|
||||
{"test_x86_correct_address_in_small_jump_hook", test_x86_correct_address_in_small_jump_hook},
|
||||
{"test_x86_correct_address_in_long_jump_hook", test_x86_correct_address_in_long_jump_hook},
|
||||
{NULL, NULL}};
|
||||
|
Loading…
x
Reference in New Issue
Block a user