One byte read can produce bound [0,255], but it is possible that an one byte read...
[dyninst.git] / parseAPI / src / JumpTablePred.h
1 #ifndef JUMP_TABLE_PRED_H
2 #define JUMP_TABLE_PRED_H
3
4 #include "CFG.h"
5 #include "slicing.h"
6 #include "Edge.h"
7 #include "ThunkData.h"
8 #include "Graph.h"
9 #include "BoundFactCalculator.h"
10 using namespace Dyninst;
11
12 class JumpTablePred : public Slicer::Predicates {
13  
14     std::set<Assignment::Ptr> currentAssigns;
15     ParseAPI::Function *func;
16     ParseAPI::Block *block;
17     ReachFact &rf;
18     ThunkData &thunks;
19     std::vector<std::pair< Address, Dyninst::ParseAPI::EdgeTypeEnum > >& outEdges;
20     std::vector<AST::Ptr> readAST;
21
22         bool MatchReadAST(Assignment::Ptr a);
23
24         std::pair<AST::Ptr, bool> ExpandAssignment(Assignment::Ptr);
25
26 public:
27 std::unordered_map<Assignment::Ptr, AST::Ptr, Assignment::AssignmentPtrHasher> expandCache;
28
29     virtual bool endAtPoint(AssignmentPtr ap);  
30     virtual bool addNodeCallback(AssignmentPtr ap, std::set<ParseAPI::Edge*> &visitedEdges);
31 GraphPtr BuildAnalysisGraph(std::set<ParseAPI::Edge*> &visitedEdges);
32     bool IsJumpTable(GraphPtr slice, BoundFactsCalculator &bfc, BoundValue &target);
33     bool FillInOutEdges(BoundValue &target, std::vector<std::pair< Address, Dyninst::ParseAPI::EdgeTypeEnum > >& outEdges);
34
35
36     JumpTablePred(ParseAPI::Function *f,
37                   ParseAPI::Block *b,
38                   ReachFact &r,
39                   ThunkData &t,
40                   std::vector<std::pair< Address, Dyninst::ParseAPI::EdgeTypeEnum > >& out):
41             func(f), block(b), rf(r), thunks(t), outEdges(out) {}
42 };
43
44
45 class TypedSliceEdge: public Dyninst::Edge {
46     ParseAPI::EdgeTypeEnum type_; 
47     
48     TypedSliceEdge(const SliceNode::Ptr source,
49               const SliceNode::Ptr target,
50               ParseAPI::EdgeTypeEnum t) 
51               : Dyninst::Edge(source, target), type_(t) {};
52   public:             
53    typedef boost::shared_ptr<TypedSliceEdge> Ptr; 
54    static TypedSliceEdge::Ptr create(SliceNode::Ptr source,
55                                      SliceNode::Ptr target,
56                                      ParseAPI::EdgeTypeEnum t) {
57         return Ptr(new TypedSliceEdge(source, target, t));       
58    }                                                
59
60   public:
61     ParseAPI::EdgeTypeEnum type() { return type_;}
62
63 };
64
65 #endif