Minor PEP8 and linter-friendly changes

This commit is contained in:
elicn
2022-10-14 00:01:26 +03:00
parent 1b3d22c06a
commit 0e63841628
5 changed files with 12 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ from .types import UcReg128
ARMCPReg = Tuple[int, int, int, int, int, int, int]
ARMCPRegValue = Tuple[int, int, int, int, int, int, int, int]
class UcRegCP(ctypes.Structure):
"""ARM coprocessors registers for instructions MRC, MCR, MRRC, MCRR
"""
@@ -57,7 +58,6 @@ class UcAArch32(Uc):
return next((cls for rng, cls in reg_class if reg_id in rng), None)
def reg_read(self, reg_id: int, aux: Any = None):
# select register class for special cases
reg_cls = UcAArch32.__select_reg_class(reg_id)

View File

@@ -91,7 +91,6 @@ class UcAArch64(Uc):
return getattr(self, '_Uc__do_hook_add')(htype, fptr, begin, end, insn)
@staticmethod
def __select_reg_class(reg_id: int):
"""Select class for special architectural registers.
@@ -104,7 +103,6 @@ class UcAArch64(Uc):
return next((cls for rng, cls in reg_class if reg_id in rng), None)
def reg_read(self, reg_id: int, aux: Any = None):
# select register class for special cases
reg_cls = UcAArch64.__select_reg_class(reg_id)

View File

@@ -145,7 +145,6 @@ class UcIntel(Uc):
return getattr(self, '_Uc__do_hook_add')(htype, fptr, begin, end, insn)
@staticmethod
def __select_reg_class(reg_id: int):
"""Select class for special architectural registers.
@@ -161,7 +160,6 @@ class UcIntel(Uc):
return next((cls for rng, cls in reg_class if reg_id in rng), None)
def reg_read(self, reg_id: int, aux: Any = None):
# select register class for special cases
reg_cls = UcIntel.__select_reg_class(reg_id)
@@ -198,10 +196,8 @@ class UcIntel(Uc):
else:
self._reg_write(reg_id, reg_cls, value)
def msr_read(self, msr_id: int) -> int:
return self._reg_read(const.UC_X86_REG_MSR, UcRegMSR, msr_id)
def msr_write(self, msr_id: int, value: int) -> None:
self._reg_write(const.UC_X86_REG_MSR, UcRegMSR, (msr_id, value))

View File

@@ -4,7 +4,6 @@
import ctypes
uc_err = ctypes.c_int
uc_mode = ctypes.c_int
uc_arch = ctypes.c_int

View File

@@ -334,7 +334,7 @@ class RegStateManager:
return reg.value
def _reg_write(self, reg_id: int, regtype, value) -> None:
def _reg_write(self, reg_id: int, regtype: Type, value) -> None:
"""Register write helper method.
"""
@@ -496,7 +496,7 @@ class Uc(RegStateManager):
# 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] = {}
self._mmio_callbacks: MutableMapping[Tuple[int, int], Tuple[Optional[ctypes._FuncPointer], Optional[ctypes._FuncPointer]]] = {}
self._mmio_callbacks: MutableMapping[Tuple[int, int], Tuple[Optional[MMIO_READ_CFUNC], Optional[MMIO_WRITE_CFUNC]]] = {}
self._hook_exception: Optional[Exception] = None
@@ -548,7 +548,6 @@ class Uc(RegStateManager):
if self._hook_exception is not None:
raise self._hook_exception
def emu_stop(self) -> None:
"""Stop emulation.
@@ -752,15 +751,15 @@ class Uc(RegStateManager):
def __do_hook_add(self, htype: int, fptr: ctypes._FuncPointer, begin: int, end: int, *args: ctypes.c_int) -> int:
handle = uc_hook_h()
# TODO: we do not need a callback counter to reference the callback and user data anymore.
# that said, we could still use the hook handler as auxiliary data - but for that we would
# need to pass a pointer since the handler is set by this very function call.
#
# for now just pass a dummy value
# TODO: we do not need a callback counter to reference the callback and user data anymore,
# so just pass a dummy value. that value will become the unused 'key' argument
dummy = 0
status = uclib.uc_hook_add(
self._uch, ctypes.byref(handle), htype, fptr,
self._uch,
ctypes.byref(handle),
htype,
fptr,
ctypes.cast(dummy, ctypes.c_void_p),
ctypes.c_uint64(begin),
ctypes.c_uint64(end),
@@ -1023,10 +1022,10 @@ class Uc(RegStateManager):
)
def ctl_get_exits(self) -> Sequence[int]:
l = self.ctl_get_exits_cnt()
arr = (ctypes.c_uint64 * l)()
count = self.ctl_get_exits_cnt()
arr = (ctypes.c_uint64 * count)()
self.ctl(uc.UC_CTL_UC_EXITS, uc.UC_CTL_IO_READ, ctypes.cast(arr, ctypes.c_void_p), ctypes.c_size_t(l))
self.ctl(uc.UC_CTL_UC_EXITS, uc.UC_CTL_IO_READ, ctypes.cast(arr, ctypes.c_void_p), ctypes.c_size_t(count))
return tuple(i for i in arr)