mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 00:05:36 +00:00
python: support uc_mem_regions() API
This commit is contained in:
parent
e4c7c3dbe4
commit
a735576dd3
|
@ -105,6 +105,14 @@ uc_engine = ctypes.c_void_p
|
|||
uc_context = ctypes.c_void_p
|
||||
uc_hook_h = ctypes.c_size_t
|
||||
|
||||
class _uc_mem_region(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("begin", ctypes.c_uint64),
|
||||
("end", ctypes.c_uint64),
|
||||
("perms", ctypes.c_uint32),
|
||||
]
|
||||
|
||||
|
||||
_setup_prototype(_uc, "uc_version", ctypes.c_uint, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
|
||||
_setup_prototype(_uc, "uc_arch_supported", ctypes.c_bool, ctypes.c_int)
|
||||
_setup_prototype(_uc, "uc_open", ucerr, ctypes.c_uint, ctypes.c_uint, ctypes.POINTER(uc_engine))
|
||||
|
@ -127,6 +135,7 @@ _setup_prototype(_uc, "uc_context_alloc", ucerr, uc_engine, ctypes.POINTER(uc_co
|
|||
_setup_prototype(_uc, "uc_free", ucerr, ctypes.c_void_p)
|
||||
_setup_prototype(_uc, "uc_context_save", ucerr, uc_engine, uc_context)
|
||||
_setup_prototype(_uc, "uc_context_restore", ucerr, uc_engine, uc_context)
|
||||
_setup_prototype(_uc, "uc_mem_regions", ucerr, uc_engine, ctypes.POINTER(ctypes.POINTER(_uc_mem_region)), ctypes.POINTER(ctypes.c_uint32))
|
||||
|
||||
# uc_hook_add is special due to variable number of arguments
|
||||
_uc.uc_hook_add = _uc.uc_hook_add
|
||||
|
@ -508,6 +517,21 @@ class Uc(object):
|
|||
if status != uc.UC_ERR_OK:
|
||||
raise UcError(status)
|
||||
|
||||
# this returns a generator of regions in the form (begin, end, perms)
|
||||
def mem_regions(self):
|
||||
regions = ctypes.POINTER(_uc_mem_region)()
|
||||
count = ctypes.c_uint32()
|
||||
status = _uc.uc_mem_regions(self._uch, ctypes.byref(regions), ctypes.byref(count))
|
||||
if status != uc.UC_ERR_OK:
|
||||
raise UcError(status)
|
||||
|
||||
try:
|
||||
for i in range(count.value):
|
||||
yield (regions[i].begin, regions[i].end, regions[i].perms)
|
||||
finally:
|
||||
_uc.uc_free(regions)
|
||||
|
||||
|
||||
class SavedContext(object):
|
||||
def __init__(self, pointer):
|
||||
self.pointer = pointer
|
||||
|
|
Loading…
Reference in a new issue