ROSE 0.11.145.192
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
9namespace Rose {
10namespace BinaryAnalysis {
11namespace Partitioner2 {
12
14namespace ModulesX86 {
15
28protected:
29 FunctionPtr function_;
30protected:
32public:
34
35public:
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
50public:
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
58protected:
59 FunctionPtr function_;
60protected:
62public:
64
65public:
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
73protected:
74 FunctionPtr function_;
75public:
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
83protected:
84 FunctionPtr function_;
85public:
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
98public:
99 static Ptr instance() { return Ptr(new FunctionReturnDetector); }
100 virtual bool operator()(bool chain, const Args&) override;
101};
102
108public:
109 enum EntryType { ABSOLUTE, RELATIVE };
110
111private:
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
116public:
118 : entryType_(ABSOLUTE), entrySizeBytes_(4) {}
119 static Ptr instance() { return Ptr(new SwitchSuccessors); }
120 virtual bool operator()(bool chain, const Args&) override;
121private:
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
169std::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
Base class for adjusting basic blocks during discovery.
Definition Modules.h:39
BasicBlockCallbackPtr Ptr
Shared-ownership pointer to a BasicBlockCallback.
Definition Modules.h:42
Base class for matching function prologues.
Definition Modules.h:108
FunctionPrologueMatcherPtr Ptr
Shared-ownership pointer to a FunctionPrologueMatcher.
Definition Modules.h:111
Basic block callback to detect function returns.
Definition ModulesX86.h:97
virtual bool operator()(bool chain, const Args &) override
Callback method.
Matches an x86 MOV EDI,EDI; PUSH ESI function prologe.
Definition ModulesX86.h:57
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
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:77
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
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
Definition ModulesX86.h:52
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
Match RET followed by PUSH with intervening no-op padding.
Definition ModulesX86.h:82
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:87
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
Basic block callback to detect "switch" statements.
Definition ModulesX86.h:107
virtual bool operator()(bool chain, const Args &) override
Callback method.
Represents no value.
Definition Optional.h:36
Holds a value or nothing.
Definition Optional.h:56
Base class for expressions.
Base class for machine instructions.
Represents one Intel x86 machine instruction.
bool matchMovBpSp(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "MOV EBP, ESP" or variant.
bool matchEnterAnyZero(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "ENTER x, 0".
bool matchPushBp(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "PUSH EBP" or variant.
bool matchMovDiDi(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "MOV EDI, EDI" or variant.
Sawyer::Optional< rose_addr_t > matchJmpConst(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "JMP constant".
bool matchPushSi(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "PUSH SI" or variant.
bool matchJmpMem(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "JMP [address]" or variant.
Sawyer::Optional< rose_addr_t > findTableBase(SgAsmExpression *)
Try to match a base+offset expression.
bool matchLeaCxMemBpConst(const PartitionerConstPtr &, SgAsmX86Instruction *)
Matches "LEA ECX, [EBP + constant]" or variant.
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.
The ROSE library.