Format code

This commit is contained in:
2022-05-23 12:30:44 +02:00
parent 17fa839a56
commit ba50035830
4 changed files with 128 additions and 102 deletions

View File

@@ -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; 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) { } else if (regid >= UC_ARM_REG_S0 && regid <= UC_ARM_REG_S31) {
uint32_t reg_index = regid - UC_ARM_REG_S0; 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); uint64_t in_value = *((uint32_t *)value);
if (reg_index % 2 == 0) { if (reg_index % 2 == 0) {
in_value |= *p_reg_value & 0xffffffff00000000ul; in_value |= *p_reg_value & 0xffffffff00000000ul;

View File

@@ -195,8 +195,9 @@ static void test_arm64_mrs_hook(void)
OK(uc_close(uc)); OK(uc_close(uc));
} }
static bool test_arm64_correct_address_in_small_jump_hook_callback(
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) uc_engine *uc, int type, uint64_t address, int size, int64_t value,
void *user_data)
{ {
// Check registers // Check registers
uint64_t r_x0 = 0x0; uint64_t r_x0 = 0x0;
@@ -224,8 +225,11 @@ static void test_arm64_correct_address_in_small_jump_hook(void)
uint64_t r_pc = 0x0; uint64_t r_pc = 0x0;
uc_hook hook; uc_hook hook;
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1, UC_CPU_ARM64_A72); uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1,
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_arm64_correct_address_in_small_jump_hook_callback, NULL, 1, 0)); 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_assert_err(
UC_ERR_FETCH_UNMAPPED, UC_ERR_FETCH_UNMAPPED,
@@ -239,7 +243,9 @@ static void test_arm64_correct_address_in_small_jump_hook(void)
OK(uc_close(uc)); 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 // Check registers
uint64_t r_x0 = 0x0; uint64_t r_x0 = 0x0;
@@ -267,8 +273,11 @@ static void test_arm64_correct_address_in_long_jump_hook(void)
uint64_t r_pc = 0x0; uint64_t r_pc = 0x0;
uc_hook hook; uc_hook hook;
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1, UC_CPU_ARM64_A72); uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1,
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_arm64_correct_address_in_long_jump_hook_callback, NULL, 1, 0)); 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_assert_err(
UC_ERR_FETCH_UNMAPPED, UC_ERR_FETCH_UNMAPPED,
@@ -282,15 +291,14 @@ static void test_arm64_correct_address_in_long_jump_hook(void)
OK(uc_close(uc)); OK(uc_close(uc));
} }
TEST_LIST = {{"test_arm64_until", test_arm64_until}, TEST_LIST = {{"test_arm64_until", test_arm64_until},
{"test_arm64_code_patching", test_arm64_code_patching}, {"test_arm64_code_patching", test_arm64_code_patching},
{"test_arm64_code_patching_count", test_arm64_code_patching_count}, {"test_arm64_code_patching_count", test_arm64_code_patching_count},
{"test_arm64_v8_pac", test_arm64_v8_pac}, {"test_arm64_v8_pac", test_arm64_v8_pac},
{"test_arm64_read_sctlr", test_arm64_read_sctlr}, {"test_arm64_read_sctlr", test_arm64_read_sctlr},
{"test_arm64_mrs_hook", test_arm64_mrs_hook}, {"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_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_long_jump_hook",
test_arm64_correct_address_in_long_jump_hook},
{NULL, NULL}}; {NULL, NULL}};

View File

@@ -537,8 +537,9 @@ static void test_riscv64_mmio_map(void)
OK(uc_close(uc)); OK(uc_close(uc));
} }
static bool test_riscv_correct_address_in_small_jump_hook_callback(
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) uc_engine *uc, int type, uint64_t address, int size, int64_t value,
void *user_data)
{ {
// Check registers // Check registers
uint64_t r_x5 = 0x0; uint64_t r_x5 = 0x0;
@@ -566,8 +567,11 @@ static void test_riscv_correct_address_in_small_jump_hook(void)
uint64_t r_pc = 0x0; uint64_t r_pc = 0x0;
uc_hook hook; uc_hook hook;
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code, sizeof(code) - 1); uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code,
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_riscv_correct_address_in_small_jump_hook_callback, NULL, 1, 0)); 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_assert_err(
UC_ERR_FETCH_UNMAPPED, UC_ERR_FETCH_UNMAPPED,
@@ -581,7 +585,9 @@ static void test_riscv_correct_address_in_small_jump_hook(void)
OK(uc_close(uc)); 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 // Check registers
uint64_t r_x5 = 0x0; uint64_t r_x5 = 0x0;
@@ -601,16 +607,20 @@ static bool test_riscv_correct_address_in_long_jump_hook_callback(uc_engine *uc,
static void test_riscv_correct_address_in_long_jump_hook(void) static void test_riscv_correct_address_in_long_jump_hook(void)
{ {
uc_engine *uc; uc_engine *uc;
// li 0x7FFFFFFFFFFFFF00, x5 > addi t0, zero, -1; slli t0, t0, 63; addi t0, t0, -256; // li 0x7FFFFFFFFFFFFF00, x5 > addi t0, zero, -1; slli t0, t0, 63; addi
// jr x5 // t0, t0, -256; jr x5
char code[] = "\x93\x02\xf0\xff\x93\x92\xf2\x03\x93\x82\x02\xf0\x67\x80\x02\x00"; 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_x5 = 0x0;
uint64_t r_pc = 0x0; uint64_t r_pc = 0x0;
uc_hook hook; uc_hook hook;
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code, sizeof(code) - 1); uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code,
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_UNMAPPED, test_riscv_correct_address_in_long_jump_hook_callback, NULL, 1, 0)); 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_assert_err(
UC_ERR_FETCH_UNMAPPED, UC_ERR_FETCH_UNMAPPED,
@@ -624,8 +634,6 @@ static void test_riscv_correct_address_in_long_jump_hook(void)
OK(uc_close(uc)); OK(uc_close(uc));
} }
TEST_LIST = { TEST_LIST = {
{"test_riscv32_nop", test_riscv32_nop}, {"test_riscv32_nop", test_riscv32_nop},
{"test_riscv64_nop", test_riscv64_nop}, {"test_riscv64_nop", test_riscv64_nop},
@@ -645,6 +653,8 @@ TEST_LIST = {
{"test_riscv32_map", test_riscv32_map}, {"test_riscv32_map", test_riscv32_map},
{"test_riscv64_code_patching", test_riscv64_code_patching}, {"test_riscv64_code_patching", test_riscv64_code_patching},
{"test_riscv64_code_patching_count", test_riscv64_code_patching_count}, {"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_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_long_jump_hook",
test_riscv_correct_address_in_long_jump_hook},
{NULL, NULL}}; {NULL, NULL}};

View File

@@ -1012,7 +1012,9 @@ static void test_x86_nested_uc_emu_start_exits(void)
OK(uc_close(uc)); 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 // Check registers
uint64_t r_rax = 0x0; uint64_t r_rax = 0x0;
@@ -1041,8 +1043,9 @@ static void test_x86_correct_address_in_small_jump_hook(void)
uc_hook hook; uc_hook hook;
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1); 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_assert_err(
UC_ERR_FETCH_UNMAPPED, UC_ERR_FETCH_UNMAPPED,
@@ -1056,7 +1059,9 @@ static void test_x86_correct_address_in_small_jump_hook(void)
OK(uc_close(uc)); 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 // Check registers
uint64_t r_rax = 0x0; uint64_t r_rax = 0x0;
@@ -1085,8 +1090,9 @@ static void test_x86_correct_address_in_long_jump_hook(void)
uc_hook hook; uc_hook hook;
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1); 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_assert_err(
UC_ERR_FETCH_UNMAPPED, UC_ERR_FETCH_UNMAPPED,
@@ -1100,7 +1106,6 @@ static void test_x86_correct_address_in_long_jump_hook(void)
OK(uc_close(uc)); OK(uc_close(uc));
} }
TEST_LIST = { TEST_LIST = {
{"test_x86_in", test_x86_in}, {"test_x86_in", test_x86_in},
{"test_x86_out", test_x86_out}, {"test_x86_out", test_x86_out},
@@ -1134,6 +1139,8 @@ TEST_LIST = {
{"test_x86_eflags_reserved_bit", test_x86_eflags_reserved_bit}, {"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_nested_uc_emu_start_exits", test_x86_nested_uc_emu_start_exits},
{"test_x86_clear_count_cache", test_x86_clear_count_cache}, {"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_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_long_jump_hook",
test_x86_correct_address_in_long_jump_hook},
{NULL, NULL}}; {NULL, NULL}};