More fixes in jump table analysis:
[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     GraphPtr BuildAnalysisGraph(std::set<ParseAPI::Edge*> &visitedEdges);
23     bool IsJumpTable(GraphPtr slice, BoundFactsCalculator &bfc, BoundValue &target);
24     bool FillInOutEdges(BoundValue &target, std::vector<std::pair< Address, Dyninst::ParseAPI::EdgeTypeEnum > >& outEdges);
25
26     bool MatchReadAST(Assignment::Ptr a);
27
28     std::unordered_map<Assignment::Ptr, AST::Ptr, Assignment::AssignmentPtrHasher> expandCache;
29     std::pair<AST::Ptr, bool> ExpandAssignment(Assignment::Ptr);
30
31 public:
32     virtual bool endAtPoint(AssignmentPtr ap);  
33     virtual bool addNodeCallback(AssignmentPtr ap, std::set<ParseAPI::Edge*> &visitedEdges);
34
35     JumpTablePred(ParseAPI::Function *f,
36                   ParseAPI::Block *b,
37                   ReachFact &r,
38                   ThunkData &t,
39                   std::vector<std::pair< Address, Dyninst::ParseAPI::EdgeTypeEnum > >& out):
40             func(f), block(b), rf(r), thunks(t), outEdges(out) {}
41 };
42
43
44 class TypedSliceEdge: public Dyninst::Edge {
45     ParseAPI::EdgeTypeEnum type_; 
46     
47     TypedSliceEdge(const SliceNode::Ptr source,
48               const SliceNode::Ptr target,
49               ParseAPI::EdgeTypeEnum t) 
50               : Dyninst::Edge(source, target), type_(t) {};
51   public:             
52    typedef boost::shared_ptr<TypedSliceEdge> Ptr; 
53    static TypedSliceEdge::Ptr create(SliceNode::Ptr source,
54                                      SliceNode::Ptr target,
55                                      ParseAPI::EdgeTypeEnum t) {
56         return Ptr(new TypedSliceEdge(source, target, t));       
57    }                                                
58
59   public:
60     ParseAPI::EdgeTypeEnum type() { return type_;}
61
62 };
63
64 #endif