My Project
userop.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 
19 #ifndef __CPUI_USEROP__
20 #define __CPUI_USEROP__
21 
22 #include "typeop.hh"
23 
36 class UserPcodeOp {
37 protected:
38  string name;
39  int4 useropindex;
41 public:
42  UserPcodeOp(Architecture *g,const string &nm,int4 ind) {
43  name = nm; useropindex = ind; glb = g; }
44  const string &getName(void) const { return name; }
45  int4 getIndex(void) const { return useropindex; }
46  virtual ~UserPcodeOp(void) {}
47 
54  virtual string getOperatorName(const PcodeOp *op) const {
55  return name; }
56 
62  virtual void restoreXml(const Element *el)=0;
63 };
64 
71 public:
72  UnspecializedPcodeOp(Architecture *g,const string &nm,int4 ind)
73  : UserPcodeOp(g,nm,ind) {}
74  virtual void restoreXml(const Element *el) {}
75 };
76 
83 class InjectedUserOp : public UserPcodeOp {
84  uint4 injectid;
85 public:
86  InjectedUserOp(Architecture *g,const string &nm,int4 ind,int4 injid)
87  : UserPcodeOp(g,nm,ind) { injectid = injid; }
88  uint4 getInjectId(void) const { return injectid; }
89  virtual void restoreXml(const Element *el);
90 };
91 
99 class VolatileOp : public UserPcodeOp {
100 protected:
101  static string appendSize(const string &base,int4 size);
102 public:
103  VolatileOp(Architecture *g,const string &nm,int4 ind)
104  : UserPcodeOp(g,nm,ind) { }
105 };
106 
112 class VolatileReadOp : public VolatileOp {
113 public:
114  VolatileReadOp(Architecture *g,const string &nm,int4 ind)
115  : VolatileOp(g,nm,ind) {}
116  virtual string getOperatorName(const PcodeOp *op) const;
117  virtual void restoreXml(const Element *el);
118 };
119 
126 class VolatileWriteOp : public VolatileOp {
127 public:
128  VolatileWriteOp(Architecture *g,const string &nm,int4 ind)
129  : VolatileOp(g,nm,ind) {}
130  virtual string getOperatorName(const PcodeOp *op) const;
131  virtual void restoreXml(const Element *el);
132 };
133 
144 class TermPatternOp : public UserPcodeOp {
145 public:
146  TermPatternOp(Architecture *g,const string &nm,int4 ind) : UserPcodeOp(g,nm,ind) {}
147  virtual int4 getNumVariableTerms(void) const=0;
148 
155  virtual bool unify(Funcdata &data,PcodeOp *op,vector<Varnode *> &bindlist) const=0;
156 
161  virtual uintb execute(const vector<uintb> &input) const=0;
162 };
163 
169 struct OpFollow {
171  uintb val;
172  int4 slot;
173  OpFollow(void) {}
174  void restoreXml(const Element *el);
175 };
176 
199 class SegmentOp : public TermPatternOp {
200  AddrSpace *spc;
201  int4 injectId;
202  int4 baseinsize;
203  int4 innerinsize;
204  bool supportsfarpointer;
205  VarnodeData constresolve;
206 public:
207  SegmentOp(Architecture *g,const string &nm,int4 ind);
208  AddrSpace *getSpace(void) const { return spc; }
209  bool hasFarPointerSupport(void) const { return supportsfarpointer; }
210  int4 getBaseSize(void) const { return baseinsize; }
211  int4 getInnerSize(void) const { return innerinsize; }
212  const VarnodeData &getResolve(void) const { return constresolve; }
213  virtual int4 getNumVariableTerms(void) const { if (baseinsize!=0) return 2; return 1; }
214  virtual bool unify(Funcdata &data,PcodeOp *op,vector<Varnode *> &bindlist) const;
215  virtual uintb execute(const vector<uintb> &input) const;
216  virtual void restoreXml(const Element *el);
217 };
218 
229 class JumpAssistOp : public UserPcodeOp {
230  int4 index2case;
231  int4 index2addr;
232  int4 defaultaddr;
233  int4 calcsize;
234 public:
236  int4 getIndex2Case(void) const { return index2case; }
237  int4 getIndex2Addr(void) const { return index2addr; }
238  int4 getDefaultAddr(void) const { return defaultaddr; }
239  int4 getCalcSize(void) const { return calcsize; }
240  virtual void restoreXml(const Element *el);
241 };
242 
251  vector<UserPcodeOp *> useroplist;
252  map<string,UserPcodeOp *> useropmap;
253  vector<SegmentOp *> segmentop;
254  VolatileReadOp *vol_read;
255  VolatileWriteOp *vol_write;
256  void registerOp(UserPcodeOp *op);
257 public:
258  UserOpManage(void);
259  ~UserOpManage(void);
260  void initialize(Architecture *glb);
261  void setDefaults(Architecture *glb);
262  int4 numSegmentOps(void) const { return segmentop.size(); }
263 
267  UserPcodeOp *getOp(int4 i) const {
268  if (i>=useroplist.size()) return (UserPcodeOp *)0;
269  return useroplist[i];
270  }
271 
272  UserPcodeOp *getOp(const string &nm) const;
273 
277  SegmentOp *getSegmentOp(int4 i) const {
278  if (i>=segmentop.size()) return (SegmentOp *)0;
279  return segmentop[i];
280  }
281 
282  VolatileReadOp *getVolatileRead(void) const { return vol_read; }
283  VolatileWriteOp *getVolatileWrite(void) const { return vol_write; }
284  void parseSegmentOp(const Element *el,Architecture *glb);
285  void parseVolatile(const Element *el,Architecture *glb);
286  void parseCallOtherFixup(const Element *el,Architecture *glb);
287  void parseJumpAssist(const Element *el,Architecture *glb);
288  void manualCallOtherFixup(const string &useropname,const string &outname,
289  const vector<string> &inname,const string &snippet,Architecture *glb);
290 };
291 
292 #endif
A region where processor data is stored.
Definition: space.hh:73
An operation that reads from volatile memory.
Definition: userop.hh:112
int4 numSegmentOps(void) const
Number of segment operations supported.
Definition: userop.hh:262
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
virtual string getOperatorName(const PcodeOp *op) const
Get the symbol representing this operation in decompiled code.
Definition: userop.hh:54
The segmented address operator.
Definition: userop.hh:199
A user defined p-code op that has a dynamically defined procedure.
Definition: userop.hh:144
UserPcodeOp * getOp(int4 i) const
Definition: userop.hh:267
Container for data structures associated with a single function.
Definition: funcdata.hh:45
virtual void restoreXml(const Element *el)
Restore the detailed description from an XML stream.
Definition: userop.hh:74
SegmentOp * getSegmentOp(int4 i) const
Definition: userop.hh:277
const VarnodeData & getResolve(void) const
Get the default register for resolving indirect segments.
Definition: userop.hh:212
VolatileWriteOp * getVolatileWrite(void) const
Get (the) volatile write description.
Definition: userop.hh:283
OpFollow(void)
Construct an empty object.
Definition: userop.hh:173
A user defined operation that is injected with other p-code.
Definition: userop.hh:83
int4 getBaseSize(void) const
Get size in bytes of the base/segment value.
Definition: userop.hh:210
A simple node used to dynamically define a sequence of operations.
Definition: userop.hh:169
VolatileReadOp(Architecture *g, const string &nm, int4 ind)
Constructor.
Definition: userop.hh:114
bool hasFarPointerSupport(void) const
Return true, if this op supports far pointers.
Definition: userop.hh:209
uint4 getInjectId(void) const
Get the id of the injection object.
Definition: userop.hh:88
string name
Low-level name of p-code operator.
Definition: userop.hh:38
int4 getInnerSize(void) const
Get size in bytes of the near value.
Definition: userop.hh:211
VolatileReadOp * getVolatileRead(void) const
Get (the) volatile read description.
Definition: userop.hh:282
Lowest level operation of the p-code language.
Definition: op.hh:58
int4 getIndex2Case(void) const
Get the injection id for index2case.
Definition: userop.hh:236
VolatileOp(Architecture *g, const string &nm, int4 ind)
Constructor.
Definition: userop.hh:103
A user defined p-code op for assisting the recovery of jump tables.
Definition: userop.hh:229
AddrSpace * getSpace(void) const
Get the address space being pointed to.
Definition: userop.hh:208
UnspecializedPcodeOp(Architecture *g, const string &nm, int4 ind)
Constructor.
Definition: userop.hh:72
InjectedUserOp(Architecture *g, const string &nm, int4 ind, int4 injid)
Constructor.
Definition: userop.hh:86
Manager for all the major decompiler subsystems.
Definition: architecture.hh:117
Manager/container for description objects (UserPcodeOp) of user defined p-code ops.
Definition: userop.hh:250
int4 getIndex2Addr(void) const
Get the injection id for index2addr.
Definition: userop.hh:237
OpCode opc
The particular p-code operation.
Definition: userop.hh:170
int4 getIndex(void) const
Get the constant id of the op.
Definition: userop.hh:45
An XML element. A node in the DOM tree.
Definition: xml.hh:150
const string & getName(void) const
Get the low-level name of the p-code op.
Definition: userop.hh:44
Data-type and behavior information associated with specific p-code op-codes.
int4 getDefaultAddr(void) const
Get the injection id for defaultaddr.
Definition: userop.hh:238
int4 useropindex
Index passed in the CALLOTHER op.
Definition: userop.hh:39
A user defined p-code op with no specialization.
Definition: userop.hh:70
virtual void restoreXml(const Element *el)=0
Restore the detailed description from an XML stream.
The base class for a detailed definition of a user-defined p-code operation.
Definition: userop.hh:36
VolatileWriteOp(Architecture *g, const string &nm, int4 ind)
Constructor.
Definition: userop.hh:128
A base class for operations that access volatile memory.
Definition: userop.hh:99
virtual int4 getNumVariableTerms(void) const
Get the number of input Varnodes expected.
Definition: userop.hh:213
int4 slot
Slot to follow.
Definition: userop.hh:172
virtual ~UserPcodeOp(void)
Destructor.
Definition: userop.hh:46
uintb val
A possible constant second input.
Definition: userop.hh:171
UserPcodeOp(Architecture *g, const string &nm, int4 ind)
Construct from name and index.
Definition: userop.hh:42
Architecture * glb
Architecture owning the user defined op.
Definition: userop.hh:40
An operation that writes to volatile memory.
Definition: userop.hh:126
int4 getCalcSize(void) const
Get the injection id for calcsize.
Definition: userop.hh:239
Data defining a specific memory location.
Definition: pcoderaw.hh:33
TermPatternOp(Architecture *g, const string &nm, int4 ind)
Constructor.
Definition: userop.hh:146