Format code
This commit is contained in:
parent
17fa839a56
commit
ba50035830
@ -337,7 +337,8 @@ static uc_err reg_write(CPUARMState *env, unsigned int regid, const void *value)
|
||||
env->vfp.zregs[reg_index / 2].d[reg_index & 1] = *(uint64_t *)value;
|
||||
} else if (regid >= UC_ARM_REG_S0 && regid <= UC_ARM_REG_S31) {
|
||||
uint32_t reg_index = regid - UC_ARM_REG_S0;
|
||||
uint64_t *p_reg_value = &env->vfp.zregs[reg_index / 4].d[reg_index % 4 / 2];
|
||||
uint64_t *p_reg_value =
|
||||
&env->vfp.zregs[reg_index / 4].d[reg_index % 4 / 2];
|
||||
uint64_t in_value = *((uint32_t *)value);
|
||||
if (reg_index % 2 == 0) {
|
||||
in_value |= *p_reg_value & 0xffffffff00000000ul;
|
||||
|
@ -195,22 +195,23 @@ static void test_arm64_mrs_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
|
||||
static bool test_arm64_correct_address_in_small_jump_hook_callback(uc_engine *uc, int type, uint64_t address, int size, int64_t value, void *user_data)
|
||||
static bool test_arm64_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_x0 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_X0, &r_x0));
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x0 == 0x7F00);
|
||||
TEST_CHECK(r_pc == 0x7F00);
|
||||
// Check registers
|
||||
uint64_t r_x0 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_X0, &r_x0));
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x0 == 0x7F00);
|
||||
TEST_CHECK(r_pc == 0x7F00);
|
||||
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7F00);
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7F00);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_arm64_correct_address_in_small_jump_hook(void)
|
||||
@ -224,8 +225,11 @@ static void test_arm64_correct_address_in_small_jump_hook(void)
|
||||
uint64_t r_pc = 0x0;
|
||||
uc_hook hook;
|
||||
|
||||
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1, UC_CPU_ARM64_A72);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_arm64_correct_address_in_small_jump_hook_callback, NULL, 1, 0));
|
||||
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1,
|
||||
UC_CPU_ARM64_A72);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED,
|
||||
test_arm64_correct_address_in_small_jump_hook_callback, NULL,
|
||||
1, 0));
|
||||
|
||||
uc_assert_err(
|
||||
UC_ERR_FETCH_UNMAPPED,
|
||||
@ -239,21 +243,23 @@ static void test_arm64_correct_address_in_small_jump_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
static bool test_arm64_correct_address_in_long_jump_hook_callback(uc_engine *uc, int type, uint64_t address, int size, int64_t value, void *user_data)
|
||||
static bool test_arm64_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_x0 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_X0, &r_x0));
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x0 == 0x7FFFFFFFFFFFFF00);
|
||||
TEST_CHECK(r_pc == 0x7FFFFFFFFFFFFF00);
|
||||
// Check registers
|
||||
uint64_t r_x0 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_X0, &r_x0));
|
||||
OK(uc_reg_read(uc, UC_ARM64_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x0 == 0x7FFFFFFFFFFFFF00);
|
||||
TEST_CHECK(r_pc == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7FFFFFFFFFFFFF00);
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_arm64_correct_address_in_long_jump_hook(void)
|
||||
@ -267,8 +273,11 @@ static void test_arm64_correct_address_in_long_jump_hook(void)
|
||||
uint64_t r_pc = 0x0;
|
||||
uc_hook hook;
|
||||
|
||||
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1, UC_CPU_ARM64_A72);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_arm64_correct_address_in_long_jump_hook_callback, NULL, 1, 0));
|
||||
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1,
|
||||
UC_CPU_ARM64_A72);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED,
|
||||
test_arm64_correct_address_in_long_jump_hook_callback, NULL,
|
||||
1, 0));
|
||||
|
||||
uc_assert_err(
|
||||
UC_ERR_FETCH_UNMAPPED,
|
||||
@ -282,15 +291,14 @@ static void test_arm64_correct_address_in_long_jump_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TEST_LIST = {{"test_arm64_until", test_arm64_until},
|
||||
{"test_arm64_code_patching", test_arm64_code_patching},
|
||||
{"test_arm64_code_patching_count", test_arm64_code_patching_count},
|
||||
{"test_arm64_v8_pac", test_arm64_v8_pac},
|
||||
{"test_arm64_read_sctlr", test_arm64_read_sctlr},
|
||||
{"test_arm64_mrs_hook", test_arm64_mrs_hook},
|
||||
{"test_arm64_correct_address_in_small_jump_hook", test_arm64_correct_address_in_small_jump_hook},
|
||||
{"test_arm64_correct_address_in_long_jump_hook", test_arm64_correct_address_in_long_jump_hook},
|
||||
{"test_arm64_correct_address_in_small_jump_hook",
|
||||
test_arm64_correct_address_in_small_jump_hook},
|
||||
{"test_arm64_correct_address_in_long_jump_hook",
|
||||
test_arm64_correct_address_in_long_jump_hook},
|
||||
{NULL, NULL}};
|
||||
|
@ -537,22 +537,23 @@ static void test_riscv64_mmio_map(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
|
||||
static bool test_riscv_correct_address_in_small_jump_hook_callback(uc_engine *uc, int type, uint64_t address, int size, int64_t value, void *user_data)
|
||||
static bool test_riscv_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_x5 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_X5, &r_x5));
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x5 == 0x7F00);
|
||||
TEST_CHECK(r_pc == 0x7F00);
|
||||
// Check registers
|
||||
uint64_t r_x5 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_X5, &r_x5));
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x5 == 0x7F00);
|
||||
TEST_CHECK(r_pc == 0x7F00);
|
||||
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7F00);
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7F00);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_riscv_correct_address_in_small_jump_hook(void)
|
||||
@ -566,8 +567,11 @@ static void test_riscv_correct_address_in_small_jump_hook(void)
|
||||
uint64_t r_pc = 0x0;
|
||||
uc_hook hook;
|
||||
|
||||
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code, sizeof(code) - 1);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_riscv_correct_address_in_small_jump_hook_callback, NULL, 1, 0));
|
||||
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code,
|
||||
sizeof(code) - 1);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED,
|
||||
test_riscv_correct_address_in_small_jump_hook_callback, NULL,
|
||||
1, 0));
|
||||
|
||||
uc_assert_err(
|
||||
UC_ERR_FETCH_UNMAPPED,
|
||||
@ -581,36 +585,42 @@ static void test_riscv_correct_address_in_small_jump_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
static bool test_riscv_correct_address_in_long_jump_hook_callback(uc_engine *uc, int type, uint64_t address, int size, int64_t value, void *user_data)
|
||||
static bool test_riscv_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_x5 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_X5, &r_x5));
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x5 == 0x7FFFFFFFFFFFFF00);
|
||||
TEST_CHECK(r_pc == 0x7FFFFFFFFFFFFF00);
|
||||
// Check registers
|
||||
uint64_t r_x5 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_X5, &r_x5));
|
||||
OK(uc_reg_read(uc, UC_RISCV_REG_PC, &r_pc));
|
||||
TEST_CHECK(r_x5 == 0x7FFFFFFFFFFFFF00);
|
||||
TEST_CHECK(r_pc == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7FFFFFFFFFFFFF00);
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_riscv_correct_address_in_long_jump_hook(void)
|
||||
{
|
||||
uc_engine *uc;
|
||||
// li 0x7FFFFFFFFFFFFF00, x5 > addi t0, zero, -1; slli t0, t0, 63; addi t0, t0, -256;
|
||||
// jr x5
|
||||
char code[] = "\x93\x02\xf0\xff\x93\x92\xf2\x03\x93\x82\x02\xf0\x67\x80\x02\x00";
|
||||
// li 0x7FFFFFFFFFFFFF00, x5 > addi t0, zero, -1; slli t0, t0, 63; addi
|
||||
// t0, t0, -256; jr x5
|
||||
char code[] =
|
||||
"\x93\x02\xf0\xff\x93\x92\xf2\x03\x93\x82\x02\xf0\x67\x80\x02\x00";
|
||||
|
||||
uint64_t r_x5 = 0x0;
|
||||
uint64_t r_pc = 0x0;
|
||||
uc_hook hook;
|
||||
|
||||
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code, sizeof(code) - 1);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_riscv_correct_address_in_long_jump_hook_callback, NULL, 1, 0));
|
||||
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code,
|
||||
sizeof(code) - 1);
|
||||
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED,
|
||||
test_riscv_correct_address_in_long_jump_hook_callback, NULL,
|
||||
1, 0));
|
||||
|
||||
uc_assert_err(
|
||||
UC_ERR_FETCH_UNMAPPED,
|
||||
@ -624,8 +634,6 @@ static void test_riscv_correct_address_in_long_jump_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_LIST = {
|
||||
{"test_riscv32_nop", test_riscv32_nop},
|
||||
{"test_riscv64_nop", test_riscv64_nop},
|
||||
@ -645,6 +653,8 @@ TEST_LIST = {
|
||||
{"test_riscv32_map", test_riscv32_map},
|
||||
{"test_riscv64_code_patching", test_riscv64_code_patching},
|
||||
{"test_riscv64_code_patching_count", test_riscv64_code_patching_count},
|
||||
{"test_riscv_correct_address_in_small_jump_hook", test_riscv_correct_address_in_small_jump_hook},
|
||||
{"test_riscv_correct_address_in_long_jump_hook", test_riscv_correct_address_in_long_jump_hook},
|
||||
{"test_riscv_correct_address_in_small_jump_hook",
|
||||
test_riscv_correct_address_in_small_jump_hook},
|
||||
{"test_riscv_correct_address_in_long_jump_hook",
|
||||
test_riscv_correct_address_in_long_jump_hook},
|
||||
{NULL, NULL}};
|
||||
|
@ -1012,21 +1012,23 @@ static void test_x86_nested_uc_emu_start_exits(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
static bool 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)
|
||||
static bool 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 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);
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7F00);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_x86_correct_address_in_small_jump_hook(void)
|
||||
@ -1041,8 +1043,9 @@ static void test_x86_correct_address_in_small_jump_hook(void)
|
||||
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));
|
||||
|
||||
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,
|
||||
@ -1056,21 +1059,23 @@ static void test_x86_correct_address_in_small_jump_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
static bool 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)
|
||||
static bool 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 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);
|
||||
// Check address
|
||||
// printf("%lx\n", address);
|
||||
TEST_CHECK(address == 0x7FFFFFFFFFFFFF00);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_x86_correct_address_in_long_jump_hook(void)
|
||||
@ -1085,8 +1090,9 @@ static void test_x86_correct_address_in_long_jump_hook(void)
|
||||
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));
|
||||
|
||||
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,
|
||||
@ -1100,7 +1106,6 @@ static void test_x86_correct_address_in_long_jump_hook(void)
|
||||
OK(uc_close(uc));
|
||||
}
|
||||
|
||||
|
||||
TEST_LIST = {
|
||||
{"test_x86_in", test_x86_in},
|
||||
{"test_x86_out", test_x86_out},
|
||||
@ -1134,6 +1139,8 @@ TEST_LIST = {
|
||||
{"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_clear_count_cache", test_x86_clear_count_cache},
|
||||
{"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},
|
||||
{"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…
Reference in New Issue
Block a user