1#ifndef ROSE_BinaryAnalysis_TaintedFlow_H
2#define ROSE_BinaryAnalysis_TaintedFlow_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/DataFlow.h>
7#include <Rose/Diagnostics.h>
9#include <boost/shared_ptr.hpp>
13namespace BinaryAnalysis {
50 typedef std::list<VariableTaint> VarTaintList;
55 typedef boost::shared_ptr<State>
Ptr;
61 taints_.push_back(std::make_pair(
variable, taint));
103 const VarTaintList&
variables()
const {
return taints_; }
128 : index_(index), approximation_(approx), smtSolver_(solver), mlog(mlog) {}
132 return (*
this)(cfgVertex, in);
137 std::string toString(
const StatePtr &in);
147 ASSERT_not_null(src);
152 return dst->merge(src);
165 bool vlistInitialized_;
166 std::vector<StatePtr> results_;
177 : approximation_(UNDER_APPROXIMATE), dataFlow_(userDispatcher), vlistInitialized_(false) {}
213 using namespace Diagnostics;
215 ASSERT_require(cfgStartVertex < cfg.nVertices());
216 Stream mesg(mlog[WHERE] <<
"computeFlowGraphs starting at CFG vertex " <<cfgStartVertex);
220 vlistInitialized_ =
true;
224 mlog[DEBUG] <<
" found variable: " <<
variable <<
"\n";
237 return vertexFlowGraphs_;
240 using namespace Diagnostics;
242 vertexFlowGraphs_ = graphMap;
244 vlistInitialized_ =
true;
246 mlog[WHERE] <<
"vertexFlowGraphs set by user with " <<
StringUtility::plural(variableList_.size(),
"variables") <<
"\n";
256 ASSERT_require2(vlistInitialized_,
"TaintedFlow::computeFlowGraphs must be called before TaintedFlow::variables");
257 return variableList_;
266 ASSERT_require2(vlistInitialized_,
"TaintedFlow::computeFlowGraphs must be called before TaintedFlow::stateInstance");
275 using namespace Diagnostics;
277 ASSERT_require(cfgStartVertex < cfg.nVertices());
278 ASSERT_not_null(initialState);
279 Stream mesg(mlog[WHERE] <<
"runToFixedPoint starting at CFG vertex " <<cfgStartVertex);
284 dfEngine.
name(
"tainted-flow");
296 ASSERT_require(cfgVertexId < results_.size());
297 return results_[cfgVertexId];
301std::ostream& operator<<(std::ostream &out,
const TaintedFlow::State &state);
void runToFixedPoint()
Run data-flow until it reaches a fixed point.
const VertexStates & getFinalStates() const
All outgoing states.
const std::string & name() const
Property: Name for debugging.
Various tools for data-flow analysis.
std::list< Variable > VariableList
List of variables.
VariableList getUniqueVariables(const VertexFlowGraphs &)
Get list of unique variables.
VertexFlowGraphs buildGraphPerVertex(const CFG &cfg, size_t startVertex, VertexUnpacker vertexUnpacker)
Compute data-flow per CFG vertex.
Taintedness & lookup(const DataFlow::Variable &)
Find the taintedness for some variable.
static State::Ptr instance(const DataFlow::VariableList &variables, Taintedness taint=BOTTOM)
Allocating constructor.
bool merge(const State::Ptr &)
Merge other state into this state.
void print(std::ostream &) const
Print this state.
virtual State::Ptr copy() const
Virtual copy constructor.
VarTaintList & variables()
List of all variables and their taintedness.
bool setIfExists(const DataFlow::Variable &, Taintedness)
Set taintedness if the variable exists.
boost::shared_ptr< State > Ptr
Shared-ownership pointer to taint states.
const VarTaintList & variables() const
List of all variables and their taintedness.
Various tools for performing tainted flow analysis.
static void initDiagnostics()
Initialize diagnostics.
void vertexFlowGraphs(const DataFlow::VertexFlowGraphs &graphMap)
Property: data flow graphs.
SmtSolverPtr smtSolver() const
Property: SMT solver.
Approximation
Mode of operation.
TaintedFlow(const InstructionSemantics::BaseSemantics::DispatcherPtr &userDispatcher)
Constructs a tainted flow analysis.
void runToFixedPoint(const CFG &cfg, size_t cfgStartVertex, const StatePtr &initialState)
Run data flow.
const DataFlow::VertexFlowGraphs & vertexFlowGraphs() const
Property: data flow graphs.
Approximation approximation() const
Property: approximation.
static Taintedness merge(Taintedness, Taintedness)
Merges two taint values.
std::pair< DataFlow::Variable, Taintedness > VariableTaint
Variable-Taintedness pair.
StatePtr getFinalState(size_t cfgVertexId) const
Query results.
void smtSolver(const SmtSolverPtr &solver)
Property: SMT solver.
const DataFlow::VariableList & variables() const
List of variables.
State::Ptr StatePtr
Reference counting pointer to State.
void approximation(Approximation a)
Property: approximation.
StatePtr stateInstance(Taintedness taint) const
Creates a new state.
void computeFlowGraphs(const CFG &cfg, size_t cfgStartVertex)
Compute data flow graphs.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
std::string plural(T n, const std::string &plural_phrase, const std::string &singular_phrase="")
Helpful way to print singular or plural words.