Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getAllXrefsTo(vw, va):
import vivisect
#manually parse the preceding instruction & look to see if it can fall through to us
#make a copy of the xrefs!!! or badness will ensue
init = vw.getXrefsTo(va)[:]
prev = vw.getPrevLocation(va)
if prev is None:
return init
lva, lsize, ltype, linfo = prev
if ltype != vivisect.const.LOC_OP:
return init
try:
op = vw.parseOpcode(lva)
except Exception:
print ('Weird error while doing getAllXrefsTo: %s' % str(err))
return init
brlist = op.getBranches()
for tova,bflags in brlist:
if tova == va:
init.append( (lva, tova, vivisect.const.REF_CODE, bflags) )
return init
def get_prev_opcode(vw, va):
prev_item = vw.getPrevLocation(va)
if prev_item is None:
raise RuntimeError('failed to find prev instruction for va: %x', va)
lva, lsize, ltype, linfo = prev_item
if ltype != vivisect.const.LOC_OP:
raise RuntimeError('failed to find prev instruction for va: %x', va)
try:
op = vw.parseOpcode(lva)
except Exception:
logger.warning('failed to parse prev instruction for va: %x', va)
raise
return op