Skip to content

Commit 0a876d3

Browse files
committed
Allow setting CPU model on Uc initialization
1 parent cef2b33 commit 0a876d3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bindings/python/unicorn/unicorn.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def __is_compliant() -> bool:
439439

440440
return (uc_maj, uc_min) == (bnd_maj, bnd_min)
441441

442-
def __new__(cls, arch: int, mode: int):
442+
def __new__(cls, arch: int, mode: int, cpu: Optional[int] = None):
443443
# verify version compatibility with the core before doing anything
444444
if not Uc.__is_compliant():
445445
raise UcError(uc.UC_ERR_VERSION)
@@ -479,12 +479,13 @@ def __uc_generic():
479479
# return the appropriate unicorn subclass type
480480
return super(Uc, cls).__new__(subclass)
481481

482-
def __init__(self, arch: int, mode: int) -> None:
482+
def __init__(self, arch: int, mode: int, cpu: Optional[int] = None) -> None:
483483
"""Initialize a Unicorn engine instance.
484484
485485
Args:
486486
arch: emulated architecture identifier (see UC_ARCH_* constants)
487487
mode: emulated processor mode (see UC_MODE_* constants)
488+
cpu: emulated cpu model (see UC_CPU_* constants) [optional]
488489
"""
489490

490491
self._arch = arch
@@ -498,6 +499,9 @@ def __init__(self, arch: int, mode: int) -> None:
498499
self._uch = None
499500
raise UcError(status)
500501

502+
if cpu is not None:
503+
self.ctl_set_cpu_model(cpu)
504+
501505
# we have to keep a reference to the callbacks so they do not get gc-ed
502506
# see: https://docs.python.org/3/library/ctypes.html#callback-functions
503507
self._callbacks: MutableMapping[int, ctypes._FuncPointer] = {}

0 commit comments

Comments
 (0)