本文整理汇总了Python中unicorn.UcError方法的典型用法代码示例。如果您正苦于以下问题:Python unicorn.UcError方法的具体用法?Python unicorn.UcError怎么用?Python unicorn.UcError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unicorn
的用法示例。
在下文中一共展示了unicorn.UcError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: concrete_emulate
# 需要导入模块: import unicorn [as 别名]
# 或者: from unicorn import UcError [as 别名]
def concrete_emulate(self, insn):
"""
Start executing in Unicorn from this point until we hit a syscall or reach break_unicorn_at
:param capstone.CsInsn insn: The instruction object to emulate
"""
if not self.emu:
self.emu = ConcreteUnicornEmulator(self)
self.emu._stop_at = self._break_unicorn_at
try:
self.emu.emulate(insn)
except unicorn.UcError as e:
if e.errno == unicorn.UC_ERR_INSN_INVALID:
text_bytes = " ".join("%02x" % x for x in insn.bytes)
logger.error(
"Unimplemented instruction: 0x%016x:\t%s\t%s\t%s",
insn.address,
text_bytes,
insn.mnemonic,
insn.op_str,
)
raise InstructionEmulationError(str(e))
示例2: run
# 需要导入模块: import unicorn [as 别名]
# 或者: from unicorn import UcError [as 别名]
def run(self, pc, timeout_seconds=1):
# checking which instruction you want to emulate: THUMB/THUMB2 or others
# Note we start at ADDRESS | 1 to indicate THUMB mode.
try:
if self.ask_arch == 'armt' and self.ask_attrib == 'l':
self.mu.emu_start(pc | 1, END_ADDR, timeout_seconds * unicorn.UC_SECOND_SCALE)
else:
self.mu.emu_start(pc, END_ADDR, timeout_seconds * unicorn.UC_SECOND_SCALE)
except unicorn.UcError as e:
if getattr(self.cpu, self.ira.pc.name) != END_ADDR:
raise UnexpectedStopException()
finally:
self.mu.emu_stop()
示例3: write_memory
# 需要导入模块: import unicorn [as 别名]
# 或者: from unicorn import UcError [as 别名]
def write_memory(self, address, wordsize, val, num_words=1, raw=False):
"""Write memory.
:param address: the address to write to
:param wordsize: size of a written word (1, 2, 4 or 8)
:param val: the value to write
:type val: int if num_words == 1 and raw == False,
list of int if num_words > 1 and raw == False,
str or byte if raw == True
:param num_words: the amount of words to write
:param raw: whether to write in raw mode
:return: True on success, False otherwise
"""
if raw:
raw_mem = val
else:
# TODO: endianness support
num2fmt = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}
fmt = '<{}{}'.format(num_words, num2fmt[wordsize])
if num_words == 1:
raw_mem = struct.pack(fmt, val)
else:
raw_mem = struct.pack(fmt, *val)
try:
self.uc.mem_write(address, raw_mem)
return True
except unicorn.UcError:
self.log.debug('Failed memory write @ 0x{:x}'.format(address))
return False
# Register protocol
示例4: backup_emulate
# 需要导入模块: import unicorn [as 别名]
# 或者: from unicorn import UcError [as 别名]
def backup_emulate(self, insn):
"""
If we could not handle emulating an instruction, use Unicorn to emulate
it.
:param capstone.CsInsn instruction: The instruction object to emulate
"""
if not hasattr(self, "backup_emu"):
self.backup_emu = UnicornEmulator(self)
try:
self.backup_emu.emulate(insn)
except unicorn.UcError as e:
if e.errno == unicorn.UC_ERR_INSN_INVALID:
text_bytes = " ".join("%02x" % x for x in insn.bytes)
logger.error(
"Unimplemented instruction: 0x%016x:\t%s\t%s\t%s",
insn.address,
text_bytes,
insn.mnemonic,
insn.op_str,
)
raise InstructionEmulationError(str(e))
finally:
# We have been seeing occasional Unicorn issues with it not clearing
# the backing unicorn instance. Saw fewer issues with the following
# line present.
del self.backup_emu
示例5: get_imp
# 需要导入模块: import unicorn [as 别名]
# 或者: from unicorn import UcError [as 别名]
def get_imp(uc, rva, base_addr, SizeOfImportTable, read_values=False):
rva += base_addr
entry_size = len(bytes(IMAGE_IMPORT_DESCRIPTOR()))
num_of_dll = SizeOfImportTable // entry_size
imp_info_list = []
imp_struct_list = []
for i in range(num_of_dll):
uc_imp = uc.mem_read(rva, entry_size)
imp_struct = IMAGE_IMPORT_DESCRIPTOR.from_buffer(uc_imp)
imp_struct_list.append(imp_struct)
if read_values:
try:
dll_name = get_string(getattr(imp_struct, "Name") + base_addr, uc, break_on_unprintable=True)
imp_names = []
rva_to_iat = getattr(imp_struct, "FirstThunk")
while True:
new_val = struct.unpack("<I", uc.mem_read(base_addr + rva_to_iat, 4))[0]
if new_val == 0:
break
imp_name = (get_string(new_val + 2 + base_addr, uc, break_on_unprintable=True), rva_to_iat)
imp_names.append(imp_name)
rva_to_iat += 4
imp_info_list.append(ImportValues(imp_struct, dll_name, imp_names))
except UcError as ue:
return imp_info_list
rva += entry_size
if read_values:
return imp_info_list
return imp_struct_list
# Deprecated