mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 16:58:28 +00:00
Merge pull request #308 from ranmrdrakono/master
Added testcase for int instruction tracing
This commit is contained in:
commit
ff7e4abd53
1 changed files with 27 additions and 0 deletions
|
@ -85,11 +85,38 @@ static void test_high_address_reads(void **state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if a read is performed from a big address whith a non-zero last digit, 0 will be read
|
||||||
|
static void test_high_address_read_values(void **state)
|
||||||
|
{
|
||||||
|
uc_engine *uc = *state;
|
||||||
|
|
||||||
|
uint64_t addr = 0x0010000000000001;
|
||||||
|
//addr = 0x000ffffffffffff8; // uncomment to fix wrong behaviour
|
||||||
|
//addr = 90000000; // uncomment to fix wrong behaviour
|
||||||
|
//
|
||||||
|
uint8_t content[] = {0x42,0x42,0x42,0x42, 0x42,0x42,0x42,0x42};
|
||||||
|
uc_assert_success(uc_mem_map(uc, addr-(addr%4096), 4096*2, UC_PROT_ALL));
|
||||||
|
uc_assert_success(uc_mem_write(uc, addr, content, 8));
|
||||||
|
uc_assert_success(uc_reg_write(uc, UC_X86_REG_RAX, &addr));
|
||||||
|
const uint64_t base_addr = 0x40000;
|
||||||
|
uint8_t code[] = {0x48,0x8b,0x00,0x90,0x90,0x90,0x90}; // mov rax, [rax], nops
|
||||||
|
uc_assert_success(uc_mem_map(uc, base_addr, 4096, UC_PROT_ALL));
|
||||||
|
uc_assert_success(uc_mem_write(uc, base_addr, code, 7));
|
||||||
|
uc_assert_success(uc_emu_start(uc, base_addr, base_addr + 3, 0, 0));
|
||||||
|
uint64_t rax = 0;
|
||||||
|
uc_assert_success(uc_reg_read(uc, UC_X86_REG_RAX, &rax));
|
||||||
|
if(rax != 0x4242424242424242) {
|
||||||
|
fail_msg("wrong memory read from code %lx", rax);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
#define test(x) cmocka_unit_test_setup_teardown(x, setup, teardown)
|
#define test(x) cmocka_unit_test_setup_teardown(x, setup, teardown)
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
test(test_last_page_map),
|
test(test_last_page_map),
|
||||||
test(test_high_address_reads),
|
test(test_high_address_reads),
|
||||||
|
test(test_high_address_read_values),
|
||||||
test(test_nullptr_deref_wrong_perms),
|
test(test_nullptr_deref_wrong_perms),
|
||||||
};
|
};
|
||||||
#undef test
|
#undef test
|
||||||
|
|
Loading…
Reference in a new issue