Step one towards uc_mem_protect, uc_mem_unmap, and support for UC_PROT_EXEC and NX regions

This commit is contained in:
Chris Eagle
2015-08-28 18:59:45 -07:00
parent 7f63d76908
commit 9ba59e4988
3 changed files with 163 additions and 38 deletions

View File

@ -151,6 +151,7 @@ typedef enum uc_mem_type {
UC_MEM_READ_WRITE, // Memory is accessed (either READ or WRITE)
UC_MEM_WRITE_NW, // write to non-writable
UC_MEM_READ_NR, // read from non-readable
UC_MEM_NX, // read from non-readable
} uc_mem_type;
// All type of hooks for uc_hook_add() API.
@ -391,12 +392,13 @@ uc_err uc_hook_del(uch handle, uch *h2);
typedef enum uc_prot {
UC_PROT_READ = 1,
UC_PROT_WRITE = 2,
UC_PROT_EXEC = 4,
} uc_prot;
/*
Map memory in for emulation.
This API adds a memory region that can be used by emulation. The region is mapped
with permissions UC_PROT_READ | UC_PROT_WRITE.
with permissions UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC.
@handle: handle returned by uc_open()
@address: starting address of the new memory region to be mapped in.
@ -420,7 +422,7 @@ uc_err uc_mem_map(uch handle, uint64_t address, size_t size);
@size: size of the new memory region to be mapped in.
This size must be multiple of 4KB, or this will return with UC_ERR_MAP error.
@perms: Permissions for the newly mapped region.
This must be some combination of UC_PROT_READ | UC_PROT_WRITE,
This must be some combination of UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC,
or this will return with UC_ERR_MAP error.
@return UC_ERR_OK on success, or other value on failure (refer to uc_err enum
@ -429,6 +431,25 @@ uc_err uc_mem_map(uch handle, uint64_t address, size_t size);
UNICORN_EXPORT
uc_err uc_mem_map_ex(uch handle, uint64_t address, size_t size, uint32_t perms);
/*
Set memory permissions for emulation memory.
This API changes permissions on an existing memory region.
@handle: handle returned by uc_open()
@start: starting address of the memory region to be modified.
This address must be aligned to 4KB, or this will return with UC_ERR_MAP error.
@block_size: size of the memory region to be modified.
This size must be multiple of 4KB, or this will return with UC_ERR_MAP error.
@perms: New permissions for the mapped region.
This must be some combination of UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC,
or this will return with UC_ERR_MAP error.
@return UC_ERR_OK on success, or other value on failure (refer to uc_err enum
for detailed error).
*/
UNICORN_EXPORT
uc_err uc_mem_protect(uch handle, uint64_t start, size_t block_size, uint32_t perms);
#ifdef __cplusplus
}
#endif