My Project
variable.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_TYPEVAR__
20 #define __CPUI_TYPEVAR__
21 
22 #include "varnode.hh"
23 
24 class Symbol;
25 
38 class HighVariable {
39 public:
45  enum {
46  flagsdirty = 1,
48  typedirty = 4,
49  coverdirty = 8,
50  symboldirty = 0x10,
51  copy_in1 = 0x20,
52  copy_in2 = 0x40,
53  type_finalized = 0x80,
54  unmerged = 0x100
55  };
56 private:
57  friend class Varnode;
58  friend class Merge;
59  vector<Varnode *> inst;
60  int4 numMergeClasses;
61  mutable uint4 highflags;
62  mutable uint4 flags;
63  mutable Datatype *type;
64  mutable Varnode *nameRepresentative;
65  mutable Cover wholecover;
66  mutable Symbol *symbol;
67  mutable int4 symboloffset;
68  int4 instanceIndex(const Varnode *vn) const;
69  void updateFlags(void) const;
70  void updateCover(void) const;
71  void updateType(void) const;
72  void updateSymbol(void) const;
73  void setCopyIn1(void) const { highflags |= copy_in1; }
74  void setCopyIn2(void) const { highflags |= copy_in2; }
75  void clearCopyIns(void) const { highflags &= ~(copy_in1 | copy_in2); }
76  bool hasCopyIn1(void) const { return ((highflags&copy_in1)!=0); }
77  bool hasCopyIn2(void) const { return ((highflags&copy_in2)!=0); }
78  void remove(Varnode *vn);
79  void merge(HighVariable *tv2,bool isspeculative);
80  void setSymbol(Varnode *vn) const;
81  void setSymbolReference(Symbol *sym,int4 off);
82  void flagsDirty(void) const { highflags |= flagsdirty | namerepdirty; }
83  void coverDirty(void) const { highflags |= coverdirty; }
84  void typeDirty(void) const { highflags |= typedirty; }
85  void setUnmerged(void) const { highflags |= unmerged; }
86 public:
87  HighVariable(Varnode *vn);
88  Datatype *getType(void) const { updateType(); return type; }
89  Symbol *getSymbol(void) const { updateSymbol(); return symbol; }
90  SymbolEntry *getSymbolEntry(void) const;
91  int4 getSymbolOffset(void) const { return symboloffset; }
92  int4 numInstances(void) const { return inst.size(); }
93  Varnode *getInstance(int4 i) const { return inst[i]; }
94  void finalizeDatatype(Datatype *tp);
95 
99  void printCover(ostream &s) const { if ((highflags&HighVariable::coverdirty)==0) wholecover.print(s); else s << "Cover dirty"; }
100 
101  void printInfo(ostream &s) const;
102  bool hasName(void) const;
103  Varnode *getTiedVarnode(void) const;
104  Varnode *getInputVarnode(void) const;
105  Varnode *getTypeRepresentative(void) const;
106  Varnode *getNameRepresentative(void) const;
107  int4 getNumMergeClasses(void) const { return numMergeClasses; }
108  bool isMapped(void) const { updateFlags(); return ((flags&Varnode::mapped)!=0); }
109  bool isPersist(void) const { updateFlags(); return ((flags&Varnode::persist)!=0); }
110  bool isAddrTied(void) const { updateFlags(); return ((flags&Varnode::addrtied)!=0); }
111  bool isInput(void) const { updateFlags(); return ((flags&Varnode::input)!=0); }
112  bool isImplied(void) const { updateFlags(); return ((flags&Varnode::implied)!=0); }
113  bool isSpacebase(void) const { updateFlags(); return ((flags&Varnode::spacebase)!=0); }
114  bool isConstant(void) const { updateFlags(); return ((flags&Varnode::constant)!=0); }
115  bool isUnaffected(void) const { updateFlags(); return ((flags&Varnode::unaffected)!=0); }
116  bool isExtraOut(void) const { updateFlags(); return ((flags&(Varnode::indirect_creation|Varnode::addrtied))==Varnode::indirect_creation); }
117  void setMark(void) const { flags |= Varnode::mark; }
118  void clearMark(void) const { flags &= ~Varnode::mark; }
119  bool isMark(void) const { return ((flags&Varnode::mark)!=0); }
120  bool isUnmerged(void) const { return ((highflags&unmerged)!=0); }
121 
126  bool hasCover(void) const {
127  updateFlags();
129 
130  bool isUnattached(void) const { return inst.empty(); }
131  bool isTypeLock(void) const { updateType(); return ((flags & Varnode::typelock)!=0); }
132  bool isNameLock(void) const { updateFlags(); return ((flags & Varnode::namelock)!=0); }
133  void saveXml(ostream &s) const;
134 #ifdef MERGEMULTI_DEBUG
135  void verifyCover(void) const;
136 #endif
137  // Varnode *findGlobalRep(void) const;
138  static bool compareName(Varnode *vn1,Varnode *vn2);
139  static bool compareJustLoc(const Varnode *a,const Varnode *b);
140 };
141 
142 #endif
The symbol attachment is dirty.
Definition: variable.hh:50
static bool compareName(Varnode *vn1, Varnode *vn2)
Determine which given Varnode is most nameable.
Definition: variable.cc:201
The base datatype class for the decompiler.
Definition: type.hh:62
A storage location for a particular Symbol.
Definition: database.hh:51
Varnode * getTypeRepresentative(void) const
Get a member Varnode with the strongest data-type.
Definition: variable.cc:122
void saveXml(ostream &s) const
Save the variable to stream as an XML <high> tag.
Definition: variable.cc:452
Class for merging low-level Varnodes into high-level HighVariables.
Definition: merge.hh:80
Varnode has a database entry associated with it.
Definition: varnode.hh:99
Set if a final data-type is locked in and dirtying is disabled.
Definition: variable.hh:53
bool isConstant(void) const
Return true if this is a constant.
Definition: variable.hh:114
bool isTypeLock(void) const
Return true if this is typelocked.
Definition: variable.hh:131
This varnode is an annotation and has no dataflow.
Definition: varnode.hh:73
Varnode * getNameRepresentative(void) const
Get a member Varnode that dictates the naming of this HighVariable.
Definition: variable.cc:235
int4 getNumMergeClasses(void) const
Get the number of speculative merges for this.
Definition: variable.hh:107
Boolean properties for the HighVariable are dirty.
Definition: variable.hh:46
bool hasCover(void) const
Determine if this HighVariable has an associated cover.
Definition: variable.hh:126
The varnode is constant.
Definition: varnode.hh:72
SymbolEntry * getSymbolEntry(void) const
Definition: variable.cc:278
There exists at least 2 COPYs into this HighVariable from other HighVariables.
Definition: variable.hh:52
bool isPersist(void) const
Return true if this is a global variable.
Definition: variable.hh:109
bool isNameLock(void) const
Return true if this is namelocked.
Definition: variable.hh:132
The data-type for the HighVariable is dirty.
Definition: variable.hh:48
Varnode * getInstance(int4 i) const
Get the i-th member Varnode.
Definition: variable.hh:93
The value in this Varnode is created indirectly.
Definition: varnode.hh:100
bool isUnaffected(void) const
Return true if this is an unaffected register.
Definition: variable.hh:115
There exists at least 1 COPY into this HighVariable from other HighVariables.
Definition: variable.hh:51
The name representative for the HighVariable is dirty.
Definition: variable.hh:47
Prevents infinite loops.
Definition: varnode.hh:71
Persists after (and before) function.
Definition: varnode.hh:91
Varnode * getInputVarnode(void) const
Find (the) input member Varnode.
Definition: variable.cc:399
High-level variable is tied to address.
Definition: varnode.hh:92
Set if part of a multi-entry Symbol but did not get merged with other SymbolEntrys.
Definition: variable.hh:54
bool isUnattached(void) const
Return true if this has no member Varnode.
Definition: variable.hh:130
int4 numInstances(void) const
Get the number of member Varnodes this has.
Definition: variable.hh:92
bool isExtraOut(void) const
Return true if this is an extra output.
Definition: variable.hh:116
void print(ostream &s) const
Dump a description of this cover to stream.
Definition: cover.cc:554
The Name of the Varnode is locked.
Definition: varnode.hh:83
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
int4 getSymbolOffset(void) const
Get the SymbolEntry mapping to this or null.
Definition: variable.hh:91
bool hasName(void) const
Check if this HighVariable can be named.
Definition: variable.cc:350
bool isInput(void) const
Return true if this is an input variable.
Definition: variable.hh:111
void finalizeDatatype(Datatype *tp)
Set a final datatype for this variable.
Definition: variable.cc:292
A description of the topological scope of a single variable object.
Definition: cover.hh:68
HighVariable(Varnode *vn)
Construct a HighVariable with a single member Varnode.
Definition: variable.cc:22
Definition: varnode.hh:76
This varnode is a temporary variable.
Definition: varnode.hh:79
Input which is unaffected by the function.
Definition: varnode.hh:93
void setMark(void) const
Set the mark on this variable.
Definition: variable.hh:117
The base class for a symbol in a symbol table or scope.
Definition: database.hh:153
This is a base register for an address space.
Definition: varnode.hh:94
The Varnode and VarnodeBank classes.
A high-level variable modeled as a list of low-level variables, each written once.
Definition: variable.hh:38
bool isUnmerged(void) const
Return true if this has merge problems.
Definition: variable.hh:120
bool isMark(void) const
Return true if this is marked.
Definition: variable.hh:119
The Dataype of the Varnode is locked.
Definition: varnode.hh:82
Varnode * getTiedVarnode(void) const
Find the first address tied member Varnode.
Definition: variable.cc:384
void clearMark(void) const
Clear the mark on this variable.
Definition: variable.hh:118
Datatype * getType(void) const
Get the data-type.
Definition: variable.hh:88
bool isAddrTied(void) const
Return true if this is address ties.
Definition: variable.hh:110
void printCover(ostream &s) const
Print details of the cover for this (for debug purposes)
Definition: variable.hh:99
static bool compareJustLoc(const Varnode *a, const Varnode *b)
Compare based on storage location.
Definition: variable.cc:184
bool isSpacebase(void) const
Return true if this is a spacebase.
Definition: variable.hh:113
Symbol * getSymbol(void) const
Get the Symbol associated with this or null.
Definition: variable.hh:89
The cover for the HighVariable is dirty.
Definition: variable.hh:49
void printInfo(ostream &s) const
Print information about this HighVariable to stream.
Definition: variable.cc:410
This varnode has no ancestor.
Definition: varnode.hh:74
bool isMapped(void) const
Return true if this is mapped.
Definition: variable.hh:108
bool isImplied(void) const
Return true if this is an implied variable.
Definition: variable.hh:112