Apply repr for C structs
This commit is contained in:
@@ -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
|
||||
@@ -13,6 +13,9 @@ from .types import UcTupledReg, UcReg128
|
||||
|
||||
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.
|
||||
|
||||
@@ -18,7 +18,7 @@ ARM64CPReg = Tuple[int, int, int, int, int, int]
|
||||
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 @@ class UcAArch64(Uc):
|
||||
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 @@ class UcAArch64(Uc):
|
||||
|
||||
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 @@ class UcAArch64(Uc):
|
||||
|
||||
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
|
||||
|
||||
@@ -10,6 +10,9 @@ from .arch.types import *
|
||||
|
||||
__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:
|
||||
|
||||
Reference in New Issue
Block a user