|
|
|
|
@ -168,7 +168,7 @@ class Emulator:
|
|
|
|
|
if DEBUG:
|
|
|
|
|
self.hook_add(U.UC_HOOK_CODE, self.trace_hook)
|
|
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
|
def __getattr__(self, name: str):
|
|
|
|
|
reg = self.get_reg_enum(name)
|
|
|
|
|
|
|
|
|
|
if reg:
|
|
|
|
|
@ -237,7 +237,7 @@ class Emulator:
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def hook_mem_invalid(self, uc, access, address, size, value, user_data) -> bool:
|
|
|
|
|
def hook_mem_invalid(self, uc, access, address, size: int, value, user_data) -> bool:
|
|
|
|
|
debug("# Invalid access at %#x", address)
|
|
|
|
|
|
|
|
|
|
# Page-align the start address
|
|
|
|
|
@ -367,7 +367,7 @@ class Emulator:
|
|
|
|
|
# We're done emulating
|
|
|
|
|
return self._prev, self._curr
|
|
|
|
|
|
|
|
|
|
def until_jump_hook_code(self, _uc, address, instruction_size, _user_data) -> None:
|
|
|
|
|
def until_jump_hook_code(self, _uc, address, instruction_size: int, _user_data) -> None:
|
|
|
|
|
# We have not emulated any instructions yet.
|
|
|
|
|
if self._prev is None:
|
|
|
|
|
pass
|
|
|
|
|
@ -405,7 +405,7 @@ class Emulator:
|
|
|
|
|
self.emulate_with_hook(self.until_syscall_hook_code)
|
|
|
|
|
return (self.until_syscall_address, None)
|
|
|
|
|
|
|
|
|
|
def until_syscall_hook_code(self, uc, address, size, user_data) -> None:
|
|
|
|
|
def until_syscall_hook_code(self, uc, address, size: int, user_data) -> None:
|
|
|
|
|
data = binascii.hexlify(self.mem_read(address, size))
|
|
|
|
|
debug("# Executing instruction at %(address)#x with bytes %(data)s", locals())
|
|
|
|
|
self.until_syscall_address = address
|
|
|
|
|
@ -446,7 +446,7 @@ class Emulator:
|
|
|
|
|
yield a
|
|
|
|
|
a = self.single_step(pc)
|
|
|
|
|
|
|
|
|
|
def single_step_hook_code(self, _uc, address, instruction_size, _user_data) -> None:
|
|
|
|
|
def single_step_hook_code(self, _uc, address, instruction_size: int, _user_data) -> None:
|
|
|
|
|
# For whatever reason, the hook will hit twice on
|
|
|
|
|
# unicorn >= 1.0.2rc4, but not on unicorn-1.0.2rc1~unicorn-1.0.2rc3,
|
|
|
|
|
# So we use a counter to ensure the code run only once
|
|
|
|
|
@ -472,6 +472,6 @@ class Emulator:
|
|
|
|
|
value = self.uc.reg_read(enum)
|
|
|
|
|
debug("uc.reg_read(%(name)s) ==> %(value)x", locals())
|
|
|
|
|
|
|
|
|
|
def trace_hook(self, _uc, address, instruction_size, _user_data) -> None:
|
|
|
|
|
def trace_hook(self, _uc, address, instruction_size: int, _user_data) -> None:
|
|
|
|
|
data = binascii.hexlify(self.mem_read(address, instruction_size))
|
|
|
|
|
debug("# trace_hook: %#-8x %r", (address, data))
|
|
|
|
|
|