ROSE  0.10.0.0
Thunk.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Thunk_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Thunk_H
3 
4 #include <rosePublicConfig.h>
5 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
6 
7 #include <Partitioner2/BasicTypes.h>
8 #include <Sawyer/SharedObject.h>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 namespace Partitioner2 {
13 
15 // Individual thunk predicates
17 
23  size_t nInsns;
24  std::string name;
28  : nInsns(0) {}
29 
31  ThunkDetection(size_t nInsns, const std::string &name)
32  : nInsns(nInsns), name(name) {}
33 
34  // C++03 safe bool conversion since we don't have explicit operator bool.
35 private:
36  typedef void(ThunkDetection::*unspecified_bool)() const;
37  void this_type_does_not_support_comparisons() const {}
38 public:
39  operator unspecified_bool() const {
40  return nInsns ? &ThunkDetection::this_type_does_not_support_comparisons : 0;
41  }
42 };
43 
47 ThunkDetection isX86JmpImmThunk(const Partitioner&, const std::vector<SgAsmInstruction*>&);
48 
52 ThunkDetection isX86JmpMemThunk(const Partitioner&, const std::vector<SgAsmInstruction*>&);
53 
57 ThunkDetection isX86LeaJmpThunk(const Partitioner&, const std::vector<SgAsmInstruction*>&);
58 
62 ThunkDetection isX86MovJmpThunk(const Partitioner&, const std::vector<SgAsmInstruction*>&);
63 
67 ThunkDetection isX86AddJmpThunk(const Partitioner&, const std::vector<SgAsmInstruction*>&);
68 
69 
71 // Collective thunk predicates
73 
80 typedef ThunkDetection(*ThunkPredicate)(const Partitioner&, const std::vector<SgAsmInstruction*>&);
81 
84 public:
86 
87 private:
89  std::vector<ThunkPredicate> predicates_;
90 
91 protected:
92  // use 'instance' instead
93  ThunkPredicates() {}
94 
95 public:
97  static Ptr instance() {
98  return Ptr(new ThunkPredicates);
99  }
100 
104  static Ptr allThunks();
105 
110  static Ptr functionMatcherThunks();
111 
115  const std::vector<ThunkPredicate>& predicates() const { return predicates_; }
116  std::vector<ThunkPredicate>& predicates() { return predicates_; }
125  ThunkDetection isThunk(const Partitioner&, const std::vector<SgAsmInstruction*>&) const;
126 };
127 
129 // Thunk utilities
131 
135 void splitThunkFunctions(Partitioner&, const ThunkPredicates::Ptr&);
136 
137 } // namespace
138 } // namespace
139 } // namespace
140 
141 #endif
142 #endif
std::string name
Name of the pattern that matched the instructions.
Definition: Thunk.h:24
ThunkDetection(size_t nInsns, const std::string &name)
Constructor for a detected thunk.
Definition: Thunk.h:31
ThunkDetection isX86JmpMemThunk(const Partitioner &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instruction begin with "jmp [ADDRESS]".
ThunkDetection()
Constructor for detecting no thunk.
Definition: Thunk.h:27
Main namespace for the ROSE library.
ThunkDetection(* ThunkPredicate)(const Partitioner &, const std::vector< SgAsmInstruction * > &)
Function signature for finding thunks.
Definition: Thunk.h:80
std::vector< ThunkPredicate > & predicates()
Property: The list of predicates that will test for thunks.
Definition: Thunk.h:116
ThunkDetection isX86MovJmpThunk(const Partitioner &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with "mov R, [ADDR]; jmp R".
const std::vector< ThunkPredicate > & predicates() const
Property: The list of predicates that will test for thunks.
Definition: Thunk.h:115
static Ptr functionMatcherThunks()
Construct collective predicate for matching thunks to create functions.
Return type for thunk detectors.
Definition: Thunk.h:22
ThunkDetection isThunk(const Partitioner &, const std::vector< SgAsmInstruction * > &) const
Test whether instructions begin with a thunk.
static Ptr instance()
Allocating constructor.
Definition: Thunk.h:97
ThunkDetection isX86LeaJmpThunk(const Partitioner &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with an LEA JMP pair.
Base class for reference counted objects.
Definition: SharedObject.h:64
static Ptr allThunks()
Construct collective predicate with all built-in predicates.
void splitThunkFunctions(Partitioner &, const ThunkPredicates::Ptr &)
Split thunks off from start of functions.
ThunkDetection isX86AddJmpThunk(const Partitioner &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with "add R, C; jmp ADDR".
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:321
ThunkDetection isX86JmpImmThunk(const Partitioner &, const std::vector< SgAsmInstruction * > &)
Test whether x86 instructions begin with "jmp ADDRESS".
size_t nInsns
Number of instructions that are part of the thunk.
Definition: Thunk.h:23