ROSE  0.11.145.0
ModulesX86.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_ModulesX86_H
2 #define ROSE_BinaryAnalysis_Partitioner2_ModulesX86_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
6 
7 #include <Rose/BinaryAnalysis/Partitioner2/Modules.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 namespace Partitioner2 {
12 
14 namespace ModulesX86 {
15 
28 protected:
29  FunctionPtr function_;
30 protected:
32 public:
34 
35 public:
36  static Ptr instance();
37  virtual std::vector<FunctionPtr> functions() const override;
38  virtual bool match(const PartitionerConstPtr&, rose_addr_t anchor) override;
39 };
40 
50 public:
51  static Ptr instance() { return Ptr(new MatchHotPatchPrologue); }
52  virtual std::vector<FunctionPtr> functions() const override { return std::vector<FunctionPtr>(1, function_); }
53  virtual bool match(const PartitionerConstPtr&, rose_addr_t anchor) override;
54 };
55 
58 protected:
59  FunctionPtr function_;
60 protected:
62 public:
64 
65 public:
66  static Ptr instance();
67  virtual std::vector<FunctionPtr> functions() const override;
68  virtual bool match(const PartitionerConstPtr&, rose_addr_t anchor) override;
69 };
70 
73 protected:
74  FunctionPtr function_;
75 public:
76  static Ptr instance() { return Ptr(new MatchEnterPrologue); }
77  virtual std::vector<FunctionPtr> functions() const override { return std::vector<FunctionPtr>(1, function_); }
78  virtual bool match(const PartitionerConstPtr&, rose_addr_t anchor) override;
79 };
80 
83 protected:
84  FunctionPtr function_;
85 public:
86  static Ptr instance() { return Ptr(new MatchRetPadPush); }
87  virtual std::vector<FunctionPtr> functions() const override { return std::vector<FunctionPtr>(1, function_); }
88  virtual bool match(const PartitionerConstPtr&, rose_addr_t anchor) override;
89 };
90 
98 public:
99  static Ptr instance() { return Ptr(new FunctionReturnDetector); }
100  virtual bool operator()(bool chain, const Args&) override;
101 };
102 
108 public:
109  enum EntryType { ABSOLUTE, RELATIVE };
110 
111 private:
112  Sawyer::Optional<rose_addr_t> tableVa_; // possible address for jump table
113  EntryType entryType_; // type of table entries
114  size_t entrySizeBytes_; // size of each table entry
115 
116 public:
118  : entryType_(ABSOLUTE), entrySizeBytes_(4) {}
119  static Ptr instance() { return Ptr(new SwitchSuccessors); }
120  virtual bool operator()(bool chain, const Args&) override;
121 private:
122  bool matchPattern1(SgAsmExpression *jmpArg);
123  bool matchPattern2(const BasicBlockPtr&, SgAsmInstruction *jmp);
124  bool matchPattern3(const PartitionerConstPtr&, const BasicBlockPtr&, SgAsmInstruction *jmp);
125  bool matchPatterns(const PartitionerConstPtr&, const BasicBlockPtr&);
126 };
127 
130 
135 
138 
141 
144 
147 
150 
153 
169 std::vector<rose_addr_t> scanCodeAddressTable(const PartitionerConstPtr&, AddressInterval &tableLimits /*in,out*/,
170  const AddressInterval &targetLimits,
171  SwitchSuccessors::EntryType tableEntryType, size_t tableEntrySizeBytes,
173  size_t nSkippable = 0);
174 
186 
187 
188 } // namespace
189 } // namespace
190 } // namespace
191 } // namespace
192 
193 #endif
194 #endif
bool matchLeaCxMemBpConst(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "LEA ECX, [EBP + constant]" or variant.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
bool matchMovDiDi(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "MOV EDI, EDI" or variant.
Match RET followed by PUSH with intervening no-op padding.
Definition: ModulesX86.h:82
bool matchPushBp(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "PUSH EBP" or variant.
Basic block callback to detect "switch" statements.
Definition: ModulesX86.h:107
Base class for adjusting basic blocks during discovery.
Definition: Modules.h:39
Base class for matching function prologues.
Definition: Modules.h:108
bool matchJmpMem(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "JMP [address]" or variant.
Base class for machine instructions.
Sawyer::Optional< rose_addr_t > findTableBase(SgAsmExpression *)
Try to match a base+offset expression.
virtual bool operator()(bool chain, const Args &) override
Callback method.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
bool matchPushSi(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "PUSH SI" or variant.
bool matchMovBpSp(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "MOV EBP, ESP" or variant.
Main namespace for the ROSE library.
Basic block callback to detect function returns.
Definition: ModulesX86.h:97
bool matchEnterAnyZero(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "ENTER x, 0".
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
Definition: ModulesX86.h:52
Matches an x86 MOV EDI,EDI; PUSH ESI function prologe.
Definition: ModulesX86.h:57
virtual bool operator()(bool chain, const Args &) override
Callback method.
std::vector< rose_addr_t > scanCodeAddressTable(const PartitionerConstPtr &, AddressInterval &tableLimits, const AddressInterval &targetLimits, SwitchSuccessors::EntryType tableEntryType, size_t tableEntrySizeBytes, Sawyer::Optional< rose_addr_t > probableStartVa=Sawyer::Nothing(), size_t nSkippable=0)
Reads a table of code addresses.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
Represents one Intel x86 machine instruction.
Base class for expressions.
Sawyer::Optional< rose_addr_t > matchJmpConst(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "JMP constant".
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
Definition: ModulesX86.h:77
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
Definition: ModulesX86.h:87
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
Represents no value.
Definition: Optional.h:32
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
BasicBlockCallbackPtr Ptr
Shared-ownership pointer to a BasicBlockCallback.
Definition: Modules.h:42
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
Matches an x86 function prologue with hot patch.
Definition: ModulesX86.h:49
FunctionPrologueMatcherPtr Ptr
Shared-ownership pointer to a FunctionPrologueMatcher.
Definition: Modules.h:111