Format code

This commit is contained in:
2023-08-06 21:53:42 +08:00
parent 30bc08611b
commit 6801e156aa
6 changed files with 52 additions and 36 deletions

View File

@@ -665,7 +665,8 @@ See sample_ctl.c for a detailed example.
uc_ctl(uc, UC_CTL_READ(UC_CTL_TCG_BUFFER_SIZE, 1), (size))
#define uc_ctl_set_tcg_buffer_size(uc, size) \
uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TCG_BUFFER_SIZE, 1), (size))
#define uc_ctl_context_mode(uc, mode) uc_ctl(uc, UC_CTL_WRITE(UC_CTL_CONTEXT_MODE, 1), (mode))
#define uc_ctl_context_mode(uc, mode) \
uc_ctl(uc, UC_CTL_WRITE(UC_CTL_CONTEXT_MODE, 1), (mode))
// Opaque storage for CPU context, used with uc_context_*()
struct uc_context;

View File

@@ -395,7 +395,9 @@ static void test_noexec(void)
OK(uc_ctl_tlb_mode(uc, UC_TLB_VIRTUAL));
OK(uc_mem_protect(uc, code_start, code_start + 0x1000, UC_PROT_EXEC));
uc_assert_err(UC_ERR_READ_PROT, uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
uc_assert_err(
UC_ERR_READ_PROT,
uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
OK(uc_close(uc));
}

View File

@@ -366,8 +366,10 @@ static void test_snapshot_unmap(void)
uc_assert_err(UC_ERR_ARG, uc_mem_unmap(uc, 0x1000, 0x1000));
OK(uc_mem_unmap(uc, 0x1000, 0x2000));
uc_assert_err(UC_ERR_READ_UNMAPPED, uc_mem_read(uc, 0x1000, &tmp, sizeof(tmp)));
uc_assert_err(UC_ERR_READ_UNMAPPED, uc_mem_read(uc, 0x2000, &tmp, sizeof(tmp)));
uc_assert_err(UC_ERR_READ_UNMAPPED,
uc_mem_read(uc, 0x1000, &tmp, sizeof(tmp)));
uc_assert_err(UC_ERR_READ_UNMAPPED,
uc_mem_read(uc, 0x2000, &tmp, sizeof(tmp)));
OK(uc_context_restore(uc, ctx));
OK(uc_mem_read(uc, 0x1000, &tmp, sizeof(tmp)));

View File

@@ -1438,7 +1438,8 @@ static void test_x86_segmentation()
uc_assert_err(UC_ERR_EXCEPTION, uc_reg_write(uc, UC_X86_REG_FS, &fs));
}
static void test_x86_0xff_lcall_callback(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
static void test_x86_0xff_lcall_callback(uc_engine *uc, uint64_t address,
uint32_t size, void *user_data)
{
// do nothing
return;
@@ -1449,7 +1450,9 @@ static void test_x86_0xff_lcall()
{
uc_engine *uc;
uc_hook hk;
const char code[] = "\xB8\x01\x00\x00\x00\xBB\x01\x00\x00\x00\xB9\x01\x00\x00\x00\xFF\xDD\xBA\x01\x00\x00\x00\xB8\x02\x00\x00\x00\xBB\x02\x00\x00\x00";
const char code[] =
"\xB8\x01\x00\x00\x00\xBB\x01\x00\x00\x00\xB9\x01\x00\x00\x00\xFF\xDD"
"\xBA\x01\x00\x00\x00\xB8\x02\x00\x00\x00\xBB\x02\x00\x00\x00";
// Taken from #1842
// 0: b8 01 00 00 00 mov eax,0x1
// 5: bb 01 00 00 00 mov ebx,0x1
@@ -1461,18 +1464,19 @@ static void test_x86_0xff_lcall()
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_32, code, sizeof(code) - 1);
OK(uc_hook_add(uc, &hk, UC_HOOK_CODE, test_x86_0xff_lcall_callback, NULL, 1, 0));
OK(uc_hook_add(uc, &hk, UC_HOOK_CODE, test_x86_0xff_lcall_callback, NULL, 1,
0));
uc_assert_err(UC_ERR_INSN_INVALID, uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
uc_assert_err(
UC_ERR_INSN_INVALID,
uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
OK(uc_close(uc));
}
static bool
test_x86_64_not_overwriting_tmp0_for_pc_update_cb(uc_engine *uc, uc_mem_type type,
uint64_t address, int size,
uint64_t value, void *user_data)
static bool test_x86_64_not_overwriting_tmp0_for_pc_update_cb(
uc_engine *uc, uc_mem_type type, uint64_t address, int size, uint64_t value,
void *user_data)
{
return true;
}
@@ -1483,15 +1487,19 @@ static void test_x86_64_not_overwriting_tmp0_for_pc_update()
{
uc_engine *uc;
uc_hook hk;
const char code[] = "\x48\xb9\xff\xff\xff\xff\xff\xff\xff\xff\x48\x89\x0c\x24\x48\xd3\x24\x24\x73\x0a";
const char code[] = "\x48\xb9\xff\xff\xff\xff\xff\xff\xff\xff\x48\x89\x0c"
"\x24\x48\xd3\x24\x24\x73\x0a";
uint64_t rsp, pc, eflags;
// 0x1000: movabs rcx, 0xffffffffffffffff
// 0x100a: mov qword ptr [rsp], rcx
// 0x100e: shl qword ptr [rsp], cl ; (Shift to CF=1)
// 0x1012: jae 0xd ; this jump should not be taken! (CF=1 but jae expects CF=0)
// 0x1012: jae 0xd ; this jump should not be taken! (CF=1 but jae
// expects CF=0)
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1);
OK(uc_hook_add(uc, &hk, UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE, test_x86_64_not_overwriting_tmp0_for_pc_update_cb, NULL, 1, 0));
OK(uc_hook_add(uc, &hk, UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE,
test_x86_64_not_overwriting_tmp0_for_pc_update_cb, NULL, 1,
0));
rsp = 0x2000;
OK(uc_reg_write(uc, UC_X86_REG_RSP, (void *)&rsp));
@@ -1552,5 +1560,6 @@ TEST_LIST = {
{"test_x86_vtlb", test_x86_vtlb},
{"test_x86_segmentation", test_x86_segmentation},
{"test_x86_0xff_lcall", test_x86_0xff_lcall},
{"test_x86_64_not_overwriting_tmp0_for_pc_update", test_x86_64_not_overwriting_tmp0_for_pc_update},
{"test_x86_64_not_overwriting_tmp0_for_pc_update",
test_x86_64_not_overwriting_tmp0_for_pc_update},
{NULL, NULL}};

12
uc.c
View File

@@ -687,7 +687,8 @@ uc_err uc_reg_write2(uc_engine *uc, int regid, const void *value, size_t *size)
return UC_ERR_OK;
}
static size_t memory_region_len(uc_engine *uc, MemoryRegion *mr, uint64_t address, size_t count)
static size_t memory_region_len(uc_engine *uc, MemoryRegion *mr,
uint64_t address, size_t count)
{
hwaddr end = mr->end;
while (mr->container != uc->system_memory) {
@@ -703,7 +704,6 @@ static bool check_mem_area(uc_engine *uc, uint64_t address, size_t size)
{
size_t count = 0, len;
while (count < size) {
MemoryRegion *mr = uc->memory_mapping(uc, address);
if (mr) {
@@ -1587,8 +1587,8 @@ uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size,
return UC_ERR_OK;
}
static
uc_err uc_mem_unmap_snapshot(struct uc_struct *uc, uint64_t address, size_t size, MemoryRegion **ret)
static uc_err uc_mem_unmap_snapshot(struct uc_struct *uc, uint64_t address,
size_t size, MemoryRegion **ret)
{
MemoryRegion *mr;
@@ -2684,7 +2684,9 @@ static uc_err uc_restore_latest_snapshot(struct uc_struct *uc)
MemoryRegion *subregion, *subregion_next, *mr, *initial_mr;
int level;
QTAILQ_FOREACH_SAFE(subregion, &uc->system_memory->subregions, subregions_link, subregion_next) {
QTAILQ_FOREACH_SAFE(subregion, &uc->system_memory->subregions,
subregions_link, subregion_next)
{
uc->memory_filter_subregions(subregion, uc->snapshot_level);
if (QTAILQ_EMPTY(&subregion->subregions)) {
uc->memory_unmap(uc, subregion);