Fix uc_mem_protect

This commit is contained in:
lazymio 2021-11-07 20:37:58 +01:00
parent c6fdbb3735
commit 2f61592ff9
No known key found for this signature in database
GPG Key ID: DFF27E34A47CB873
2 changed files with 27 additions and 0 deletions

View File

@ -1084,6 +1084,7 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly)
if (mr->readonly != readonly) {
memory_region_transaction_begin();
mr->readonly = readonly;
mr->uc->memory_region_update_pending |= mr->enabled;
memory_region_transaction_commit(mr);
}
}

View File

@ -35,6 +35,32 @@ static void test_map_wrapping()
OK(uc_close(uc));
}
static void test_mem_protect()
{
uc_engine *qc;
int r_eax = 0x2000;
int r_esi = 0xdeadbeef;
uint32_t mem;
// add [eax + 4], esi
char code[] = {0x01, 0x70, 0x04};
OK(uc_open(UC_ARCH_X86, UC_MODE_32, &qc));
OK(uc_reg_write(qc, UC_X86_REG_EAX, &r_eax));
OK(uc_reg_write(qc, UC_X86_REG_ESI, &r_esi));
OK(uc_mem_map(qc, 0x1000, 0x1000, UC_PROT_READ | UC_PROT_EXEC));
OK(uc_mem_map(qc, 0x2000, 0x1000, UC_PROT_READ));
OK(uc_mem_protect(qc, 0x2000, 0x1000, UC_PROT_READ | UC_PROT_WRITE));
OK(uc_mem_write(qc, 0x1000, code, sizeof(code)));
OK(uc_emu_start(qc, 0x1000, 0x1000 + sizeof(code) - 1, 0, 1));
OK(uc_mem_read(qc, 0x2000 + 4, &mem, 4));
TEST_CHECK(mem == 0xdeadbeef);
OK(uc_close(qc));
}
TEST_LIST = {{"test_map_correct", test_map_correct},
{"test_map_wrapping", test_map_wrapping},
{"test_mem_protect", test_mem_protect},
{NULL, NULL}};