1 #ifndef ROSE_BinaryAnalysis_FeasiblePath_H
2 #define ROSE_BinaryAnalysis_FeasiblePath_H
3 #include <featureTests.h>
6 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics.h>
7 #include <Rose/BinaryAnalysis/SmtSolver.h>
8 #include <Rose/BinaryAnalysis/SymbolicExprParser.h>
9 #include <Rose/BinaryAnalysis/Partitioner2/CfgPath.h>
10 #include <Rose/Exception.h>
11 #include <Sawyer/CommandLine.h>
12 #include <Sawyer/Message.h>
13 #include <boost/filesystem/path.hpp>
14 #include <boost/logic/tribool.hpp>
16 namespace Rose {
17 namespace BinaryAnalysis {
22 class FeasiblePath {
24  // Types and public data members
26 public:
28  class Exception: public Rose::Exception {
29  public:
30  Exception(const std::string &what)
31  : Rose::Exception(what) {}
32  ~Exception() throw () {}
33  };
36  enum SearchMode {
40  };
46  };
53  };
56  enum IoMode { READ, WRITE };
59  enum MayOrMust { MAY, MUST };
62  typedef std::set<rose_addr_t> AddressSet;
70  struct Expression {
72  std::string parsable;
75  Expression() {}
76  /*implicit*/ Expression(const std::string &parsable): parsable(parsable) {}
77  /*implicit*/ Expression(const SymbolicExpr::Ptr &expr): expr(expr) {}
79  void print(std::ostream&) const;
80  };
83  struct Settings {
84  // Path feasibility
87  size_t maxVertexVisit;
88  size_t maxPathLength;
89  size_t maxCallDepth;
91  std::vector<Expression> assertions;
92  std::vector<std::string> assertionLocations;
93  std::vector<rose_addr_t> summarizeFunctions;
95  std::string solverName;
102  std::vector<rose_addr_t> ipRewrite;
104  size_t maxExprSize;
107  // Null dereferences
108  struct NullDeref {
109  bool check;
111  bool constOnly;
112  rose_addr_t minValid;
114  NullDeref()
115  : check(false), mode(MUST), constOnly(false), minValid(1024) {}
116  } nullDeref;
118  std::string exprParserDoc;
122  : searchMode(SEARCH_SINGLE_DFS), maxVertexVisit((size_t)-1), maxPathLength(200), maxCallDepth((size_t)-1),
123  maxRecursionDepth((size_t)-1), nonAddressIsFeasible(true), solverName("best"),
124  memoryParadigm(LIST_BASED_MEMORY), processFinalVertex(false), ignoreSemanticFailure(false),
125  kCycleCoefficient(0.0), edgeVisitOrder(VISIT_NATURAL), trackingCodeCoverage(true), maxExprSize(UNLIMITED),
126  traceSemantics(false) {}
127  };
130  struct Statistics {
131  size_t nPathsExplored;
138  Statistics()
139  : nPathsExplored(0), maxVertexVisitHits(0), maxPathLengthHits(0), maxCallDepthHits(0), maxRecursionDepthHits(0) {}
141  Statistics& operator+=(const Statistics&);
142  };
157  struct VarDetail {
158  std::string registerName;
159  std::string firstAccessMode;
163  size_t memSize;
164  size_t memByteNumber;
167  VarDetail(): firstAccessInsn(NULL), memSize(0), memByteNumber(0) {}
168  std::string toString() const;
169  };
178  public:
179  enum Action {
182  };
184  virtual ~PathProcessor() {}
202  virtual Action found(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path,
204  const SmtSolverPtr &solver) {
205  return CONTINUE;
206  }
241  virtual Action nullDeref(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn,
244  return CONTINUE;
245  }
286  virtual Action memoryIo(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn,
290  return CONTINUE;
291  }
292  };
298  rose_addr_t address = 0;
300  std::string name;
303  FunctionSummary();
306  FunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgFuncVertex, uint64_t stackDelta);
307  };
316  public:
319  protected:
320  FunctionSummarizer() {}
321  public:
323  virtual void init(const FeasiblePath &analysis, FunctionSummary &summary /*in,out*/,
324  const Partitioner2::Function::Ptr &function,
325  Partitioner2::ControlFlowGraph::ConstVertexIterator cfgCallTarget) = 0;
331  virtual bool process(const FeasiblePath &analysis, const FunctionSummary &summary,
339  returnValue(const FeasiblePath &analysis, const FunctionSummary &summary,
341  };
344  // Private data members
346 private:
347  const Partitioner2::Partitioner *partitioner_ = nullptr; // binary analysis context
348  RegisterDictionary *registers_ = nullptr; // registers augmented with "path" pseudo-register
349  RegisterDescriptor REG_RETURN_; // FIXME[Robb P Matzke 2016-10-11]: see source
350  Settings settings_;
351  FunctionSummaries functionSummaries_;
352  Partitioner2::CfgVertexMap vmap_; // relates CFG vertices to path vertices
353  Partitioner2::ControlFlowGraph paths_; // all possible paths, feasible or otherwise
354  Partitioner2::CfgConstVertexSet pathsBeginVertices_;// vertices of paths_ where searching starts
355  Partitioner2::CfgConstVertexSet pathsEndVertices_; // vertices of paths_ where searching stops
356  bool isDirectedSearch_ = true; // use pathsEndVertices_?
357  Partitioner2::CfgConstEdgeSet cfgAvoidEdges_; // CFG edges to avoid
358  Partitioner2::CfgConstVertexSet cfgEndAvoidVertices_;// CFG end-of-path and other avoidance vertices
359  FunctionSummarizer::Ptr functionSummarizer_; // user-defined function for handling function summaries
360  InstructionSemantics2::BaseSemantics::StatePtr initialState_; // set by setInitialState.
361  static Sawyer::Attribute::Id POST_STATE; // stores semantic state after executing the insns for a vertex
362  static Sawyer::Attribute::Id POST_INSN_LENGTH; // path length in instructions at end of vertex
363  static Sawyer::Attribute::Id EFFECTIVE_K; // (double) effective maximimum path length
365  mutable SAWYER_THREAD_TRAITS::Mutex statsMutex_; // protects the following data member
366  Statistics stats_; // statistical results of the analysis
369  // Construction, destruction
371 public:
373  FeasiblePath();
374  virtual ~FeasiblePath();
377  void reset() {
378  partitioner_ = NULL;
379  registers_ = NULL;
380  REG_PATH = REG_RETURN_ = RegisterDescriptor();
381  functionSummaries_.clear();
382  vmap_.clear();
383  paths_.clear();
384  pathsBeginVertices_.clear();
385  pathsEndVertices_.clear();
386  isDirectedSearch_ = true;
387  cfgAvoidEdges_.clear();
388  cfgEndAvoidVertices_.clear();
389  resetStatistics();
390  }
396  SAWYER_THREAD_TRAITS::LockGuard lock(statsMutex_);
397  stats_ = Statistics();
398  }
401  static void initDiagnostics();
405  // Settings affecting behavior
407 public:
411  const Settings& settings() const { return settings_; }
412  Settings& settings() { return settings_; }
413  void settings(const Settings &s) { settings_ = s; }
423  static std::string expressionDocumentation();
427  // Overridable processing functions
429 public:
436  buildVirtualCpu(const Partitioner2::Partitioner&, const Partitioner2::CfgPath*, PathProcessor*, const SmtSolver::Ptr&);
444  virtual void
446  const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsBeginVertex);
452  virtual void
454  const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex);
459  virtual void
460  processIndeterminateBlock(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex,
462  size_t pathInsnIndex);
467  virtual void
468  processFunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex,
470  size_t pathInsnIndex);
475  virtual void
477  const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex,
478  size_t pathInsnIndex);
481  virtual bool
482  shouldSummarizeCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex,
484  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget);
487  virtual bool
488  shouldInline(const Partitioner2::CfgPath &path, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget);
498  FunctionSummarizer::Ptr functionSummarizer() const { return functionSummarizer_; }
499  void functionSummarizer(const FunctionSummarizer::Ptr &f) { functionSummarizer_ = f; }
502  // Utilities
505 public:
507  Partitioner2::ControlFlowGraph::ConstVertexIterator
508  pathToCfg(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex) const;
524  bool isFunctionCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator&) const;
527  void printPathVertex(std::ostream &out, const Partitioner2::ControlFlowGraph::Vertex &pathVertex,
528  size_t &insnIdx /*in,out*/) const;
533  void printPath(std::ostream &out, const Partitioner2::CfgPath&) const;
540  const Partitioner2::ControlFlowGraph::ConstVertexIterator &beginVertex,
541  const Partitioner2::CfgConstVertexSet &endVertices);
544  // Functions for describing the search space
546 public:
556  void
558  const Partitioner2::CfgConstVertexSet &cfgBeginVertices,
559  const Partitioner2::CfgConstVertexSet &cfgEndVertices,
562  void
563  setSearchBoundary(const Partitioner2::Partitioner &partitioner,
564  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgBeginVertex,
565  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgEndVertex,
568  void
569  setSearchBoundary(const Partitioner2::Partitioner &partitioner,
570  const Partitioner2::CfgConstVertexSet &cfgBeginVertices,
573  void
574  setSearchBoundary(const Partitioner2::Partitioner &partitioner,
575  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgBeginVertex,
585  bool isDirectedSearch() const {
586  return isDirectedSearch_;
587  }
590  // Functions for searching for paths
592 public:
597  void depthFirstSearch(PathProcessor &pathProcessor);
601  // Functions for getting the results
603 public:
608  const Partitioner2::Partitioner& partitioner() const;
613  const FunctionSummaries& functionSummaries() const {
614  return functionSummaries_;
615  }
621  const FunctionSummary& functionSummary(rose_addr_t entryVa) const;
624  const VarDetail& varDetail(const InstructionSemantics2::BaseSemantics::StatePtr&, const std::string &varName) const;
627  const VarDetails& varDetails(const InstructionSemantics2::BaseSemantics::StatePtr&) const;
640  double pathEffectiveK(const Partitioner2::CfgPath&) const;
648  static size_t pathLength(const Partitioner2::CfgPath&, int position = -1);
656  SAWYER_THREAD_TRAITS::LockGuard lock(statsMutex_);
657  return stats_;
658  }
661  // Private supporting functions
663 private:
664  // Check that analysis settings are valid, or throw an exception.
665  void checkSettings() const;
667  static rose_addr_t virtualAddress(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex);
669  void insertCallSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsCallSite,
671  const Partitioner2::ControlFlowGraph::ConstEdgeIterator &cfgCallEdge);
673  boost::filesystem::path emitPathGraph(size_t callId, size_t graphId); // emit paths graph to "rose-debug" directory
675  // Pop an edge (or more) from the path and follow some other edge. Also, adjust the SMT solver's stack in a similar
676  // way. The SMT solver will have an initial state, plus one pushed state per edge of the path.
677  void backtrack(Partitioner2::CfgPath &path /*in,out*/, const SmtSolver::Ptr&);
679  // Process one edge of a path to find any path constraints. When called, the cpu's current state should be the virtual
680  // machine state at it exists just prior to executing the target vertex of the specified edge.
681  //
682  // Returns a null pointer if the edge's assertion is trivially unsatisfiable, such as when the edge points to a basic block
683  // whose address doesn't match the contents of the instruction pointer register after executing the edge's source
684  // block. Otherwise, returns a symbolic expression which must be tree if the edge is feasible. For trivially feasible
685  // edges, the return value is the constant 1 (one bit wide; i.e., true).
686  SymbolicExpr::Ptr pathEdgeConstraint(const Partitioner2::ControlFlowGraph::ConstEdgeIterator &pathEdge,
689  // Parse the expression if it's a parsable string, otherwise return the expression as is. */
690  Expression parseExpression(Expression, const std::string &where, SymbolicExprParser&) const;
692  SymbolicExpr::Ptr expandExpression(const Expression&, const SymbolicExprParser&);
694  // Based on the last vertex of the path, insert user-specified assertions into the SMT solver.
695  void insertAssertions(const SmtSolver::Ptr&, const Partitioner2::CfgPath&,
696  const std::vector<Expression> &assertions, bool atEndOfPath, const SymbolicExprParser&);
698  // Size of vertex. How much of "k" does this vertex consume?
699  static size_t vertexSize(const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
701  // Information needed for adding user-supplied assertions to the solver.
702  struct Substitutions {
703  SymbolicExprParser exprParser;
704  std::vector<Expression> assertions;
707  };
709  // Insert the edge assertion and any applicable user assertions (after delayed expansion of the expressions' register
710  // and memory references), and run the solver, returning its result.
712  solvePathConstraints(const SmtSolver::Ptr&, const Partitioner2::CfgPath&, const SymbolicExpr::Ptr &edgeAssertion,
713  const Substitutions&, bool atEndOfPath);
715  // Mark vertex as being reached
716  void markAsReached(const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
718  // Top-level info for debugging
719  void dfsDebugHeader(Sawyer::Message::Stream &trace, Sawyer::Message::Stream &debug, size_t callId, size_t graphId);
721  // Top-level info for debugging a path.
722  void dfsDebugCurrentPath(Sawyer::Message::Stream&, const Partitioner2::CfgPath&, const SmtSolverPtr&, size_t effectiveK);
724  // Prepare substitutions for registers and memory based on user-supplied symbolic expressions.
725  Substitutions parseSubstitutions();
727  // Substitute registers and memory values into user-supplied symbolic expressions.
728  void makeSubstitutions(const Substitutions&, const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr&);
730  // Create an SMT solver. It will have an initial state plus, eventually, a transaction for each path edge.
731  SmtSolverPtr createSmtSolver();
733  // The parts of the instruction semantics framework
734  struct Semantics {
738  };
740  // Create the parts of the instruction semantics framework.
741  Semantics createSemantics(const Partitioner2::CfgPath&, PathProcessor&, const SmtSolverPtr&);
743  // Convert a position to an index. Negative positions measure from the end of the sequence so that -1 refers to the last
744  // element, -2 to the second-to-last element, etc. Non-negative positions are the same thing as an index. Returns nothing
745  // if the position is out of range.
746  static Sawyer::Optional<size_t> positionToIndex(int position, size_t nElmts);
748  // Obtain the incoming state for the specified path vertex. This is a pointer to the state, so copy it if you make changes.
749  // The incoming state for the first vertex is the specified initial state.
751  incomingState(const Partitioner2::CfgPath&, int position, const InstructionSemantics2::BaseSemantics::StatePtr &initialState);
753  // Number of steps (e.g., instructions) up to but not including the specified path vertex.
754  size_t incomingStepCount(const Partitioner2::CfgPath&, int position);
756  // Number of steps (e.g., instructions) up to and including the specified path vertex.
757  size_t outgoingStepCount(const Partitioner2::CfgPath&, int position);
759  // Evaluate semantics up to and including the specified path vertex, returning the outgoing state for that vertex. If
760  // semantics fails, then returns a null state pointer.
761  InstructionSemantics2::BaseSemantics::StatePtr evaluate(Partitioner2::CfgPath&, int position, const Semantics&);
763  // Check whether the last vertex of the path is feasible. Returns true if provably feasible, false if provably infeasible,
764  // or indeterminate if not provable one way or the other.
765  boost::logic::tribool isFeasible(Partitioner2::CfgPath&, const Substitutions&, const Semantics&, const SmtSolverPtr&);
767  // Safely call the path processor's "found" action for the path's final vertex and return its value.
768  PathProcessor::Action callPathProcessorFound(PathProcessor&, Partitioner2::CfgPath&, const Semantics&, const SmtSolverPtr&);
770  // Given an effective K value, adjust it based on how often the last vertex of the path has been visited. Returns a new
771  // effective K. As a special case, the new K is zero if the last vertex has been visited too often.
772  double adjustEffectiveK(Partitioner2::CfgPath&, double oldK);
774  // Given a path that ends with a function call, inline the function or a summary of the function, adjusting the paths_
775  // control flow graph.
776  void summarizeOrInline(Partitioner2::CfgPath&, const Semantics&);
777 };
779 } // namespace
780 } // namespace
782 std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::FeasiblePath::Expression&);
784 // Convert string to feasible path expression during command-line parsing
785 namespace Sawyer {
786  namespace CommandLine {
787  template<>
788  struct LexicalCast<Rose::BinaryAnalysis::FeasiblePath::Expression> {
789  static Rose::BinaryAnalysis::FeasiblePath::Expression convert(const std::string &src) {
791  }
792  };
793  }
794 }
796 #endif
797 #endif
SmtSolverPtr Ptr
Reference counting pointer for SMT solvers.
Definition: SmtSolver.h:48
std::string firstAccessMode
How was variable first accessed ("read" or "write").
Definition: FeasiblePath.h:159
bool traceSemantics
Trace all instruction semantics operations.
Definition: FeasiblePath.h:105
size_t maxPathLengthHits
Number of times settings.maxPathLength was hit (effective K).
Definition: FeasiblePath.h:133
std::vector< rose_addr_t > summarizeFunctions
Functions to always summarize.
Definition: FeasiblePath.h:93
Sawyer::Container::Map< rose_addr_t, FunctionSummary > FunctionSummaries
Summaries for multiple functions.
Definition: FeasiblePath.h:310
MayOrMust mode
Check for addrs that may or must be null.
Definition: FeasiblePath.h:110
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
InstructionSemantics2::BaseSemantics::StatePtr initialState() const
Get the initial state before the first path vertex.
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:166
EdgeVisitOrder edgeVisitOrder
Order in which to visit edges.
Definition: FeasiblePath.h:100
virtual InstructionSemantics2::SymbolicSemantics::SValuePtr returnValue(const FeasiblePath &analysis, const FunctionSummary &summary, const InstructionSemantics2::SymbolicSemantics::RiscOperatorsPtr &ops)=0
Return value for function.
size_t maxCallDepthHits
Number of times settings.maxCallDepth was hit.
Definition: FeasiblePath.h:134
size_t nPathsExplored
Number of paths explored.
Definition: FeasiblePath.h:131
rose_addr_t address
Address of summarized function.
Definition: FeasiblePath.h:298
SemanticMemoryParadigm memoryParadigm
Type of memory state when there's a choice to be made.
Definition: FeasiblePath.h:96
bool trackingCodeCoverage
If set, track which block addresses are reached.
Definition: FeasiblePath.h:101
static size_t pathLength(const Partitioner2::CfgPath &, int position=-1)
Total length of path up to and including the specified vertex.
const size_t UNLIMITED(-1)
Effictively unlimited size.
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:72
Information stored per V_USER_DEFINED path vertex.
Definition: FeasiblePath.h:297
Sawyer::Container::Map< std::string, FeasiblePath::VarDetail > VarDetails
Variable detail by name.
Definition: FeasiblePath.h:172
Types of comparisons.
Definition: FeasiblePath.h:59
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.
void depthFirstSearch(PathProcessor &pathProcessor)
Find all feasible paths.
virtual void processIndeterminateBlock(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex, const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process an indeterminate block.
Base class for machine instructions.
Sawyer::Optional< rose_addr_t > returnFrom
This variable is the return value from the specified function.
Definition: FeasiblePath.h:165
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:36
virtual bool process(const FeasiblePath &analysis, const FunctionSummary &summary, const InstructionSemantics2::SymbolicSemantics::RiscOperatorsPtr &ops)=0
Invoked when the analysis traverses the summary.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
virtual void processFunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex, const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process a function summary vertex.
RegisterDescriptor REG_PATH
Descriptor of path pseudo-registers.
Definition: FeasiblePath.h:154
size_t maxRecursionDepthHits
Number of times settings.maxRecursionDepth was hit.
Definition: FeasiblePath.h:135
std::string name
Name of summarized function.
Definition: FeasiblePath.h:300
Sawyer::Optional< size_t > firstAccessIdx
Instruction position in path where this var was first read.
Definition: FeasiblePath.h:161
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:136
Sawyer::Optional< boost::chrono::duration< double > > smtTimeout
Max seconds allowed per SMT solve call.
Definition: FeasiblePath.h:103
Main namespace for the ROSE library.
Parses symbolic expressions from text.
Satisfiability constants.
Definition: SmtSolver.h:90
size_t maxCallDepth
Max length of path in terms of function calls.
Definition: FeasiblePath.h:89
size_t maxExprSize
Maximum symbolic expression size before replacement.
Definition: FeasiblePath.h:104
struct Rose::BinaryAnalysis::FeasiblePath::Settings::NullDeref nullDeref
Settings for null-dereference analysis.
Blast everything at once to the SMT solver.
Definition: FeasiblePath.h:39
Feasible path analysis.
Definition: FeasiblePath.h:22
Name space for the entire library.
Definition: FeasiblePath.h:785
std::vector< std::string > assertionLocations
Locations at which "constraints" are checked.
Definition: FeasiblePath.h:92
size_t maxVertexVisitHits
Number of times settings.maxVertexVisit was hit.
Definition: FeasiblePath.h:132
static const int64_t INVALID_STACK_DELTA
Represents an invalid stack delta.
const FunctionSummaries & functionSummaries() const
Function summary information.
Definition: FeasiblePath.h:613
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:102
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
static std::string expressionDocumentation()
Documentation for the symbolic expression parser.
void settings(const Settings &s)
Property: Settings used by this analysis.
Definition: FeasiblePath.h:413
size_t maxPathLength
Limit path length in terms of number of instructions.
Definition: FeasiblePath.h:88
bool constOnly
If true, check only constants or sets of constants.
Definition: FeasiblePath.h:111
Base class for callbacks for function summaries.
Definition: FeasiblePath.h:315
AddressIntervalSet location
Location where constraint applies.
Definition: FeasiblePath.h:71
void clear()
Remove all entries from this container.
Visit edges in reverse of the natural order.
Definition: FeasiblePath.h:51
bool isDirectedSearch() const
Property: Whether search is directed or not.
Definition: FeasiblePath.h:585
static InstructionSemantics2::BaseSemantics::StatePtr pathPostState(const Partitioner2::CfgPath &, size_t vertexIdx)
Get the state at the end of the specified vertex.
Construct empty function summary.
bool nonAddressIsFeasible
Indeterminate/undiscovered vertices are feasible?
Definition: FeasiblePath.h:94
size_t maxVertexVisit
Max times to visit a particular vertex in one path.
Definition: FeasiblePath.h:87
Describes (part of) a physical CPU register.
size_t maxRecursionDepth
Max path length in terms of recursive function calls.
Definition: FeasiblePath.h:90
void reset()
Reset to initial state without changing settings.
Definition: FeasiblePath.h:377
A path through a control flow graph.
Definition: CfgPath.h:17
rose_addr_t minValid
Minnimum address that is not treated as a null dereference.
Definition: FeasiblePath.h:112
Information about a variable seen on a path.
Definition: FeasiblePath.h:157
virtual Action found(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, const SmtSolverPtr &solver)
Function invoked whenever a complete path is found.
Definition: FeasiblePath.h:202
FunctionSummarizer::Ptr functionSummarizer() const
Property: Function summary handling.
Definition: FeasiblePath.h:498
Exception for errors specific to feasible path analysis.
Definition: FeasiblePath.h:28
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.
SymbolicExpr::Ptr expr
Symbolic expression.
Definition: FeasiblePath.h:73
bool ignoreSemanticFailure
Whether to ignore instructions with no semantic info.
Definition: FeasiblePath.h:98
SearchMode searchMode
Method to use when searching for feasible paths.
Definition: FeasiblePath.h:85
size_t Id
Attribute identification.
Definition: Attribute.h:140
void clear()
Remove all vertices and edges.
Definition: Graph.h:1978
bool pathEndsWithFunctionCall(const Partitioner2::CfgPath &) const
True if path ends with a function call.
Read or write operation.
Definition: FeasiblePath.h:56
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:655
void resetStatistics()
Reset only statistics.
Definition: FeasiblePath.h:395
std::set< rose_addr_t > AddressSet
Set of basic block addresses.
Definition: FeasiblePath.h:62
virtual InstructionSemantics2::BaseSemantics::DispatcherPtr buildVirtualCpu(const Partitioner2::Partitioner &, const Partitioner2::CfgPath *, PathProcessor *, const SmtSolver::Ptr &)
Create the virtual CPU.
const Settings & settings() const
Property: Settings used by this analysis.
Definition: FeasiblePath.h:411
size_t memByteNumber
Byte number for memory access.
Definition: FeasiblePath.h:164
virtual Action memoryIo(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn, const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver, IoMode ioMode, const InstructionSemantics2::BaseSemantics::SValuePtr &addr, const InstructionSemantics2::BaseSemantics::SValuePtr &value)
Function invoked every time a memory reference occurs.
Definition: FeasiblePath.h:286
int64_t stackDelta
Stack delta for summarized function.
Definition: FeasiblePath.h:299
Base class for reference counted objects.
Definition: SharedObject.h:64
double kCycleCoefficient
Coefficient for adjusting maxPathLengh during CFG cycles.
Definition: FeasiblePath.h:99
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &settings)
Describe command-line switches.
Sawyer::SharedPointer< FunctionSummarizer > Ptr
Reference counting pointer.
Definition: FeasiblePath.h:318
static Sawyer::Message::Facility mlog
Diagnostic output.
Definition: FeasiblePath.h:145
bool isAnyEndpointReachable(const Partitioner2::ControlFlowGraph &cfg, const Partitioner2::ControlFlowGraph::ConstVertexIterator &beginVertex, const Partitioner2::CfgConstVertexSet &endVertices)
Determine whether any ending vertex is reachable.
const VarDetails & varDetails(const InstructionSemantics2::BaseSemantics::StatePtr &) const
Details about all variables by name.
void clear()
Remove all edges or vertices from this set.
Partitioner2::ControlFlowGraph::ConstVertexIterator pathToCfg(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex) const
Convert path vertex to a CFG vertex.
virtual void processVertex(const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex, size_t pathInsnIndex)
Process one vertex.
Visit edges in their natural, forward order.
Definition: FeasiblePath.h:50
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
Defines registers available for a particular architecture.
Definition: Registers.h:37
const VarDetail & varDetail(const InstructionSemantics2::BaseSemantics::StatePtr &, const std::string &varName) const
Details about a variable.
virtual void processBasicBlock(const Partitioner2::BasicBlock::Ptr &bblock, const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process instructions for one basic block on the specified virtual CPU.
virtual Action nullDeref(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn, const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver, IoMode ioMode, const InstructionSemantics2::BaseSemantics::SValuePtr &addr)
Function invoked whenever a null pointer dereference is detected.
Definition: FeasiblePath.h:241
Statistics from path searching.
Definition: FeasiblePath.h:130
SymbolicExpr::Ptr memAddress
Address where variable is located.
Definition: FeasiblePath.h:162
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:289
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
std::string solverName
Type of SMT solver.
Definition: FeasiblePath.h:95
Edge visitation order.
Definition: FeasiblePath.h:49
void functionSummarizer(const FunctionSummarizer::Ptr &f)
Property: Function summary handling.
Definition: FeasiblePath.h:499
Settings & settings()
Property: Settings used by this analysis.
Definition: FeasiblePath.h:412
size_t memSize
Size of total memory access in bytes.
Definition: FeasiblePath.h:163
std::string exprParserDoc
String documenting how expressions are parsed, empty for default.
Definition: FeasiblePath.h:118
bool processFinalVertex
Whether to process the last vertex of the path.
Definition: FeasiblePath.h:97
SgAsmInstruction * firstAccessInsn
Instruction address where this var was first read.
Definition: FeasiblePath.h:160
Settings that control this analysis.
Definition: FeasiblePath.h:83
static void initDiagnostics()
Initialize diagnostic output.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
Definition: SmtSolver.h:26
bool check
If true, look for null dereferences along the paths.
Definition: FeasiblePath.h:109
virtual void setInitialState(const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsBeginVertex)
Initialize state for first vertex of path.
Sawyer::Optional< rose_addr_t > initialStackPtr
Concrete value to use for stack pointer register initial value.
Definition: FeasiblePath.h:86
Organization of semantic memory.
Definition: FeasiblePath.h:43
std::vector< Expression > assertions
Constraints to be satisfied at some point along the path.
Definition: FeasiblePath.h:91
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.