Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_thumb_object():
"""
Test for an object file I ripped out of an ARM firmware HAL.
Uses some nasty relocs
:return:
"""
path = os.path.join(test_location, "armel", "i2c_api.o")
l = cle.Loader(path, rebase_granularity=0x1000)
for r in l.main_object.relocs:
if r.__class__ == cle.backends.elf.relocation.arm.R_ARM_THM_JUMP24:
if r.symbol.name == 'HAL_I2C_ER_IRQHandler':
irsb = pyvex.lift(struct.pack('
# phase 4: get bytes
if insn_bytes is not None:
buff, size = insn_bytes, len(insn_bytes)
else:
buff, size = self._load_bytes(addr, size, state, clemory)
if not buff or size == 0:
raise SimEngineError("No bytes in memory for block starting at %#x." % addr)
# phase 5: call into pyvex
# l.debug("Creating pyvex.IRSB of arch %s at %#x", arch.name, addr)
try:
for subphase in range(2):
irsb = pyvex.lift(buff, addr + thumb, arch,
max_bytes=size,
max_inst=num_inst,
bytes_offset=thumb,
traceflags=traceflags,
opt_level=opt_level,
strict_block_end=strict_block_end,
skip_stmts=skip_stmts,
collect_data_refs=collect_data_refs,
)
if subphase == 0 and irsb.statements is not None:
# check for possible stop points
stop_point = self._first_stoppoint(irsb, extra_stop_points)
if stop_point is not None:
size = stop_point - addr
continue
def lift(self, addr=None, clemory=None, insn_bytes=None, size=None, arch=None, **kwargs):
if addr is None:
raise ValueError("addr must be specified.")
if insn_bytes is None:
if clemory is None:
raise ValueError("clemory must be specified if insn_bytes is None.")
insn_bytes = clemory.load(addr, size)
else:
size = len(insn_bytes)
if arch is None:
arch = archinfo.arch_from_id('bf')
irsb = pyvex.lift(insn_bytes, addr, arch, max_bytes=size)
return irsb
# phase 4: get bytes
if insn_bytes is not None:
buff, size = insn_bytes, len(insn_bytes)
else:
buff, size = self._load_bytes(addr, size, state, clemory)
if not buff or size == 0:
raise SimEngineError("No bytes in memory for block starting at %#x." % addr)
# phase 5: call into pyvex
# l.debug("Creating pyvex.IRSB of arch %s at %#x", arch.name, addr)
try:
for subphase in range(2):
irsb = pyvex.lift(buff, addr + thumb, arch,
max_bytes=size,
max_inst=num_inst,
bytes_offset=thumb,
traceflags=traceflags,
opt_level=opt_level,
strict_block_end=strict_block_end,
skip_stmts=skip_stmts,
collect_data_refs=collect_data_refs,
)
if subphase == 0 and irsb.statements is not None:
# check for possible stop points
stop_point = self._first_stoppoint(irsb, extra_stop_points)
if stop_point is not None:
size = stop_point - addr
continue