new API uc_mem_regions() to retrieve the list of memory regions mapped by uc_mem_map_*()

This commit is contained in:
Nguyen Anh Quynh
2016-01-16 16:57:17 +08:00
parent d0125eb8bf
commit 3d8f413ce8
2 changed files with 53 additions and 0 deletions

28
uc.c
View File

@ -1138,3 +1138,31 @@ uc_err uc_hook_del(uc_engine *uc, uc_hook hh)
{
return hook_del(uc, hh);
}
UNICORN_EXPORT
uint32_t uc_mem_regions(uc_engine *uc, uc_mem_region **regions, uint32_t *count)
{
uint32_t i;
uc_mem_region *r = NULL;
*count = uc->mapped_block_count;
if (*count) {
r = malloc(*count * sizeof(uc_mem_region));
if (r == NULL) {
// out of memory
return UC_ERR_NOMEM;
}
}
for (i = 0; i < *count; i++) {
r[i].begin = uc->mapped_blocks[i]->addr;
r[i].end = uc->mapped_blocks[i]->end - 1;
r[i].perms = uc->mapped_blocks[i]->perms;
}
*regions = r;
return UC_ERR_OK;
}