My Project
cpool.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 __CPOOL__
20 #define __CPOOL__
21 
22 #include "type.hh"
23 
44 class CPoolRecord {
45 public:
47  enum {
56  };
57  enum {
58  has_thisptr = 0x1,
61  };
62 private:
63  friend class ConstantPool;
64  uint4 tag;
65  uint4 flags;
66  string token;
67  uintb value;
68  Datatype *type;
69  uint1 *byteData;
70  int4 byteDataLen;
71 public:
72  CPoolRecord(void) { type = (Datatype *)0; byteData = (uint1 *)0; }
73  ~CPoolRecord(void) { if (byteData != (uint1 *)0) delete [] byteData; }
74  uint4 getTag(void) const { return tag; }
75  const string &getToken(void) const { return token; }
76  const uint1 *getByteData(void) const { return byteData; }
77  int4 getByteDataLength(void) const { return byteDataLen; }
78  Datatype *getType(void) const { return type; }
79  uintb getValue(void) const { return value; }
80  bool hasThisPointer(void) const { return ((flags & has_thisptr)!=0); }
81  bool isConstructor(void) const { return ((flags & is_constructor)!=0); }
82  bool isDestructor(void) const { return ((flags & is_destructor)!=0); }
83  void saveXml(ostream &s) const;
84  void restoreXml(const Element *el,TypeFactory &typegrp);
85 };
86 
94 class ConstantPool {
101  virtual CPoolRecord *createRecord(const vector<uintb> &refs)=0;
102 public:
103  virtual ~ConstantPool() {}
104 
109  virtual const CPoolRecord *getRecord(const vector<uintb> &refs) const=0;
110 
119  void putRecord(const vector<uintb> &refs,uint4 tag,const string &tok,Datatype *ct);
120 
129  const CPoolRecord *restoreXmlRecord(const vector<uintb> &refs,const Element *el,TypeFactory &typegrp);
130 
131  virtual bool empty(void) const=0;
132  virtual void clear(void)=0;
133 
139  virtual void saveXml(ostream &s) const=0;
140 
147  virtual void restoreXml(const Element *el,TypeFactory &typegrp)=0;
148 };
149 
156 
165  class CheapSorter {
166  public:
167  uintb a;
168  uintb b;
169  CheapSorter(void) { a = 0; b = 0; }
170  CheapSorter(const CheapSorter &op2) { a = op2.a; b = op2.b; }
171  CheapSorter(const vector<uintb> &refs) { a = refs[0]; b = (refs.size() > 1) ? refs[1] : 0; }
172 
177  bool operator<(const CheapSorter &op2) const {
178  if (a != op2.a) return (a<op2.a);
179  return (b < op2.b);
180  }
181 
185  void apply(vector<uintb> &refs) const { refs.push_back(a); refs.push_back(b); }
186 
187  void saveXml(ostream &s) const;
188  void restoreXml(const Element *el);
189  };
190  map<CheapSorter,CPoolRecord> cpoolMap;
191  virtual CPoolRecord *createRecord(const vector<uintb> &refs);
192 public:
193  virtual const CPoolRecord *getRecord(const vector<uintb> &refs) const;
194  virtual bool empty(void) const { return cpoolMap.empty(); }
195  virtual void clear(void) { cpoolMap.clear(); }
196  virtual void saveXml(ostream &s) const;
197  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
198 };
199 
200 #endif
void saveXml(ostream &s) const
Save object to an XML stream.
Definition: cpool.cc:20
const string & getToken(void) const
Get name of method or data-type.
Definition: cpool.hh:75
bool isDestructor(void) const
Is object a destructor method.
Definition: cpool.hh:82
The base datatype class for the decompiler.
Definition: type.hh:62
virtual void clear(void)
Release any (local) resources.
Definition: cpool.hh:195
void restoreXml(const Element *el, TypeFactory &typegrp)
Restore object from XML stream.
Definition: cpool.cc:77
Pointer to object, new name in token, new data-type in type.
Definition: cpool.hh:55
Referenced method has a this pointer.
Definition: cpool.hh:58
Pointer to a field, name in token, data-type in type.
Definition: cpool.hh:52
Constant reference to string (passed back as byteData)
Definition: cpool.hh:49
uintb getValue(void) const
Get the constant value associated with this.
Definition: cpool.hh:79
An implementation of the ConstantPool interface storing records internally in RAM.
Definition: cpool.hh:155
~CPoolRecord(void)
Destructor.
Definition: cpool.hh:73
Reference to (system level) class object, token holds class name.
Definition: cpool.hh:50
int4 getByteDataLength(void) const
Number of bytes of string literal data.
Definition: cpool.hh:77
Referenced method is a destructor.
Definition: cpool.hh:60
uint4 getTag(void) const
Get the type of record.
Definition: cpool.hh:74
Referenced method is a constructor.
Definition: cpool.hh:59
Integer length, token is language specific indicator, type is integral data-type. ...
Definition: cpool.hh:53
Datatype * getType(void) const
Get the data-type associated with this.
Definition: cpool.hh:78
const uint1 * getByteData(void) const
Get pointer to string literal data.
Definition: cpool.hh:76
An interface to the pool of constant objects for byte-code languages.
Definition: cpool.hh:94
Classes for describing and printing data-types.
An XML element. A node in the DOM tree.
Definition: xml.hh:150
Constant value of data-type type, cpool operator can be eliminated.
Definition: cpool.hh:48
A description of a byte-code object referenced by a constant.
Definition: cpool.hh:44
virtual bool empty(void) const
Is the container empty of records.
Definition: cpool.hh:194
Container class for all Datatype objects in an Architecture.
Definition: type.hh:380
Boolean value, token is language specific indicator, type is boolean data-type.
Definition: cpool.hh:54
Pointer to a method, name in token, signature in type.
Definition: cpool.hh:51
bool hasThisPointer(void) const
Is object a method with a this pointer.
Definition: cpool.hh:80
CPoolRecord(void)
Construct an empty record.
Definition: cpool.hh:72
virtual ~ConstantPool()
Destructor.
Definition: cpool.hh:103
bool isConstructor(void) const
Is object a constructor method.
Definition: cpool.hh:81