1 #ifndef ROSE_BinaryAnalysis_FeasiblePath_H
2 #define ROSE_BinaryAnalysis_FeasiblePath_H
3 #include <featureTests.h>
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
8 #include <Rose/BinaryAnalysis/SmtSolver.h>
9 #include <Rose/BinaryAnalysis/SymbolicExpressionParser.h>
10 #include <Rose/BinaryAnalysis/Partitioner2/CfgPath.h>
11 #include <Rose/Exception.h>
12 #include <Sawyer/CommandLine.h>
13 #include <Sawyer/Message.h>
14 #include <boost/filesystem/path.hpp>
15 #include <boost/logic/tribool.hpp>
17 namespace Rose {
18 namespace BinaryAnalysis {
23 class FeasiblePath {
25  // Types and public data members
27 public:
29  class Exception: public Rose::Exception {
30  public:
31  Exception(const std::string &what)
32  : Rose::Exception(what) {}
33  ~Exception() throw () {}
34  };
37  enum SearchMode {
41  };
47  };
54  };
57  enum IoMode { READ, WRITE };
60  enum MayOrMust { MAY, MUST };
63  typedef std::set<rose_addr_t> AddressSet;
71  struct Expression {
73  std::string parsable;
76  Expression() {}
77  /*implicit*/ Expression(const std::string &parsable): parsable(parsable) {}
78  /*implicit*/ Expression(const SymbolicExpression::Ptr &expr): expr(expr) {}
80  void print(std::ostream&) const;
81  };
84  struct Settings {
85  // Path feasibility
88  size_t maxVertexVisit;
89  size_t maxPathLength;
90  size_t maxCallDepth;
92  std::vector<Expression> assertions;
93  std::vector<std::string> assertionLocations;
94  std::vector<rose_addr_t> summarizeFunctions;
96  std::string solverName;
103  std::vector<rose_addr_t> ipRewrite;
105  size_t maxExprSize;
108  // Null dereferences
109  struct NullDeref {
110  bool check;
112  bool constOnly;
113  rose_addr_t minValid;
115  NullDeref()
116  : check(false), mode(MUST), constOnly(false), minValid(1024) {}
117  } nullDeref;
119  std::string exprParserDoc;
123  : searchMode(SEARCH_SINGLE_DFS), maxVertexVisit((size_t)-1), maxPathLength(200), maxCallDepth((size_t)-1),
124  maxRecursionDepth((size_t)-1), nonAddressIsFeasible(true), solverName("best"),
125  memoryParadigm(LIST_BASED_MEMORY), processFinalVertex(false), ignoreSemanticFailure(false),
126  kCycleCoefficient(0.0), edgeVisitOrder(VISIT_NATURAL), trackingCodeCoverage(true), maxExprSize(UNLIMITED),
127  traceSemantics(false) {}
128  };
131  struct Statistics {
132  size_t nPathsExplored;
139  Statistics()
140  : nPathsExplored(0), maxVertexVisitHits(0), maxPathLengthHits(0), maxCallDepthHits(0), maxRecursionDepthHits(0) {}
142  Statistics& operator+=(const Statistics&);
143  };
158  struct VarDetail {
159  std::string registerName;
160  std::string firstAccessMode;
164  size_t memSize;
165  size_t memByteNumber;
168  VarDetail(): firstAccessInsn(NULL), memSize(0), memByteNumber(0) {}
169  std::string toString() const;
170  };
179  public:
180  enum Action {
183  };
185  virtual ~PathProcessor() {}
203  virtual Action found(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path,
205  const SmtSolverPtr &solver) {
206  return CONTINUE;
207  }
242  virtual Action nullDeref(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn,
243  const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver,
245  return CONTINUE;
246  }
287  virtual Action memoryIo(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn,
288  const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver,
291  return CONTINUE;
292  }
293  };
299  rose_addr_t address = 0;
301  std::string name;
304  FunctionSummary();
307  FunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgFuncVertex, uint64_t stackDelta);
308  };
317  public:
320  protected:
321  FunctionSummarizer() {}
322  public:
324  virtual void init(const FeasiblePath &analysis, FunctionSummary &summary /*in,out*/,
325  const Partitioner2::Function::Ptr &function,
326  Partitioner2::ControlFlowGraph::ConstVertexIterator cfgCallTarget) = 0;
332  virtual bool process(const FeasiblePath &analysis, const FunctionSummary &summary,
340  returnValue(const FeasiblePath &analysis, const FunctionSummary &summary,
342  };
345  // Private data members
347 private:
348  const Partitioner2::Partitioner *partitioner_ = nullptr; // binary analysis context
349  RegisterDictionaryPtr registers_; // registers augmented with "path" pseudo-register
350  RegisterDescriptor REG_RETURN_; // FIXME[Robb P Matzke 2016-10-11]: see source
351  Settings settings_;
352  FunctionSummaries functionSummaries_;
353  Partitioner2::CfgVertexMap vmap_; // relates CFG vertices to path vertices
354  Partitioner2::ControlFlowGraph paths_; // all possible paths, feasible or otherwise
355  Partitioner2::CfgConstVertexSet pathsBeginVertices_;// vertices of paths_ where searching starts
356  Partitioner2::CfgConstVertexSet pathsEndVertices_; // vertices of paths_ where searching stops
357  bool isDirectedSearch_ = true; // use pathsEndVertices_?
358  Partitioner2::CfgConstEdgeSet cfgAvoidEdges_; // CFG edges to avoid
359  Partitioner2::CfgConstVertexSet cfgEndAvoidVertices_;// CFG end-of-path and other avoidance vertices
360  FunctionSummarizer::Ptr functionSummarizer_; // user-defined function for handling function summaries
361  InstructionSemantics::BaseSemantics::StatePtr initialState_; // set by setInitialState.
362  static Sawyer::Attribute::Id POST_STATE; // stores semantic state after executing the insns for a vertex
363  static Sawyer::Attribute::Id POST_INSN_LENGTH; // path length in instructions at end of vertex
364  static Sawyer::Attribute::Id EFFECTIVE_K; // (double) effective maximimum path length
366  mutable SAWYER_THREAD_TRAITS::Mutex statsMutex_; // protects the following data member
367  Statistics stats_; // statistical results of the analysis
370  // Construction, destruction
372 public:
374  FeasiblePath();
375  virtual ~FeasiblePath();
378  void reset();
384  SAWYER_THREAD_TRAITS::LockGuard lock(statsMutex_);
385  stats_ = Statistics();
386  }
389  static void initDiagnostics();
393  // Settings affecting behavior
395 public:
399  const Settings& settings() const { return settings_; }
400  Settings& settings() { return settings_; }
401  void settings(const Settings &s) { settings_ = s; }
411  static std::string expressionDocumentation();
415  // Overridable processing functions
417 public:
424  buildVirtualCpu(const Partitioner2::Partitioner&, const Partitioner2::CfgPath*, PathProcessor*, const SmtSolver::Ptr&);
432  virtual void
434  const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsBeginVertex);
440  virtual void
442  const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex);
447  virtual void
448  processIndeterminateBlock(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex,
450  size_t pathInsnIndex);
455  virtual void
456  processFunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex,
458  size_t pathInsnIndex);
463  virtual void
465  const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex,
466  size_t pathInsnIndex);
469  virtual bool
470  shouldSummarizeCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex,
472  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget);
475  virtual bool
476  shouldInline(const Partitioner2::CfgPath &path, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget);
486  FunctionSummarizer::Ptr functionSummarizer() const { return functionSummarizer_; }
487  void functionSummarizer(const FunctionSummarizer::Ptr &f) { functionSummarizer_ = f; }
490  // Utilities
493 public:
495  Partitioner2::ControlFlowGraph::ConstVertexIterator
496  pathToCfg(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex) const;
512  bool isFunctionCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator&) const;
515  void printPathVertex(std::ostream &out, const Partitioner2::ControlFlowGraph::Vertex &pathVertex,
516  size_t &insnIdx /*in,out*/) const;
521  void printPath(std::ostream &out, const Partitioner2::CfgPath&) const;
528  const Partitioner2::ControlFlowGraph::ConstVertexIterator &beginVertex,
529  const Partitioner2::CfgConstVertexSet &endVertices);
532  // Functions for describing the search space
534 public:
544  void
546  const Partitioner2::CfgConstVertexSet &cfgBeginVertices,
547  const Partitioner2::CfgConstVertexSet &cfgEndVertices,
550  void
551  setSearchBoundary(const Partitioner2::Partitioner &partitioner,
552  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgBeginVertex,
553  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgEndVertex,
556  void
557  setSearchBoundary(const Partitioner2::Partitioner &partitioner,
558  const Partitioner2::CfgConstVertexSet &cfgBeginVertices,
561  void
562  setSearchBoundary(const Partitioner2::Partitioner &partitioner,
563  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgBeginVertex,
573  bool isDirectedSearch() const {
574  return isDirectedSearch_;
575  }
578  // Functions for searching for paths
580 public:
585  void depthFirstSearch(PathProcessor &pathProcessor);
589  // Functions for getting the results
591 public:
596  const Partitioner2::Partitioner& partitioner() const;
601  const FunctionSummaries& functionSummaries() const {
602  return functionSummaries_;
603  }
609  const FunctionSummary& functionSummary(rose_addr_t entryVa) const;
612  const VarDetail& varDetail(const InstructionSemantics::BaseSemantics::StatePtr&, const std::string &varName) const;
615  const VarDetails& varDetails(const InstructionSemantics::BaseSemantics::StatePtr&) const;
628  double pathEffectiveK(const Partitioner2::CfgPath&) const;
636  static size_t pathLength(const Partitioner2::CfgPath&, int position = -1);
644  SAWYER_THREAD_TRAITS::LockGuard lock(statsMutex_);
645  return stats_;
646  }
649  // Private supporting functions
651 private:
652  // Check that analysis settings are valid, or throw an exception.
653  void checkSettings() const;
655  static rose_addr_t virtualAddress(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex);
657  void insertCallSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsCallSite,
659  const Partitioner2::ControlFlowGraph::ConstEdgeIterator &cfgCallEdge);
661  boost::filesystem::path emitPathGraph(size_t callId, size_t graphId); // emit paths graph to "rose-debug" directory
663  // Pop an edge (or more) from the path and follow some other edge. Also, adjust the SMT solver's stack in a similar
664  // way. The SMT solver will have an initial state, plus one pushed state per edge of the path.
665  void backtrack(Partitioner2::CfgPath &path /*in,out*/, const SmtSolver::Ptr&);
667  // Process one edge of a path to find any path constraints. When called, the cpu's current state should be the virtual
668  // machine state at it exists just prior to executing the target vertex of the specified edge.
669  //
670  // Returns a null pointer if the edge's assertion is trivially unsatisfiable, such as when the edge points to a basic block
671  // whose address doesn't match the contents of the instruction pointer register after executing the edge's source
672  // block. Otherwise, returns a symbolic expression which must be tree if the edge is feasible. For trivially feasible
673  // edges, the return value is the constant 1 (one bit wide; i.e., true).
674  SymbolicExpression::Ptr pathEdgeConstraint(const Partitioner2::ControlFlowGraph::ConstEdgeIterator &pathEdge,
677  // Parse the expression if it's a parsable string, otherwise return the expression as is. */
678  Expression parseExpression(Expression, const std::string &where, SymbolicExpressionParser&) const;
680  SymbolicExpression::Ptr expandExpression(const Expression&, const SymbolicExpressionParser&);
682  // Based on the last vertex of the path, insert user-specified assertions into the SMT solver.
683  void insertAssertions(const SmtSolver::Ptr&, const Partitioner2::CfgPath&,
684  const std::vector<Expression> &assertions, bool atEndOfPath, const SymbolicExpressionParser&);
686  // Size of vertex. How much of "k" does this vertex consume?
687  static size_t vertexSize(const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
689  // Information needed for adding user-supplied assertions to the solver.
690  struct Substitutions {
691  SymbolicExpressionParser exprParser;
692  std::vector<Expression> assertions;
695  };
697  // Insert the edge assertion and any applicable user assertions (after delayed expansion of the expressions' register
698  // and memory references), and run the solver, returning its result.
700  solvePathConstraints(const SmtSolver::Ptr&, const Partitioner2::CfgPath&, const SymbolicExpression::Ptr &edgeAssertion,
701  const Substitutions&, bool atEndOfPath);
703  // Mark vertex as being reached
704  void markAsReached(const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
706  // Top-level info for debugging
707  void dfsDebugHeader(Sawyer::Message::Stream &trace, Sawyer::Message::Stream &debug, size_t callId, size_t graphId);
709  // Top-level info for debugging a path.
710  void dfsDebugCurrentPath(Sawyer::Message::Stream&, const Partitioner2::CfgPath&, const SmtSolverPtr&, size_t effectiveK);
712  // Prepare substitutions for registers and memory based on user-supplied symbolic expressions.
713  Substitutions parseSubstitutions();
715  // Substitute registers and memory values into user-supplied symbolic expressions.
716  void makeSubstitutions(const Substitutions&, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&);
718  // Create an SMT solver. It will have an initial state plus, eventually, a transaction for each path edge.
719  SmtSolverPtr createSmtSolver();
721  // The parts of the instruction semantics framework
722  struct Semantics {
726  };
728  // Create the parts of the instruction semantics framework.
729  Semantics createSemantics(const Partitioner2::CfgPath&, PathProcessor&, const SmtSolverPtr&);
731  // Convert a position to an index. Negative positions measure from the end of the sequence so that -1 refers to the last
732  // element, -2 to the second-to-last element, etc. Non-negative positions are the same thing as an index. Returns nothing
733  // if the position is out of range.
734  static Sawyer::Optional<size_t> positionToIndex(int position, size_t nElmts);
736  // Obtain the incoming state for the specified path vertex. This is a pointer to the state, so copy it if you make changes.
737  // The incoming state for the first vertex is the specified initial state.
739  incomingState(const Partitioner2::CfgPath&, int position, const InstructionSemantics::BaseSemantics::StatePtr &initialState);
741  // Number of steps (e.g., instructions) up to but not including the specified path vertex.
742  size_t incomingStepCount(const Partitioner2::CfgPath&, int position);
744  // Number of steps (e.g., instructions) up to and including the specified path vertex.
745  size_t outgoingStepCount(const Partitioner2::CfgPath&, int position);
747  // Evaluate semantics up to and including the specified path vertex, returning the outgoing state for that vertex. If
748  // semantics fails, then returns a null state pointer.
749  InstructionSemantics::BaseSemantics::StatePtr evaluate(Partitioner2::CfgPath&, int position, const Semantics&);
751  // Check whether the last vertex of the path is feasible. Returns true if provably feasible, false if provably infeasible,
752  // or indeterminate if not provable one way or the other.
753  boost::logic::tribool isFeasible(Partitioner2::CfgPath&, const Substitutions&, const Semantics&, const SmtSolverPtr&);
755  // Safely call the path processor's "found" action for the path's final vertex and return its value.
756  PathProcessor::Action callPathProcessorFound(PathProcessor&, Partitioner2::CfgPath&, const Semantics&, const SmtSolverPtr&);
758  // Given an effective K value, adjust it based on how often the last vertex of the path has been visited. Returns a new
759  // effective K. As a special case, the new K is zero if the last vertex has been visited too often.
760  double adjustEffectiveK(Partitioner2::CfgPath&, double oldK);
762  // Given a path that ends with a function call, inline the function or a summary of the function, adjusting the paths_
763  // control flow graph.
764  void summarizeOrInline(Partitioner2::CfgPath&, const Semantics&);
765 };
767 } // namespace
768 } // namespace
770 std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::FeasiblePath::Expression&);
772 // Convert string to feasible path expression during command-line parsing
773 namespace Sawyer {
774  namespace CommandLine {
775  template<>
776  struct LexicalCast<Rose::BinaryAnalysis::FeasiblePath::Expression> {
777  static Rose::BinaryAnalysis::FeasiblePath::Expression convert(const std::string &src) {
779  }
780  };
781  }
782 }
784 #endif
785 #endif
SmtSolverPtr Ptr
Reference counting pointer for SMT solvers.
Definition: SmtSolver.h:45
std::string firstAccessMode
How was variable first accessed ("read" or "write").
Definition: FeasiblePath.h:160
bool traceSemantics
Trace all instruction semantics operations.
Definition: FeasiblePath.h:106
size_t maxPathLengthHits
Number of times settings.maxPathLength was hit (effective K).
Definition: FeasiblePath.h:134
std::vector< rose_addr_t > summarizeFunctions
Functions to always summarize.
Definition: FeasiblePath.h:94
Sawyer::Container::Map< rose_addr_t, FunctionSummary > FunctionSummaries
Summaries for multiple functions.
Definition: FeasiblePath.h:311
MayOrMust mode
Check for addrs that may or must be null.
Definition: FeasiblePath.h:111
EdgeVisitOrder edgeVisitOrder
Order in which to visit edges.
Definition: FeasiblePath.h:101
virtual void processBasicBlock(const Partitioner2::BasicBlock::Ptr &bblock, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process instructions for one basic block on the specified virtual CPU.
size_t maxCallDepthHits
Number of times settings.maxCallDepth was hit.
Definition: FeasiblePath.h:135
size_t nPathsExplored
Number of paths explored.
Definition: FeasiblePath.h:132
rose_addr_t address
Address of summarized function.
Definition: FeasiblePath.h:299
SemanticMemoryParadigm memoryParadigm
Type of memory state when there's a choice to be made.
Definition: FeasiblePath.h:97
virtual void setInitialState(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsBeginVertex)
Initialize state for first vertex of path.
bool trackingCodeCoverage
If set, track which block addresses are reached.
Definition: FeasiblePath.h:102
static size_t pathLength(const Partitioner2::CfgPath &, int position=-1)
Total length of path up to and including the specified vertex.
InstructionSemantics::BaseSemantics::StatePtr initialState() const
Get the initial state before the first path vertex.
double pathEffectiveK(const Partitioner2::CfgPath &) const
Effective maximum path length.
void printPathVertex(std::ostream &out, const Partitioner2::ControlFlowGraph::Vertex &pathVertex, size_t &insnIdx) const
Print one vertex of a path for debugging.
std::string parsable
String to be parsed as an expression.
Definition: FeasiblePath.h:73
Information stored per V_USER_DEFINED path vertex.
Definition: FeasiblePath.h:298
Sawyer::Container::Map< std::string, FeasiblePath::VarDetail > VarDetails
Variable detail by name.
Definition: FeasiblePath.h:173
Types of comparisons.
Definition: FeasiblePath.h:60
SymbolicExpression::Ptr expr
Symbolic expression.
Definition: FeasiblePath.h:74
void setSearchBoundary(const Partitioner2::Partitioner &partitioner, const Partitioner2::CfgConstVertexSet &cfgBeginVertices, const Partitioner2::CfgConstVertexSet &cfgEndVertices, const Partitioner2::CfgConstVertexSet &cfgAvoidVertices=Partitioner2::CfgConstVertexSet(), const Partitioner2::CfgConstEdgeSet &cfgAvoidEdges=Partitioner2::CfgConstEdgeSet())
Specify search boundary.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
void depthFirstSearch(PathProcessor &pathProcessor)
Find all feasible paths.
Base class for machine instructions.
Sawyer::Optional< rose_addr_t > returnFrom
This variable is the return value from the specified function.
Definition: FeasiblePath.h:166
Collection of streams.
Definition: Message.h:1606
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to symbolic RISC operations.
Constructs a new feasible path analyzer.
How to search for paths.
Definition: FeasiblePath.h:37
static InstructionSemantics::BaseSemantics::StatePtr pathPostState(const Partitioner2::CfgPath &, size_t vertexIdx)
Get the state at the end of the specified vertex.
virtual void processVertex(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex, size_t pathInsnIndex)
Process one vertex.
const VarDetails & varDetails(const InstructionSemantics::BaseSemantics::StatePtr &) const
Details about all variables by name.
RegisterDescriptor REG_PATH
Descriptor of path pseudo-registers.
Definition: FeasiblePath.h:155
virtual Action nullDeref(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver, IoMode ioMode, const InstructionSemantics::BaseSemantics::SValuePtr &addr)
Function invoked whenever a null pointer dereference is detected.
Definition: FeasiblePath.h:242
size_t maxRecursionDepthHits
Number of times settings.maxRecursionDepth was hit.
Definition: FeasiblePath.h:136
std::string name
Name of summarized function.
Definition: FeasiblePath.h:301
Sawyer::Optional< size_t > firstAccessIdx
Instruction position in path where this var was first read.
Definition: FeasiblePath.h:162
A collection of related switch declarations.
Sawyer::Container::Map< rose_addr_t, size_t > reachedBlockVas
Number of times each basic block was reached.
Definition: FeasiblePath.h:137
Sawyer::Optional< boost::chrono::duration< double > > smtTimeout
Max seconds allowed per SMT solve call.
Definition: FeasiblePath.h:104
SymbolicExpression::Ptr memAddress
Address where variable is located.
Definition: FeasiblePath.h:163
Main namespace for the ROSE library.
const size_t UNLIMITED(static_cast< size_t >(-1))
Effictively unlimited size.
Satisfiability constants.
Definition: SmtSolver.h:87
size_t maxCallDepth
Max length of path in terms of function calls.
Definition: FeasiblePath.h:90
size_t maxExprSize
Maximum symbolic expression size before replacement.
Definition: FeasiblePath.h:105
struct Rose::BinaryAnalysis::FeasiblePath::Settings::NullDeref nullDeref
Settings for null-dereference analysis.
Blast everything at once to the SMT solver.
Definition: FeasiblePath.h:40
virtual void processFunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process a function summary vertex.
Feasible path analysis.
Definition: FeasiblePath.h:23
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
Name space for the entire library.
Definition: FeasiblePath.h:773
std::vector< std::string > assertionLocations
Locations at which "constraints" are checked.
Definition: FeasiblePath.h:93
size_t maxVertexVisitHits
Number of times settings.maxVertexVisit was hit.
Definition: FeasiblePath.h:133
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
static const int64_t INVALID_STACK_DELTA
Represents an invalid stack delta.
const FunctionSummaries & functionSummaries() const
Function summary information.
Definition: FeasiblePath.h:601
Partitioner2::CfgConstVertexSet cfgToPaths(const Partitioner2::CfgConstVertexSet &) const
Convert CFG vertices to path vertices.
virtual bool shouldInline(const Partitioner2::CfgPath &path, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget)
Determines whether a function call should be inlined.
std::vector< rose_addr_t > ipRewrite
An even number of from,to pairs for rewriting the insn ptr reg.
Definition: FeasiblePath.h:103
static std::string expressionDocumentation()
Documentation for the symbolic expression parser.
void settings(const Settings &s)
Property: Settings used by this analysis.
Definition: FeasiblePath.h:401
size_t maxPathLength
Limit path length in terms of number of instructions.
Definition: FeasiblePath.h:89
bool constOnly
If true, check only constants or sets of constants.
Definition: FeasiblePath.h:112
Base class for callbacks for function summaries.
Definition: FeasiblePath.h:316
AddressIntervalSet location
Location where constraint applies.
Definition: FeasiblePath.h:72
virtual Action found(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, const SmtSolverPtr &solver)
Function invoked whenever a complete path is found.
Definition: FeasiblePath.h:203
Visit edges in reverse of the natural order.
Definition: FeasiblePath.h:52
bool isDirectedSearch() const
Property: Whether search is directed or not.
Definition: FeasiblePath.h:573
virtual Action memoryIo(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver, IoMode ioMode, const InstructionSemantics::BaseSemantics::SValuePtr &addr, const InstructionSemantics::BaseSemantics::SValuePtr &value)
Function invoked every time a memory reference occurs.
Definition: FeasiblePath.h:287
Construct empty function summary.
bool nonAddressIsFeasible
Indeterminate/undiscovered vertices are feasible?
Definition: FeasiblePath.h:95
size_t maxVertexVisit
Max times to visit a particular vertex in one path.
Definition: FeasiblePath.h:88
Describes (part of) a physical CPU register.
size_t maxRecursionDepth
Max path length in terms of recursive function calls.
Definition: FeasiblePath.h:91
void reset()
Reset to initial state without changing settings.
A path through a control flow graph.
Definition: CfgPath.h:17
virtual void processIndeterminateBlock(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process an indeterminate block.
rose_addr_t minValid
Minnimum address that is not treated as a null dereference.
Definition: FeasiblePath.h:113
Information about a variable seen on a path.
Definition: FeasiblePath.h:158
FunctionSummarizer::Ptr functionSummarizer() const
Property: Function summary handling.
Definition: FeasiblePath.h:486
Exception for errors specific to feasible path analysis.
Definition: FeasiblePath.h:29
virtual bool shouldSummarizeCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex, const Partitioner2::ControlFlowGraph &cfg, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget)
Determines whether a function call should be summarized instead of inlined.
bool isFunctionCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &) const
True if vertex is a function call.
virtual InstructionSemantics::BaseSemantics::DispatcherPtr buildVirtualCpu(const Partitioner2::Partitioner &, const Partitioner2::CfgPath *, PathProcessor *, const SmtSolver::Ptr &)
Create the virtual CPU.
bool ignoreSemanticFailure
Whether to ignore instructions with no semantic info.
Definition: FeasiblePath.h:99
const VarDetail & varDetail(const InstructionSemantics::BaseSemantics::StatePtr &, const std::string &varName) const
Details about a variable.
SearchMode searchMode
Method to use when searching for feasible paths.
Definition: FeasiblePath.h:86
size_t Id
Attribute identification.
Definition: Attribute.h:140
Binary analysis.
bool pathEndsWithFunctionCall(const Partitioner2::CfgPath &) const
True if path ends with a function call.
Read or write operation.
Definition: FeasiblePath.h:57
void printPath(std::ostream &out, const Partitioner2::CfgPath &) const
Print the path to the specified output stream.
Statistics statistics() const
Cumulative statistics about prior analyses.
Definition: FeasiblePath.h:643
void resetStatistics()
Reset only statistics.
Definition: FeasiblePath.h:383
std::set< rose_addr_t > AddressSet
Set of basic block addresses.
Definition: FeasiblePath.h:63
Parses symbolic expressions from text.
const Settings & settings() const
Property: Settings used by this analysis.
Definition: FeasiblePath.h:399
size_t memByteNumber
Byte number for memory access.
Definition: FeasiblePath.h:165
int64_t stackDelta
Stack delta for summarized function.
Definition: FeasiblePath.h:300
Base class for reference counted objects.
Definition: SharedObject.h:64
double kCycleCoefficient
Coefficient for adjusting maxPathLengh during CFG cycles.
Definition: FeasiblePath.h:100
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &settings)
Describe command-line switches.
Sawyer::SharedPointer< FunctionSummarizer > Ptr
Reference counting pointer.
Definition: FeasiblePath.h:319
static Sawyer::Message::Facility mlog
Diagnostic output.
Definition: FeasiblePath.h:146
virtual bool process(const FeasiblePath &analysis, const FunctionSummary &summary, const InstructionSemantics::SymbolicSemantics::RiscOperatorsPtr &ops)=0
Invoked when the analysis traverses the summary.
bool isAnyEndpointReachable(const Partitioner2::ControlFlowGraph &cfg, const Partitioner2::ControlFlowGraph::ConstVertexIterator &beginVertex, const Partitioner2::CfgConstVertexSet &endVertices)
Determine whether any ending vertex is reachable.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
Partitioner2::ControlFlowGraph::ConstVertexIterator pathToCfg(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex) const
Convert path vertex to a CFG vertex.
Visit edges in their natural, forward order.
Definition: FeasiblePath.h:51
virtual InstructionSemantics::SymbolicSemantics::SValuePtr returnValue(const FeasiblePath &analysis, const FunctionSummary &summary, const InstructionSemantics::SymbolicSemantics::RiscOperatorsPtr &ops)=0
Return value for function.
const FunctionSummary & functionSummary(rose_addr_t entryVa) const
Function summary information.
const Partitioner2::Partitioner & partitioner() const
Property: Partitioner currently in use.
Converts text to messages.
Definition: Message.h:1396
Statistics from path searching.
Definition: FeasiblePath.h:131
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:294
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
std::string solverName
Type of SMT solver.
Definition: FeasiblePath.h:96
Edge visitation order.
Definition: FeasiblePath.h:50
void functionSummarizer(const FunctionSummarizer::Ptr &f)
Property: Function summary handling.
Definition: FeasiblePath.h:487
Settings & settings()
Property: Settings used by this analysis.
Definition: FeasiblePath.h:400
size_t memSize
Size of total memory access in bytes.
Definition: FeasiblePath.h:164
std::string exprParserDoc
String documenting how expressions are parsed, empty for default.
Definition: FeasiblePath.h:119
bool processFinalVertex
Whether to process the last vertex of the path.
Definition: FeasiblePath.h:98
SgAsmInstruction * firstAccessInsn
Instruction address where this var was first read.
Definition: FeasiblePath.h:161
Settings that control this analysis.
Definition: FeasiblePath.h:84
static void initDiagnostics()
Initialize diagnostic output.
bool check
If true, look for null dereferences along the paths.
Definition: FeasiblePath.h:110
Sawyer::Optional< rose_addr_t > initialStackPtr
Concrete value to use for stack pointer register initial value.
Definition: FeasiblePath.h:87
Organization of semantic memory.
Definition: FeasiblePath.h:44
std::vector< Expression > assertions
Constraints to be satisfied at some point along the path.
Definition: FeasiblePath.h:92
virtual void init(const FeasiblePath &analysis, FunctionSummary &summary, const Partitioner2::Function::Ptr &function, Partitioner2::ControlFlowGraph::ConstVertexIterator cfgCallTarget)=0
Invoked when a new summary is created.