/
memoryAccess.hpp
226 lines (159 loc) · 7.01 KB
/
memoryAccess.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//! \file
/*
** Copyright (C) - Triton
**
** This program is under the terms of the BSD License.
*/
#ifndef TRITON_MEMORYACCESS
#define TRITON_MEMORYACCESS
#include "ast.hpp"
#include "bitsVector.hpp"
#include "cpuSize.hpp"
#include "immediate.hpp"
#include "operandInterface.hpp"
#include "register.hpp"
#include "tritonTypes.hpp"
//! The Triton namespace
namespace triton {
/*!
* \addtogroup triton
* @{
*/
//! The Triton namespace
namespace arch {
/*!
* \ingroup triton
* \addtogroup arch
* @{
*/
/*! \class MemoryAccess
* \brief This class is used to represent a memory access.
*/
class MemoryAccess : public BitsVector, public OperandInterface {
protected:
//! The memory' address.
triton::uint64 address;
//! The concrete value (content of the access)
triton::uint512 concreteValue;
//! True if this memory contains a concrete value.
bool concreteValueDefined;
//! Contains the pc relative if it exists.
triton::uint64 pcRelative;
//! LEA - If the operand has a segment register, this attribute is filled.
triton::arch::Register segmentReg;
//! LEA - If the operand has a base register, this attribute is filled.
triton::arch::Register baseReg;
//! LEA - If the operand has an index register, this attribute is filled.
triton::arch::Register indexReg;
//! LEA - If the operand has a displacement, this attribute is filled.
triton::arch::Immediate displacement;
//! LEA - If the operand has a scale, this attribute is filled.
triton::arch::Immediate scale;
//! The AST of the memory access.
triton::ast::AbstractNode* ast;
//! Copy a MemoryAccess.
void copy(const MemoryAccess& other);
private:
//! LEA - Returns the segment register value.
triton::uint64 getSegmentValue(void);
//! LEA - Returns the scale immediate value.
triton::uint64 getScaleValue(void);
//! LEA - Returns the displacement immediate value.
triton::uint64 getDisplacementValue(void);
//! LEA - Returns the mask of the memory access based on the CPU architecture.
triton::uint64 getAccessMask(void);
//! LEA - Returns the size of the memory access.
triton::uint32 getAccessSize(void);
public:
//! Constructor.
MemoryAccess();
//! Constructor.
MemoryAccess(triton::uint64 address, triton::uint32 size /* bytes */);
//! Constructor.
MemoryAccess(triton::uint64 address, triton::uint32 size /* bytes */, triton::uint512 concreteValue);
//! Constructor by copy.
MemoryAccess(const MemoryAccess& other);
//! Destructor.
virtual ~MemoryAccess();
//! Initialize the address of the memory.
void initAddress(bool force=false);
//! Returns the AST of the memory access (LEA).
triton::ast::AbstractNode* getLeaAst(void) const;
//! Returns the address of the memory.
triton::uint64 getAddress(void) const;
//! Returns the highest bit of the memory vector. \sa BitsVector::getHigh()
triton::uint32 getAbstractHigh(void) const;
//! Returns the lower bit of the memory vector. \sa BitsVector::getLow()
triton::uint32 getAbstractLow(void) const;
//! Returns the size (in bits) of the memory vector.
triton::uint32 getBitSize(void) const;
//! Returnts the concrete value (content of the access)
triton::uint512 getConcreteValue(void) const;
//! LEA - Gets pc relative.
triton::uint64 getPcRelative(void) const;
//! Returns the size (in bytes) of the memory vector.
triton::uint32 getSize(void) const;
//! Returns the type of the operand (triton::arch::OP_MEM).
triton::uint32 getType(void) const;
//! LEA - Returns the segment register operand.
triton::arch::Register& getSegmentRegister(void);
//! LEA - Returns the base register operand.
triton::arch::Register& getBaseRegister(void);
//! LEA - Returns the index register operand.
triton::arch::Register& getIndexRegister(void);
//! LEA - Returns the displacement operand.
triton::arch::Immediate& getDisplacement(void);
//! LEA - Returns the scale operand.
triton::arch::Immediate& getScale(void);
//! LEA - Returns the segment register operand.
const triton::arch::Register& getConstSegmentRegister(void) const;
//! LEA - Returns the base register operand.
const triton::arch::Register& getConstBaseRegister(void) const;
//! LEA - Returns the index register operand.
const triton::arch::Register& getConstIndexRegister(void) const;
//! LEA - Returns the displacement operand.
const triton::arch::Immediate& getConstDisplacement(void) const;
//! LEA - Returns the scale operand.
const triton::arch::Immediate& getConstScale(void) const;
//! True if the memory is not empty.
bool isValid(void) const;
//! Returns true if `other` and `self` overlap.
bool isOverlapWith(const MemoryAccess& other) const;
//! Returns true if the memory contains a concrete value.
bool hasConcreteValue(void) const;
//! Sets the address of the memory access.
void setAddress(triton::uint64 addr);
//! Sets the concrete value of the memory access.
void setConcreteValue(triton::uint512 concreteValue);
//! LEA - Sets pc relative.
void setPcRelative(triton::uint64 addr);
//! LEA - Sets the segment register operand.
void setSegmentRegister(triton::arch::Register& segment);
//! LEA - Sets the base register operand.
void setBaseRegister(triton::arch::Register& base);
//! LEA - Sets the index register operand.
void setIndexRegister(triton::arch::Register& index);
//! LEA - Sets the displacement operand.
void setDisplacement(triton::arch::Immediate& displacement);
//! LEA - Sets the scale operand.
void setScale(triton::arch::Immediate& scale);
//! Copies a MemoryAccess.
void operator=(const MemoryAccess& other);
};
//! Displays an MemoryAccess.
std::ostream& operator<<(std::ostream& stream, const MemoryAccess& mem);
//! Displays an MemoryAccess.
std::ostream& operator<<(std::ostream& stream, const MemoryAccess* mem);
//! Compares two MemoryAccess.
bool operator==(const MemoryAccess& mem1, const MemoryAccess& mem2);
//! Compares two MemoryAccess.
bool operator!=(const MemoryAccess& mem1, const MemoryAccess& mem2);
//! Compares two MemoryAccess (needed for std::map)
bool operator<(const MemoryAccess& mem1, const MemoryAccess& mem2);
//! Defines the force memory initialization constant.
const bool FORCE_MEMORY_INITIALIZATION = true;
/*! @} End of arch namespace */
};
/*! @} End of triton namespace */
};
#endif /* TRITON_MEMORYACCESS */