ROSE  0.11.145.0
Thunk.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Thunk_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Thunk_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <Sawyer/SharedObject.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 namespace Partitioner2 {
12 
14 // Individual thunk predicates
16 
22  size_t nInsns;
23  std::string name;
27  : nInsns(0) {}
28 
30  ThunkDetection(size_t nInsns, const std::string &name)
31  : nInsns(nInsns), name(name) {}
32 
33  // C++03 safe bool conversion since we don't have explicit operator bool.
34 private:
35  typedef void(ThunkDetection::*unspecified_bool)() const;
36  void this_type_does_not_support_comparisons() const {}
37 public:
38  operator unspecified_bool() const {
39  return nInsns ? &ThunkDetection::this_type_does_not_support_comparisons : 0;
40  }
41 };
42 
46 ThunkDetection isX86JmpImmThunk(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&);
47 
51 ThunkDetection isX86JmpMemThunk(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&);
52 
56 ThunkDetection isX86LeaJmpThunk(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&);
57 
61 ThunkDetection isX86MovJmpThunk(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&);
62 
66 ThunkDetection isX86AddJmpThunk(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&);
67 
68 
70 // Collective thunk predicates
72 
79 typedef ThunkDetection(*ThunkPredicate)(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&);
80 
83 public:
85 
86 private:
88  std::vector<ThunkPredicate> predicates_;
89 
90 protected:
91  // use 'instance' instead
92  ThunkPredicates() {}
93 
94 public:
96  static Ptr instance() {
97  return Ptr(new ThunkPredicates);
98  }
99 
103  static Ptr allThunks();
104 
109  static Ptr functionMatcherThunks();
110 
114  const std::vector<ThunkPredicate>& predicates() const { return predicates_; }
115  std::vector<ThunkPredicate>& predicates() { return predicates_; }
124  ThunkDetection isThunk(const PartitionerConstPtr&, const std::vector<SgAsmInstruction*>&) const;
125 };
126 
128 // Thunk utilities
130 
134 void splitThunkFunctions(const PartitionerPtr&, const ThunkPredicates::Ptr&);
135 
136 } // namespace
137 } // namespace
138 } // namespace
139 
140 #endif
141 #endif
ThunkDetection isX86MovJmpThunk(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with "mov R, [ADDR]; jmp R".
void splitThunkFunctions(const PartitionerPtr &, const ThunkPredicates::Ptr &)
Split thunks off from start of functions.
std::string name
Name of the pattern that matched the instructions.
Definition: Thunk.h:23
ThunkDetection(* ThunkPredicate)(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &)
Function signature for finding thunks.
Definition: Thunk.h:79
ThunkDetection(size_t nInsns, const std::string &name)
Constructor for a detected thunk.
Definition: Thunk.h:30
ThunkDetection()
Constructor for detecting no thunk.
Definition: Thunk.h:26
Main namespace for the ROSE library.
ThunkDetection isThunk(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &) const
Test whether instructions begin with a thunk.
std::vector< ThunkPredicate > & predicates()
Property: The list of predicates that will test for thunks.
Definition: Thunk.h:115
Sawyer::SharedPointer< Partitioner > PartitionerPtr
Shared-ownership pointer for Partitioner.
const std::vector< ThunkPredicate > & predicates() const
Property: The list of predicates that will test for thunks.
Definition: Thunk.h:114
ThunkDetection isX86JmpMemThunk(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instruction begin with "jmp [ADDRESS]".
static Ptr functionMatcherThunks()
Construct collective predicate for matching thunks to create functions.
Sawyer::SharedPointer< const Partitioner > PartitionerConstPtr
Shared-ownership pointer for Partitioner.
Return type for thunk detectors.
Definition: Thunk.h:21
ThunkDetection isX86JmpImmThunk(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with "jmp ADDRESS".
static Ptr instance()
Allocating constructor.
Definition: Thunk.h:96
ThunkDetection isX86AddJmpThunk(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with "add R, C; jmp ADDR".
Base class for reference counted objects.
Definition: SharedObject.h:64
static Ptr allThunks()
Construct collective predicate with all built-in predicates.
ThunkDetection isX86LeaJmpThunk(const PartitionerConstPtr &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with an LEA JMP pair.
size_t nInsns
Number of instructions that are part of the thunk.
Definition: Thunk.h:22