How to use the pyvex.IRStmt function in pyvex

To help you get started, we’ve selected a few pyvex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angr / angr / simuvex / s_irsb.py View on Github external
for stmt in self.irsb.statements():
			if type(stmt) == pyvex.IRStmt.IMark:
				self.last_imark = stmt
			elif type(stmt) == pyvex.IRStmt.Exit:
				l.debug("%s adding conditional exit", self)
				e = SimExit(expr=self.state.BVV(stmt.offsIP, self.state.arch.bits), guard=guard, state=self.state, source=self.state.BVV(self.last_imark.addr, self.state.arch.bits), jumpkind=self.irsb.jumpkind, simplify=False)
				self.conditional_exits.append(e)
				self.add_exits(e)

				if self.irsb.jumpkind == 'Ijk_Call' and o.DO_RET_EMULATION in self.state.options:
					self.postcall_exit = SimExit(expr=self.state.BVV(self.last_imark.addr+self.last_imark.len, self.state.arch.bits), guard=guard, state=self.state, source=self.state.BVV(self.last_imark.addr, self.state.arch.bits), jumpkind='Ijk_Ret', simplify=False)
					self.add_exits(self.postcall_exit)
			elif type(stmt) == pyvex.IRStmt.WrTmp:
				temps[stmt.tmp] = self._fastpath_irexpr(stmt.data, temps, regs)
			elif type(stmt) == pyvex.IRStmt.Put:
				regs[stmt.offset] = self._fastpath_irexpr(stmt.data, temps, regs)
			else:
				continue

		next_expr = self._fastpath_irexpr(self.irsb.next, temps, regs)
		if next_expr is not None:
			self.has_default_exit = True
			self.default_exit = SimExit(expr=next_expr, guard=guard, state=self.state, jumpkind=self.irsb.jumpkind, simplify=False, source=self.state.BVV(self.last_imark.addr, self.state.arch.bits))
			self.add_exits(self.default_exit)

			if self.irsb.jumpkind == 'Ijk_Call' and o.DO_RET_EMULATION in self.state.options:
				self.postcall_exit = SimExit(expr=self.state.BVV(self.last_imark.addr+self.last_imark.len, self.state.arch.bits), guard=guard, state=self.state, source=self.state.BVV(self.last_imark.addr, self.state.arch.bits), jumpkind='Ijk_Ret', simplify=False)
				self.add_exits(self.postcall_exit)
github angr / angr / simuvex / s_irsb.py View on Github external
if self.whitelist is not None and stmt_idx not in self.whitelist:
				l.debug("... whitelist says skip it!")
				continue
			elif self.whitelist is not None:
				l.debug("... whitelist says analyze it!")

			# process it!
			self.state._inspect('statement', BP_BEFORE, statement=stmt_idx)
			s_stmt = SimIRStmt(stmt, self.last_imark, self.addr, stmt_idx, self.state, self.irsb.tyenv)
			self.add_refs(*s_stmt.refs)
			self.statements.append(s_stmt)
			self.state._inspect('statement', BP_AFTER)

			# for the exits, put *not* taking the exit on the list of constraints so
			# that we can continue on. Otherwise, add the constraints
			if type(stmt) == pyvex.IRStmt.Exit:
				e = SimExit(sexit = s_stmt)
				self.default_exit_guard = self.state.se.And(self.default_exit_guard, self.state.se.Not(e.guard))

				l.debug("%s adding conditional exit", self)
				self.conditional_exits.append(e)
				self.add_exits(e)

				if o.SINGLE_EXIT in self.state.options and not self.state.se.symbolic(e.guard) and e.reachable() != 0:
					l.debug("%s returning after taken exit due to SINGLE_EXIT option.", self)
					return

		if self.last_stmt is None:
			self.has_default_exit = True
github angr / angr / angr / analyses / stack_pointer_tracker.py View on Github external
def resolve_stmt(stmt):
            if type(stmt) is pyvex.IRStmt.WrTmp:
                tmps[stmt.tmp] = resolve_expr(stmt.data)
            elif self.track_mem and type(stmt) is pyvex.IRStmt.Store:
                state.store(resolve_expr(stmt.addr), resolve_expr(stmt.data))
            elif type(stmt) is pyvex.IRStmt.Put:
                state.put(stmt.offset, resolve_expr(stmt.data))
            else:
                raise CouldNotResolveException
github angr / angr / angr / lifter.py View on Github external
stmts = block.statements
        tmp_exit = None
        exit_stmt_idx = None
        dst = None

        for i, stmt in reversed(list(enumerate(stmts))):
            if tmp_exit is None:
                # Looking for the Exit statement
                if isinstance(stmt, pyvex.IRStmt.Exit) and \
                        isinstance(stmt.guard, pyvex.IRExpr.RdTmp):
                    tmp_exit = stmt.guard.tmp
                    dst = stmt.dst
                    exit_stmt_idx = i
            else:
                # Looking for the WrTmp statement
                if isinstance(stmt, pyvex.IRStmt.WrTmp) and \
                                stmt.tmp == tmp_exit:
                    if isinstance(stmt.data, pyvex.IRExpr.Binop) and \
                                    stmt.data.op == 'Iop_CmpEQ32' and \
                            isinstance(stmt.data.child_expressions[0], pyvex.IRExpr.Const) and \
                            isinstance(stmt.data.child_expressions[1], pyvex.IRExpr.Const) and \
                                    stmt.data.child_expressions[0].con.value == stmt.data.child_expressions[
                                1].con.value:

                        # Create a new IRConst
                        irconst = pyvex.IRExpr.Const.__new__()  # XXX: does this work???
                        irconst.con = dst
                        irconst.is_atomic = True
                        irconst.result_type = dst.type
                        irconst.tag = 'Iex_Const'

                        block.statements = block.statements[: exit_stmt_idx] + block.statements[exit_stmt_idx + 1:]