2021-10-03 17:14:44 +03:00
|
|
|
#include "unicorn_test.h"
|
|
|
|
|
|
|
|
const uint64_t code_start = 0x1000;
|
|
|
|
const uint64_t code_len = 0x4000;
|
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
static void uc_common_setup(uc_engine **uc, uc_arch arch, uc_mode mode,
|
|
|
|
const char *code, uint64_t size)
|
|
|
|
{
|
2021-10-19 18:12:52 +03:00
|
|
|
OK(uc_open(arch, mode, uc));
|
|
|
|
OK(uc_mem_map(*uc, code_start, code_len, UC_PROT_ALL));
|
|
|
|
OK(uc_mem_write(*uc, code_start, code, size));
|
|
|
|
}
|
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
static void test_arm64_until()
|
|
|
|
{
|
|
|
|
uc_engine *uc;
|
|
|
|
char code[] = "\x30\x00\x80\xd2\x11\x04\x80\xd2\x9c\x23\x00\x91";
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
/*
|
|
|
|
mov x16, #1
|
|
|
|
mov x17, #0x20
|
|
|
|
add x28, x28, 8
|
|
|
|
*/
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
uint64_t r_x16 = 0x12341234;
|
|
|
|
uint64_t r_x17 = 0x78907890;
|
|
|
|
uint64_t r_pc = 0x00000000;
|
|
|
|
uint64_t r_x28 = 0x12341234;
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
uc_common_setup(&uc, UC_ARCH_ARM64, UC_MODE_ARM, code, sizeof(code) - 1);
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
// initialize machine registers
|
|
|
|
OK(uc_reg_write(uc, UC_ARM64_REG_X16, &r_x16));
|
|
|
|
OK(uc_reg_write(uc, UC_ARM64_REG_X17, &r_x17));
|
|
|
|
OK(uc_reg_write(uc, UC_ARM64_REG_X28, &r_x28));
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
// emulate the three instructions
|
|
|
|
OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 3));
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
OK(uc_reg_read(uc, UC_ARM64_REG_X16, &r_x16));
|
|
|
|
OK(uc_reg_read(uc, UC_ARM64_REG_X17, &r_x17));
|
|
|
|
OK(uc_reg_read(uc, UC_ARM64_REG_X28, &r_x28));
|
|
|
|
OK(uc_reg_read(uc, UC_ARM64_REG_PC, &r_pc));
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
TEST_CHECK(r_x16 == 0x1);
|
|
|
|
TEST_CHECK(r_x17 == 0x20);
|
|
|
|
TEST_CHECK(r_x28 == 0x1234123c);
|
|
|
|
TEST_CHECK(r_pc == (code_start + sizeof(code) - 1));
|
2021-10-19 18:12:52 +03:00
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
OK(uc_close(uc));
|
2021-10-19 18:12:52 +03:00
|
|
|
}
|
|
|
|
|
2021-10-29 13:44:49 +03:00
|
|
|
TEST_LIST = {{"test_arm64_until", test_arm64_until}, {NULL, NULL}};
|