change mem read/write APIs to use void*

Don't force the user to use uint8_t pointers, or cast their
pointers-to-other-objects to uint8_t* when calling these APIs.
This commit is contained in:
Jonathon Reinhart 2015-09-07 12:44:03 -04:00
parent 2b4caeed37
commit f6cecf45d2
2 changed files with 8 additions and 4 deletions

View file

@ -313,7 +313,7 @@ uc_err uc_reg_read(uc_engine *uc, int regid, void *value);
for detailed error).
*/
UNICORN_EXPORT
uc_err uc_mem_write(uc_engine *uc, uint64_t address, const uint8_t *bytes, size_t size);
uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *bytes, size_t size);
/*
Read a range of bytes in memory.
@ -329,7 +329,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const uint8_t *bytes, size_
for detailed error).
*/
UNICORN_EXPORT
uc_err uc_mem_read(uc_engine *uc, uint64_t address, uint8_t *bytes, size_t size);
uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *bytes, size_t size);
/*
Emulate machine code in a specific duration of time.

8
uc.c
View file

@ -331,8 +331,10 @@ static bool check_mem_area(uc_engine *uc, uint64_t address, size_t size)
UNICORN_EXPORT
uc_err uc_mem_read(uc_engine *uc, uint64_t address, uint8_t *bytes, size_t size)
uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size)
{
uint8_t *bytes = _bytes;
if (!check_mem_area(uc, address, size))
return UC_ERR_MEM_READ;
@ -359,8 +361,10 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, uint8_t *bytes, size_t size)
}
UNICORN_EXPORT
uc_err uc_mem_write(uc_engine *uc, uint64_t address, const uint8_t *bytes, size_t size)
uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, size_t size)
{
const uint8_t *bytes = _bytes;
if (!check_mem_area(uc, address, size))
return UC_ERR_MEM_WRITE;