Ghidra Decompiler Analysis Engine
pcoderaw.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 #ifndef __CPUI_PCODERAW__
19 #define __CPUI_PCODERAW__
20 
21 #include "address.hh"
22 #include "opbehavior.hh"
23 
33 struct VarnodeData {
35  uintb offset;
36  uint4 size;
37  bool operator<(const VarnodeData &op2) const;
38  bool operator==(const VarnodeData &op2) const;
39  bool operator!=(const VarnodeData &op2) const;
40 
42  Address getAddr(void) const;
43 
45  void restoreXml(const Element *el,const AddrSpaceManager *manage);
46 
48  bool contains(const VarnodeData &op2) const;
49 };
50 
56 inline bool VarnodeData::operator<(const VarnodeData &op2) const {
57  if (space != op2.space) return (space->getIndex() < op2.space->getIndex());
58  if (offset != op2.offset) return (offset < op2.offset);
59  return (size > op2.size); // BIG sizes come first
60 }
61 
66 inline bool VarnodeData::operator==(const VarnodeData &op2) const {
67  if (space != op2.space) return false;
68  if (offset != op2.offset) return false;
69  return (size == op2.size);
70 }
71 
76 inline bool VarnodeData::operator!=(const VarnodeData &op2) const {
77  if (space != op2.space) return true;
78  if (offset != op2.offset) return true;
79  return (size != op2.size);
80 }
81 
85 inline Address VarnodeData::getAddr(void) const {
86  return Address(space,offset);
87 }
88 
94 class PcodeOpRaw {
95  OpBehavior *behave;
96  SeqNum seq;
97  VarnodeData *out;
98  vector<VarnodeData *> in;
99 public:
100  void setBehavior(OpBehavior *be);
101  OpBehavior *getBehavior(void) const;
102  OpCode getOpcode(void) const;
103  void setSeqNum(const Address &a,uintm b);
104  const SeqNum &getSeqNum(void) const;
105  const Address &getAddr(void) const;
106  void setOutput(VarnodeData *o);
107  VarnodeData *getOutput(void) const;
108  void addInput(VarnodeData *i);
109  void clearInputs(void);
110  int4 numInput(void) const;
111  VarnodeData *getInput(int4 i) const;
112 };
113 
118 
119 {
120  behave = be;
121 }
122 
127 
128 {
129  return behave;
130 }
131 
135 inline OpCode PcodeOpRaw::getOpcode(void) const
136 
137 {
138  return behave->getOpcode();
139 }
140 
147 inline void PcodeOpRaw::setSeqNum(const Address &a,uintm b)
148 
149 {
150  seq = SeqNum(a,b);
151 }
152 
157 inline const SeqNum &PcodeOpRaw::getSeqNum(void) const
158 
159 {
160  return seq;
161 }
162 
166 inline const Address &PcodeOpRaw::getAddr(void) const
167 
168 {
169  return seq.getAddr();
170 }
171 
175 
176 {
177  out = o;
178 }
179 
183 
184 {
185  return out;
186 }
187 
192 
193 {
194  in.push_back(i);
195 }
196 
199 inline void PcodeOpRaw::clearInputs(void)
200 
201 {
202  in.clear();
203 }
204 
206 inline int4 PcodeOpRaw::numInput(void) const
207 
208 {
209  return in.size();
210 }
211 
217 inline VarnodeData *PcodeOpRaw::getInput(int4 i) const
218 
219 {
220  return in[i];
221 }
222 
223 #endif
PcodeOpRaw::setOutput
void setOutput(VarnodeData *o)
Set the output varnode for this op.
Definition: pcoderaw.hh:174
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
PcodeOpRaw::setBehavior
void setBehavior(OpBehavior *be)
Set the opcode for this op.
Definition: pcoderaw.hh:117
PcodeOpRaw::numInput
int4 numInput(void) const
Get the number of input varnodes to this op.
Definition: pcoderaw.hh:206
VarnodeData::space
AddrSpace * space
The address space.
Definition: pcoderaw.hh:34
PcodeOpRaw::setSeqNum
void setSeqNum(const Address &a, uintm b)
Set the sequence number.
Definition: pcoderaw.hh:147
SeqNum
A class for uniquely labelling and comparing PcodeOps.
Definition: address.hh:111
VarnodeData::getAddr
Address getAddr(void) const
Get the location of the varnode as an address.
Definition: pcoderaw.hh:85
PcodeOpRaw::getOpcode
OpCode getOpcode(void) const
Get the opcode for this op.
Definition: pcoderaw.hh:135
VarnodeData::contains
bool contains(const VarnodeData &op2) const
Does this container another given VarnodeData.
Definition: pcoderaw.cc:48
PcodeOpRaw::getSeqNum
const SeqNum & getSeqNum(void) const
Retrieve the sequence number.
Definition: pcoderaw.hh:157
PcodeOpRaw::getInput
VarnodeData * getInput(int4 i) const
Get the i-th input varnode for this op.
Definition: pcoderaw.hh:217
VarnodeData::operator!=
bool operator!=(const VarnodeData &op2) const
Compare for inequality.
Definition: pcoderaw.hh:76
OpBehavior
Class encapsulating the action/behavior of specific pcode opcodes.
Definition: opbehavior.hh:42
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
opbehavior.hh
Classes for describing the behavior of individual p-code operations.
VarnodeData::operator==
bool operator==(const VarnodeData &op2) const
Compare for equality.
Definition: pcoderaw.hh:66
PcodeOpRaw::getOutput
VarnodeData * getOutput(void) const
Retrieve the output varnode for this op.
Definition: pcoderaw.hh:182
VarnodeData::operator<
bool operator<(const VarnodeData &op2) const
An ordering for VarnodeData.
Definition: pcoderaw.hh:56
VarnodeData::offset
uintb offset
The offset within the space.
Definition: pcoderaw.hh:35
VarnodeData::size
uint4 size
The number of bytes in the location.
Definition: pcoderaw.hh:36
PcodeOpRaw::getAddr
const Address & getAddr(void) const
Get address of this operation.
Definition: pcoderaw.hh:166
SeqNum::getAddr
const Address & getAddr(void) const
Get the address portion of a sequence number.
Definition: address.hh:126
PcodeOpRaw::clearInputs
void clearInputs(void)
Remove all input varnodes to this op.
Definition: pcoderaw.hh:199
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
AddrSpace::getIndex
int4 getIndex(void) const
Get the integer identifier.
Definition: space.hh:319
OpBehavior::getOpcode
OpCode getOpcode(void) const
Get the opcode for this pcode operation.
Definition: opbehavior.hh:103
OpCode
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
PcodeOpRaw::getBehavior
OpBehavior * getBehavior(void) const
Retrieve the behavior for this op.
Definition: pcoderaw.hh:126
PcodeOpRaw
A low-level representation of a single pcode operation.
Definition: pcoderaw.hh:94
address.hh
Classes for specifying addresses and other low-level constants.
VarnodeData
Data defining a specific memory location.
Definition: pcoderaw.hh:33
PcodeOpRaw::addInput
void addInput(VarnodeData *i)
Add an additional input varnode to this op.
Definition: pcoderaw.hh:191
AddrSpaceManager
A manager for different address spaces.
Definition: translate.hh:218
VarnodeData::restoreXml
void restoreXml(const Element *el, const AddrSpaceManager *manage)
Recover this object from an XML tag.
Definition: pcoderaw.cc:22