From 0a876d30eac5d94270a882e7c0607c27064b05fe Mon Sep 17 00:00:00 2001 From: elicn Date: Fri, 14 Jul 2023 00:44:58 +0300 Subject: [PATCH] Allow setting CPU model on Uc initialization --- bindings/python/unicorn/unicorn.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 25b7b084..17093835 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -439,7 +439,7 @@ class Uc(RegStateManager): return (uc_maj, uc_min) == (bnd_maj, bnd_min) - def __new__(cls, arch: int, mode: int): + def __new__(cls, arch: int, mode: int, cpu: Optional[int] = None): # verify version compatibility with the core before doing anything if not Uc.__is_compliant(): raise UcError(uc.UC_ERR_VERSION) @@ -479,12 +479,13 @@ class Uc(RegStateManager): # return the appropriate unicorn subclass type return super(Uc, cls).__new__(subclass) - def __init__(self, arch: int, mode: int) -> None: + def __init__(self, arch: int, mode: int, cpu: Optional[int] = None) -> None: """Initialize a Unicorn engine instance. Args: arch: emulated architecture identifier (see UC_ARCH_* constants) mode: emulated processor mode (see UC_MODE_* constants) + cpu: emulated cpu model (see UC_CPU_* constants) [optional] """ self._arch = arch @@ -498,6 +499,9 @@ class Uc(RegStateManager): self._uch = None raise UcError(status) + if cpu is not None: + self.ctl_set_cpu_model(cpu) + # we have to keep a reference to the callbacks so they do not get gc-ed # see: https://docs.python.org/3/library/ctypes.html#callback-functions self._callbacks: MutableMapping[int, ctypes._FuncPointer] = {}