Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def insn_observe(self, insn_addr, stmt, block, state, op_type):
"""
:param int insn_addr:
:param ailment.Stmt.Statement|pyvex.stmt.IRStmt stmt:
:param angr.Block block:
:param angr.analyses.reaching_definitions.LiveDefinitions state:
:param angr.analyses.reaching_definitions.constants op_type: OP_BEFORE, OP_AFTER
"""
key = 'insn', insn_addr, op_type
if self._observe_all or \
self._observation_points is not None and key in self._observation_points:
if isinstance(stmt, pyvex.stmt.IRStmt):
# it's an angr block
vex_block = block.vex
# OP_BEFORE: stmt has to be IMark
if op_type == OP_BEFORE and type(stmt) is pyvex.stmt.IMark:
self.observed_results[key] = state.copy()
# OP_AFTER: stmt has to be last stmt of block or next stmt has to be IMark
elif op_type == OP_AFTER:
idx = vex_block.statements.index(stmt)
if idx == len(vex_block.statements) - 1 or type(
vex_block.statements[idx + 1]) is pyvex.IRStmt.IMark:
self.observed_results[key] = state.copy()
elif isinstance(stmt, ailment.Stmt.Statement):
# it's an AIL block
self.observed_results[key] = state.copy()
def annotate_content(self, node, content):
if node.obj.is_simprocedure or node.obj.is_syscall:
return
st = self.bs.chosen_statements[node.obj.addr]
staddr = set()
#TODO
vex = self.bs.project.factory.block(addr=node.obj.addr, max_size=node.obj.size).vex
caddr = None
for j, s in enumerate(vex.statements):
if isinstance(s, pyvex.stmt.IMark):
caddr = s.addr
if j in st:
staddr.add(caddr)
for c in content['data']:
if c['_addr'] in staddr:
c['addr']['style'] = 'B'
c['mnemonic']['style'] = 'B'
c['operands']['style'] = 'B'
c['taint'] = {
'content':'[*]',
'style':'B'
}
def _first_stoppoint(self, irsb, extra_stop_points=None):
"""
Enumerate the imarks in the block. If any of them (after the first one) are at a stop point, returns the address
of the stop point. None is returned otherwise.
"""
if extra_stop_points is None and self.project is None:
return None
first_imark = True
for stmt in irsb.statements:
if type(stmt) is pyvex.stmt.IMark: # pylint: disable=unidiomatic-typecheck
addr = stmt.addr + stmt.delta
if not first_imark:
if self.__is_stop_point(addr, extra_stop_points):
# could this part be moved by pyvex?
return addr
if stmt.delta != 0 and self.__is_stop_point(stmt.addr, extra_stop_points):
return addr
first_imark = False
return None
def _Get_Statement(self,s): # 태그마다 ë‚˜ëˆ ì„œ 처리 해야함 (미구현)
stat = {}
stat['tag'] = s.tag
stat['pp'] = str(s)
if isinstance(s,pyvex.stmt.IMark):
self.old_addr = s.addr
self.stat_count = 0
stat['count'] = self.stat_count
stat['addr'] = self.old_addr
if isinstance(s,pyvex.stmt.WrTmp):
stat['data'] = {}
stat['data']['tag'] = s.data.tag
if('op' in s.data.__dict__.keys()):
stat['data']['op'] = s.data.op
self.stat_count += 1
return stat
def _first_stoppoint(self, irsb, extra_stop_points=None):
"""
Enumerate the imarks in the block. If any of them (after the first one) are at a stop point, returns the address
of the stop point. None is returned otherwise.
"""
if self._stop_points is None and extra_stop_points is None and self.project is None:
return None
first_imark = True
for stmt in irsb.statements:
if type(stmt) is pyvex.stmt.IMark: # pylint: disable=unidiomatic-typecheck
addr = stmt.addr + stmt.delta
if not first_imark:
if self.is_stop_point(addr, extra_stop_points):
# could this part be moved by pyvex?
return addr
if stmt.delta != 0 and self.is_stop_point(stmt.addr, extra_stop_points):
return addr
first_imark = False
return None
def __init_handlers(self):
self._vex_expr_handlers = [None]*pyvex.expr.tag_count
self._vex_stmt_handlers = [None]*pyvex.stmt.tag_count
for name, cls in vars(pyvex.expr).items():
if isinstance(cls, type) and issubclass(cls, pyvex.expr.IRExpr) and cls is not pyvex.expr.IRExpr:
self._vex_expr_handlers[cls.tag_int] = getattr(self, '_handle_vex_expr_' + name)
for name, cls in vars(pyvex.stmt).items():
if isinstance(cls, type) and issubclass(cls, pyvex.stmt.IRStmt) and cls is not pyvex.stmt.IRStmt:
self._vex_stmt_handlers[cls.tag_int] = getattr(self, '_handle_vex_stmt_' + name)
assert None not in self._vex_expr_handlers
assert None not in self._vex_stmt_handlers
def __init_handlers(self):
self._vex_expr_handlers = [None]*pyvex.expr.tag_count
self._vex_stmt_handlers = [None]*pyvex.stmt.tag_count
for name, cls in vars(pyvex.expr).items():
if isinstance(cls, type) and issubclass(cls, pyvex.expr.IRExpr) and cls is not pyvex.expr.IRExpr:
self._vex_expr_handlers[cls.tag_int] = getattr(self, '_handle_vex_expr_' + name)
for name, cls in vars(pyvex.stmt).items():
if isinstance(cls, type) and issubclass(cls, pyvex.stmt.IRStmt) and cls is not pyvex.stmt.IRStmt:
self._vex_stmt_handlers[cls.tag_int] = getattr(self, '_handle_vex_stmt_' + name)
assert None not in self._vex_expr_handlers
assert None not in self._vex_stmt_handlers