diff --git a/bindings/python/unicorn/unicorn_py3/arch/__init__.py b/bindings/python/unicorn/unicorn_py3/arch/__init__.py index e69de29bb2..1330905dc6 100644 --- a/bindings/python/unicorn/unicorn_py3/arch/__init__.py +++ b/bindings/python/unicorn/unicorn_py3/arch/__init__.py @@ -0,0 +1,4 @@ +# from .arm import UcRegCP +# from .arm64 import UcRegCP64 +# from .intel import UcRegFPR, UcRegMMR, UcRegMSR +# from .types import UcReg128, UcReg256, UcReg512, UcReg, UcLargeReg, UcTupledReg \ No newline at end of file diff --git a/bindings/python/unicorn/unicorn_py3/arch/arm.py b/bindings/python/unicorn/unicorn_py3/arch/arm.py index 0669072de5..7ec019b35b 100644 --- a/bindings/python/unicorn/unicorn_py3/arch/arm.py +++ b/bindings/python/unicorn/unicorn_py3/arch/arm.py @@ -13,6 +13,9 @@ ARMCPReg = Tuple[int, int, int, int, int, int, int, int] +def _structure_repr(self): + return "%s(%s)" % (self.__class__.__name__, ", ".join("%s=%s" % (k, getattr(self, k)) for (k, _) in self._fields_)) + class UcRegCP(UcTupledReg[ARMCPReg]): """ARM coprocessors registers for instructions MRC, MCR, MRRC, MCRR @@ -33,6 +36,7 @@ class UcRegCP(UcTupledReg[ARMCPReg]): def value(self) -> int: return self.val + __repr__ = _structure_repr class UcAArch32(Uc): """Unicorn subclass for ARM architecture. diff --git a/bindings/python/unicorn/unicorn_py3/arch/arm64.py b/bindings/python/unicorn/unicorn_py3/arch/arm64.py index 86ec1787b4..e6dcdb275c 100644 --- a/bindings/python/unicorn/unicorn_py3/arch/arm64.py +++ b/bindings/python/unicorn/unicorn_py3/arch/arm64.py @@ -18,7 +18,7 @@ HOOK_INSN_SYS_CFUNC = ctypes.CFUNCTYPE(ctypes.c_uint32, uc_engine, ctypes.c_uint32, ctypes.c_void_p, ctypes.c_void_p) -class UcRegCP(UcTupledReg[ARM64CPReg]): +class UcRegCP64(UcTupledReg[ARM64CPReg]): """ARM64 coprocessors registers for instructions MRS, MSR """ @@ -52,7 +52,7 @@ def hook_add(self, htype: int, callback: Callable, user_data: Any = None, begin: def __hook_insn_sys(): @uccallback(HOOK_INSN_SYS_CFUNC) def __hook_insn_sys_cb(handle: int, reg: int, pcp_reg: Any, key: int) -> int: - cp_reg = ctypes.cast(pcp_reg, ctypes.POINTER(UcRegCP)).contents + cp_reg = ctypes.cast(pcp_reg, ctypes.POINTER(UcRegCP64)).contents class CpReg(NamedTuple): crn: int @@ -102,7 +102,7 @@ def reg_read(self, reg_id: int, aux: Any = None): if reg_cls is None: if reg_id == const.UC_ARM64_REG_CP_REG: - return self._reg_read(reg_id, UcRegCP, *aux) + return self._reg_read(reg_id, UcRegCP64, *aux) else: # fallback to default reading method @@ -116,7 +116,7 @@ def reg_write(self, reg_id: int, value) -> None: if reg_cls is None: if reg_id == const.UC_ARM64_REG_CP_REG: - self._reg_write(reg_id, UcRegCP, value) + self._reg_write(reg_id, UcRegCP64, value) else: # fallback to default writing method diff --git a/bindings/python/unicorn/unicorn_py3/unicorn.py b/bindings/python/unicorn/unicorn_py3/unicorn.py index ad2d0c603c..4363039df8 100644 --- a/bindings/python/unicorn/unicorn_py3/unicorn.py +++ b/bindings/python/unicorn/unicorn_py3/unicorn.py @@ -10,6 +10,9 @@ __version__ = f'{uc.UC_VERSION_MAJOR}.{uc.UC_VERSION_MINOR}.{uc.UC_VERSION_PATCH}' +def _structure_repr(self): + return "%s(%s)" % (self.__class__.__name__, ", ".join("%s=%s" % (k, getattr(self, k)) for (k, _) in self._fields_)) + class _uc_mem_region(ctypes.Structure): _fields_ = ( @@ -22,6 +25,7 @@ class _uc_mem_region(ctypes.Structure): def value(self) -> Tuple[int, int, int]: return tuple(getattr(self, fname) for fname, _ in self._fields_) + __repr__ = _structure_repr class uc_tb(ctypes.Structure): """"TranslationBlock @@ -32,6 +36,8 @@ class uc_tb(ctypes.Structure): ('icount', ctypes.c_uint16), ('size', ctypes.c_uint16) ) + + __repr__ = _structure_repr def __load_uc_lib() -> ctypes.CDLL: