Ghidra Decompiler Analysis Engine
database.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  */
22 
23 #ifndef __CPUI_DATABASE__
24 #define __CPUI_DATABASE__
25 
26 #include "variable.hh"
27 #include "partmap.hh"
28 #include "rangemap.hh"
29 
30 class Architecture;
31 class Funcdata;
32 class Scope;
33 class Database;
34 class Symbol;
35 class PrintLanguage;
36 
51 class SymbolEntry {
52  friend class Scope;
53  Symbol *symbol;
54  uint4 extraflags;
55  Address addr;
56  uint8 hash;
57  int4 offset;
58  int4 size;
59  RangeList uselimit;
60  SymbolEntry(Symbol *sym);
61 public:
67  class EntryInitData {
68  friend class SymbolEntry;
69  AddrSpace *space;
70  Symbol *symbol;
71  uint4 extraflags;
72  int4 offset;
73  const RangeList &uselimit;
74  public:
75  EntryInitData(Symbol *sym,uint4 exfl,AddrSpace *spc,int4 off,const RangeList &ul)
76  : uselimit(ul) { symbol = sym; extraflags=exfl; space = spc; offset = off; }
77  };
78 
83  class EntrySubsort {
84  friend class SymbolEntry;
85  int4 useindex;
86  uintb useoffset;
87  public:
88  EntrySubsort(const Address &addr) {
89  useindex = addr.getSpace()->getIndex(); useoffset = addr.getOffset(); }
90  EntrySubsort(void) { useindex=0; useoffset=0; }
91 
95  EntrySubsort(bool val) {
96  if (val) { useindex=0xffff; } // Greater than any real values
97  else { useindex=0; useoffset=0; } // Less than any real values
98  }
101  useindex = op2.useindex;
102  useoffset = op2.useoffset;
103  }
105  bool operator<(const EntrySubsort &op2) {
106  if (useindex != op2.useindex)
107  return (useindex < op2.useindex);
108  return (useoffset < op2.useoffset);
109  }
110  };
111  typedef uintb linetype;
114 
115  SymbolEntry(const EntryInitData &data,uintb a,uintb b);
116  SymbolEntry(Symbol *sym,uint4 exfl,uint8 h,int4 off,int4 sz,const RangeList &rnglist);
117  bool isPiece(void) const { return ((extraflags&(Varnode::precislo|Varnode::precishi))!=0); }
118  bool isDynamic(void) const { return addr.isInvalid(); }
119  bool isInvalid(void) const { return (addr.isInvalid() && (hash==0)); }
120  uint4 getAllFlags(void) const;
121  int4 getOffset(void) const { return offset; }
122  uintb getFirst(void) const { return addr.getOffset(); }
123  uintb getLast(void) const { return (addr.getOffset()+size-1); }
124  subsorttype getSubsort(void) const;
125  Symbol *getSymbol(void) const { return symbol; }
126  const Address &getAddr(void) const { return addr; }
127  uint8 getHash(void) const { return hash; }
128  int4 getSize(void) const { return size; }
129  bool inUse(const Address &usepoint) const;
130  const RangeList &getUseLimit(void) const { return uselimit; }
131  Address getFirstUseAddress(void) const;
132  void setUseLimit(const RangeList &uselim) { uselimit = uselim; }
133  bool isAddrTied(void) const;
134  bool updateType(Varnode *vn) const;
135  Datatype *getSizedType(const Address &addr,int4 sz) const;
136  void printEntry(ostream &s) const;
137  void saveXml(ostream &s) const;
138  List::const_iterator restoreXml(List::const_iterator iter,const AddrSpaceManager *manage);
139 };
141 
152 class Symbol {
153  friend class Scope;
154  friend class ScopeInternal;
155  friend class SymbolCompareName;
156 protected:
158  string name;
160  uint4 nameDedup;
161  uint4 flags;
162  // only typelock,namelock,readonly,externref
163  // addrtied, persist inherited from scope
164  uint4 dispflags;
165  int2 category;
166  uint2 catindex;
167  uint8 symbolId;
168  vector<list<SymbolEntry>::iterator> mapentry;
169  mutable const Scope *depthScope;
170  mutable int4 depthResolution;
171  uint4 wholeCount;
172  virtual ~Symbol(void) {}
173  void setDisplayFormat(uint4 val);
174  void checkSizeTypeLock(void);
175  void setThisPointer(bool val);
176 public:
178  enum {
179  force_hex = 1,
180  force_dec = 2,
181  force_oct = 3,
182  force_bin = 4,
185  isolate = 16,
188  };
189 
190  Symbol(Scope *sc,const string &nm,Datatype *ct);
191  Symbol(Scope *sc);
192  const string &getName(void) const { return name; }
193  Datatype *getType(void) const { return type; }
194  uint8 getId(void) const { return symbolId; }
195  uint4 getFlags(void) const { return flags; }
196  uint4 getDisplayFormat(void) const { return (dispflags & 7); }
197  int2 getCategory(void) const { return category; }
198  uint2 getCategoryIndex(void) const { return catindex; }
199  bool isTypeLocked(void) const { return ((flags&Varnode::typelock)!=0); }
200  bool isNameLocked(void) const { return ((flags&Varnode::namelock)!=0); }
201  bool isSizeTypeLocked(void) const { return ((dispflags & size_typelock)!=0); }
202  bool isThisPointer(void) const { return ((dispflags & is_this_ptr)!=0); }
203  bool isIndirectStorage(void) const { return ((flags&Varnode::indirectstorage)!=0); }
204  bool isHiddenReturn(void) const { return ((flags&Varnode::hiddenretparm)!=0); }
205  bool isNameUndefined(void) const;
206  bool isMultiEntry(void) const { return (wholeCount > 1); }
207  bool hasMergeProblems(void) const { return ((dispflags & merge_problems)!=0); }
208  void setMergeProblems(void) { dispflags |= merge_problems; }
209  bool isIsolated(void) const { return ((dispflags & isolate)!=0); }
210  void setIsolated(bool val);
211  Scope *getScope(void) const { return scope; }
212  SymbolEntry *getFirstWholeMap(void) const;
213  SymbolEntry *getMapEntry(const Address &addr) const;
214  int4 numEntries(void) const { return mapentry.size(); }
215  SymbolEntry *getMapEntry(int4 i) const { return &(*mapentry[i]); }
216  int4 getMapEntryPosition(const SymbolEntry *entry) const;
217  int4 getResolutionDepth(const Scope *useScope) const;
218  void saveXmlHeader(ostream &s) const;
219  void restoreXmlHeader(const Element *el);
220  void saveXmlBody(ostream &s) const;
221  void restoreXmlBody(List::const_iterator iter);
222  virtual void saveXml(ostream &s) const;
223  virtual void restoreXml(const Element *el);
224  virtual int4 getBytesConsumed(void) const;
225  static uint8 ID_BASE;
226 };
227 
230 inline void Symbol::setDisplayFormat(uint4 val)
231 
232 {
233  dispflags &= 0xfffffff8;
234  dispflags |= val;
235 }
236 
239 inline uint4 SymbolEntry::getAllFlags(void) const {
240  return extraflags | symbol->getFlags();
241 }
242 
243 inline bool SymbolEntry::isAddrTied(void) const {
244  return ((symbol->getFlags()&Varnode::addrtied)!=0);
245 }
246 
251 class FunctionSymbol : public Symbol {
252  Funcdata *fd;
253  int4 consumeSize;
254  virtual ~FunctionSymbol(void);
255  void buildType(void);
256 public:
257  FunctionSymbol(Scope *sc,const string &nm,int4 size);
258  FunctionSymbol(Scope *sc,int4 size);
259  Funcdata *getFunction(void);
260  virtual void saveXml(ostream &s) const;
261  virtual void restoreXml(const Element *el);
262  virtual int4 getBytesConsumed(void) const { return consumeSize; }
263 };
264 
270 class EquateSymbol : public Symbol {
271  uintb value;
272 public:
273  EquateSymbol(Scope *sc) : Symbol(sc) { value = 0; category = 1; }
274  uintb getValue(void) const { return value; }
275  bool isValueClose(uintb op2Value,int4 size) const;
276  virtual void saveXml(ostream &s) const;
277  virtual void restoreXml(const Element *el);
278 };
279 
281 class LabSymbol : public Symbol {
282  void buildType(void);
283 public:
284  LabSymbol(Scope *sc,const string &nm);
285  LabSymbol(Scope *sc);
286  virtual void saveXml(ostream &s) const;
287  virtual void restoreXml(const Element *el);
288 };
289 
296 class ExternRefSymbol : public Symbol {
297  Address refaddr;
298  void buildNameType(void);
299  virtual ~ExternRefSymbol(void) {}
300 public:
301  ExternRefSymbol(Scope *sc,const Address &ref,const string &nm);
302  ExternRefSymbol(Scope *sc) : Symbol(sc) {}
303  const Address &getRefAddr(void) const { return refaddr; }
304  virtual void saveXml(ostream &s) const;
305  virtual void restoreXml(const Element *el);
306 };
307 
310 public:
317  bool operator()(const Symbol *sym1,const Symbol *sym2) const {
318  int4 comp = sym1->name.compare(sym2->name);
319  if (comp < 0) return true;
320  if (comp > 0) return false;
321  return (sym1->nameDedup < sym2->nameDedup);
322  }
323 };
324 typedef set<Symbol *,SymbolCompareName> SymbolNameTree;
325 
330 class MapIterator {
331  const vector<EntryMap *> *map;
332  vector<EntryMap *>::const_iterator curmap;
333  list<SymbolEntry>::const_iterator curiter;
334 public:
335  MapIterator(void) { map = (const vector<EntryMap *> *)0; }
336 
342  MapIterator(const vector<EntryMap *> *m,
343  vector<EntryMap *>::const_iterator cm,
344  list<SymbolEntry>::const_iterator ci) {
345  map = m; curmap = cm; curiter = ci;
346  }
347 
349  MapIterator(const MapIterator &op2) {
350  map = op2.map; curmap = op2.curmap; curiter = op2.curiter;
351  }
352  const SymbolEntry *operator*(void) const { return &(*curiter); }
353  MapIterator &operator++(void);
354  MapIterator operator++(int4 i);
355 
358  map = op2.map;
359  curmap = op2.curmap;
360  curiter = op2.curiter;
361  return *this;
362  }
363 
365  bool operator==(const MapIterator &op2) const {
366  if (curmap != op2.curmap) return false;
367  if (curmap == map->end()) return true;
368  return (curiter==op2.curiter);
369  }
370 
372  bool operator!=(const MapIterator &op2) const {
373  if (curmap != op2.curmap) return true;
374  if (curmap == map->end()) return false;
375  return (curiter!=op2.curiter);
376  }
377 };
378 
379 typedef map<uint8,Scope *> ScopeMap;
380 
402 class Scope {
403  friend class Database;
404  friend class ScopeCompare;
405  RangeList rangetree;
406  Scope *parent;
407  Scope *owner;
408  ScopeMap children;
409  void attachScope(Scope *child);
410  void detachScope(ScopeMap::iterator iter);
411  static uint8 hashScopeName(uint8 baseId,const string &nm);
412 protected:
414  string name;
416  uint8 uniqueId;
417  static const Scope *stackAddr(const Scope *scope1,
418  const Scope *scope2,
419  const Address &addr,
420  const Address &usepoint,
421  SymbolEntry **addrmatch);
422  static const Scope *stackContainer(const Scope *scope1,
423  const Scope *scope2,
424  const Address &addr,int4 size,
425  const Address &usepoint,
426  SymbolEntry **addrmatch);
427  static const Scope *stackClosestFit(const Scope *scope1,
428  const Scope *scope2,
429  const Address &addr,int4 size,
430  const Address &usepoint,
431  SymbolEntry **addrmatch);
432  static const Scope *stackFunction(const Scope *scope1,
433  const Scope *scope2,
434  const Address &addr,
435  Funcdata **addrmatch);
436  static const Scope *stackExternalRef(const Scope *scope1,
437  const Scope *scope2,
438  const Address &addr,
439  ExternRefSymbol **addrmatch);
440  static const Scope *stackCodeLabel(const Scope *scope1,
441  const Scope *scope2,
442  const Address &addr,
443  LabSymbol **addrmatch);
444 
445  const RangeList &getRangeTree(void) const { return rangetree; }
446 
454  virtual Scope *buildSubScope(uint8 id,const string &nm)=0;
455 
456  virtual void restrictScope(Funcdata *f);
457 
458  // These add/remove range are for scope \b discovery, i.e. we may
459  // know an address belongs to a certain scope, without knowing any symbol
460  virtual void addRange(AddrSpace *spc,uintb first,uintb last);
461  virtual void removeRange(AddrSpace *spc,uintb first,uintb last);
462 
466  virtual void addSymbolInternal(Symbol *sym)=0;
467 
478  virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,
479  const RangeList &uselim)=0;
480 
481 
493  virtual SymbolEntry *addDynamicMapInternal(Symbol *sym,uint4 exfl,uint8 hash,int4 off,int4 sz,
494  const RangeList &uselim)=0;
495  SymbolEntry *addMap(SymbolEntry &entry);
496  void setSymbolId(Symbol *sym,uint8 id) const { sym->symbolId = id; }
497 public:
498 #ifdef OPACTION_DEBUG
499  mutable bool debugon;
500  void turnOnDebug(void) const { debugon = true; }
501  void turnOffDebug(void) const { debugon = false; }
502 #endif
503  Scope(uint8 id,const string &nm,Architecture *g,Scope *own) {
505  uniqueId = id; name = nm; glb = g; parent = (Scope *)0; fd = (Funcdata *)0; owner=own;
506 #ifdef OPACTION_DEBUG
507  debugon = false;
508 #endif
509  }
510  virtual ~Scope(void);
511  virtual MapIterator begin(void) const=0;
512  virtual MapIterator end(void) const=0;
513  virtual list<SymbolEntry>::const_iterator beginDynamic(void) const=0;
514  virtual list<SymbolEntry>::const_iterator endDynamic(void) const=0;
515  virtual list<SymbolEntry>::iterator beginDynamic(void)=0;
516  virtual list<SymbolEntry>::iterator endDynamic(void)=0;
517  virtual void clear(void)=0;
518  virtual void clearCategory(int4 cat)=0;
519  virtual void clearUnlocked(void)=0;
520  virtual void clearUnlockedCategory(int4 cat)=0;
521 
525  virtual void adjustCaches(void)=0;
526 
535  virtual bool inScope(const Address &addr,int4 size, const Address &usepoint) const {
536  return rangetree.inRange(addr,size); }
537 
538  virtual void removeSymbolMappings(Symbol *symbol)=0;
539  virtual void removeSymbol(Symbol *symbol)=0;
540  virtual void renameSymbol(Symbol *sym,const string &newname)=0;
541 
547  virtual void retypeSymbol(Symbol *sym,Datatype *ct)=0;
548  virtual void setAttribute(Symbol *sym,uint4 attr)=0;
549  virtual void clearAttribute(Symbol *sym,uint4 attr)=0;
550  virtual void setDisplayFormat(Symbol *sym,uint4 attr)=0;
551 
552  // Find routines only search the scope itself
553 
559  virtual SymbolEntry *findAddr(const Address &addr,const Address &usepoint) const=0;
560 
567  virtual SymbolEntry *findContainer(const Address &addr,int4 size,
568  const Address &usepoint) const=0;
569 
576  virtual SymbolEntry *findClosestFit(const Address &addr,int4 size,
577  const Address &usepoint) const=0;
578 
583  virtual Funcdata *findFunction(const Address &addr) const=0;
584 
589  virtual ExternRefSymbol *findExternalRef(const Address &addr) const=0;
590 
595  virtual LabSymbol *findCodeLabel(const Address &addr) const=0;
596 
602  virtual SymbolEntry *findOverlap(const Address &addr,int4 size) const=0;
603 
609  virtual void findByName(const string &name,vector<Symbol *> &res) const=0;
610 
618  virtual bool isNameUsed(const string &nm,const Scope *op2) const=0;
619 
624  virtual Funcdata *resolveExternalRefFunction(ExternRefSymbol *sym) const=0;
625 
634  virtual string buildVariableName(const Address &addr,
635  const Address &pc,
636  Datatype *ct,int4 &index,uint4 flags) const=0;
637 
641  virtual string buildUndefinedName(void) const=0;
642 
647  virtual string makeNameUnique(const string &nm) const=0;
648 
649  virtual void saveXml(ostream &s) const=0;
650  virtual void restoreXml(const Element *el)=0;
651  virtual void printEntries(ostream &s) const=0;
652 
657  virtual int4 getCategorySize(int4 cat) const=0;
658 
664  virtual Symbol *getCategorySymbol(int4 cat,int4 ind) const=0;
665 
671  virtual void setCategory(Symbol *sym,int4 cat,int4 ind)=0;
672 
673  virtual SymbolEntry *addSymbol(const string &name,Datatype *ct,
674  const Address &addr,const Address &usepoint);
675 
676  const string &getName(void) const { return name; }
677  uint8 getId(void) const { return uniqueId; }
678  bool isGlobal(void) const { return (fd == (Funcdata *)0); }
679 
680  // The main global querying routines
681  void queryByName(const string &name,vector<Symbol *> &res) const;
682  Funcdata *queryFunction(const string &name) const;
683  SymbolEntry *queryByAddr(const Address &addr,
684  const Address &usepoint) const;
685  SymbolEntry *queryContainer(const Address &addr,int4 size,
686  const Address &usepoint) const;
687  SymbolEntry *queryProperties(const Address &addr,int4 size,
688  const Address &usepoint,uint4 &flags) const;
689  Funcdata *queryFunction(const Address &addr) const;
690  Funcdata *queryExternalRefFunction(const Address &addr) const;
691  LabSymbol *queryCodeLabel(const Address &addr) const;
692 
693  Scope *resolveScope(const string &name, bool strategy) const;
694  Scope *discoverScope(const Address &addr,int4 sz,const Address &usepoint);
695  ScopeMap::const_iterator childrenBegin() const { return children.begin(); }
696  ScopeMap::const_iterator childrenEnd() const { return children.end(); }
697  void saveXmlRecursive(ostream &s,bool onlyGlobal) const;
698  void overrideSizeLockType(Symbol *sym,Datatype *ct);
699  void resetSizeLockType(Symbol *sym);
700  void setThisPointer(Symbol *sym,bool val) { sym->setThisPointer(val); }
701  bool isSubScope(const Scope *scp) const;
702  string getFullName(void) const;
703  void getScopePath(vector<const Scope *> &vec) const;
704  const Scope *findDistinguishingScope(const Scope *op2) const;
705  Architecture *getArch(void) const { return glb; }
706  Scope *getParent(void) const { return parent; }
707  Symbol *addSymbol(const string &name,Datatype *ct);
708  SymbolEntry *addMapPoint(Symbol *sym,const Address &addr,
709  const Address &usepoint);
710  Symbol *addMapSym(const Element *el);
711  FunctionSymbol *addFunction(const Address &addr,const string &nm);
712  ExternRefSymbol *addExternalRef(const Address &addr,const Address &refaddr,const string &nm);
713  LabSymbol *addCodeLabel(const Address &addr,const string &nm);
714  Symbol *addDynamicSymbol(const string &nm,Datatype *ct,const Address &caddr,uint8 hash);
715  string buildDefaultName(Symbol *sym,int4 &base,Varnode *vn) const;
716  bool isReadOnly(const Address &addr,int4 size,const Address &usepoint) const;
717  void printBounds(ostream &s) const { rangetree.printBounds(s); }
718 };
719 
726 class ScopeInternal : public Scope {
727  void processHole(const Element *el);
728  void processCollision(const Element *el);
729  void insertNameTree(Symbol *sym);
730  SymbolNameTree::const_iterator findFirstByName(const string &name) const;
731 protected:
732  virtual Scope *buildSubScope(uint8 id,const string &nm);
733  virtual void addSymbolInternal(Symbol *sym);
734  virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,const RangeList &uselim);
735  virtual SymbolEntry *addDynamicMapInternal(Symbol *sym,uint4 exfl,uint8 hash,int4 off,int4 sz,
736  const RangeList &uselim);
738  vector<EntryMap *> maptable;
739  vector<vector<Symbol *> > category;
740  list<SymbolEntry> dynamicentry;
742  uint8 nextUniqueId;
743 public:
744  ScopeInternal(uint8 id,const string &nm,Architecture *g);
745  ScopeInternal(uint8 id,const string &nm,Architecture *g, Scope *own);
746  virtual void clear(void);
747  virtual void categorySanity(void);
748  virtual void clearCategory(int4 cat);
749  virtual void clearUnlocked(void);
750  virtual void clearUnlockedCategory(int4 cat);
751  virtual void adjustCaches(void);
752  virtual ~ScopeInternal(void);
753  virtual MapIterator begin(void) const;
754  virtual MapIterator end(void) const;
755  virtual list<SymbolEntry>::const_iterator beginDynamic(void) const;
756  virtual list<SymbolEntry>::const_iterator endDynamic(void) const;
757  virtual list<SymbolEntry>::iterator beginDynamic(void);
758  virtual list<SymbolEntry>::iterator endDynamic(void);
759  virtual void removeSymbolMappings(Symbol *symbol);
760  virtual void removeSymbol(Symbol *symbol);
761  virtual void renameSymbol(Symbol *sym,const string &newname);
762  virtual void retypeSymbol(Symbol *sym,Datatype *ct);
763  virtual void setAttribute(Symbol *sym,uint4 attr);
764  virtual void clearAttribute(Symbol *sym,uint4 attr);
765  virtual void setDisplayFormat(Symbol *sym,uint4 attr);
766 
767  virtual SymbolEntry *findAddr(const Address &addr,const Address &usepoint) const;
768  virtual SymbolEntry *findContainer(const Address &addr,int4 size,
769  const Address &usepoint) const;
770  virtual SymbolEntry *findClosestFit(const Address &addr,int4 size,
771  const Address &usepoint) const;
772  virtual Funcdata *findFunction(const Address &addr) const;
773  virtual ExternRefSymbol *findExternalRef(const Address &addr) const;
774  virtual LabSymbol *findCodeLabel(const Address &addr) const;
775  virtual SymbolEntry *findOverlap(const Address &addr,int4 size) const;
776 
777  virtual void findByName(const string &name,vector<Symbol *> &res) const;
778  virtual bool isNameUsed(const string &nm,const Scope *op2) const;
780 
781  virtual string buildVariableName(const Address &addr,
782  const Address &pc,
783  Datatype *ct,int4 &index,uint4 flags) const;
784  virtual string buildUndefinedName(void) const;
785  virtual string makeNameUnique(const string &nm) const;
786  virtual void saveXml(ostream &s) const;
787  virtual void restoreXml(const Element *el);
788  virtual void printEntries(ostream &s) const;
789  virtual int4 getCategorySize(int4 cat) const;
790  virtual Symbol *getCategorySymbol(int4 cat,int4 ind) const;
791  virtual void setCategory(Symbol *sym,int4 cat,int4 ind);
792  void assignDefaultNames(int4 &base);
793  set<Symbol *>::const_iterator beginMultiEntry(void) const { return multiEntrySet.begin(); }
794  set<Symbol *>::const_iterator endMultiEntry(void) const { return multiEntrySet.end(); }
795 };
796 
802 class ScopeMapper {
803  friend class Database;
805  class NullSubsort {
806  public:
807  NullSubsort(void) {}
808  NullSubsort(bool val) {}
809  NullSubsort(const NullSubsort &op2) {}
810  bool operator<(const NullSubsort &op2) { return false; }
811  };
812 public:
813  typedef Address linetype;
814  typedef NullSubsort subsorttype;
815  typedef Scope *inittype;
816 private:
817  Scope *scope;
818  Address first;
819  Address last;
820 public:
821  ScopeMapper(const inittype &data,const Address &f,const Address &l) {
822  scope = data; first = f; last = l; }
823  Address getFirst(void) const { return first; }
824  Address getLast(void) const { return last; }
825  NullSubsort getSubsort(void) const { return NullSubsort(); }
826  Scope *getScope(void) const { return scope; }
827 };
829 
844 class Database {
845  Architecture *glb;
846  Scope *globalscope;
847  ScopeResolve resolvemap;
848  ScopeMap idmap;
849  partmap<Address,uint4> flagbase;
850  bool idByNameHash;
851  void clearResolve(Scope *scope);
852  void clearReferences(Scope *scope);
853  void fillResolve(Scope *scope);
854  Scope *parseParentTag(const Element *el);
855 public:
856  Database(Architecture *g,bool idByName);
857  ~Database(void);
858  Architecture *getArch(void) const { return glb; }
859  void adjustCaches(void);
860  void attachScope(Scope *newscope,Scope *parent);
861  void deleteScope(Scope *scope);
862  void deleteSubScopes(Scope *scope);
863  void clearUnlocked(Scope *scope);
864  void setRange(Scope *scope,const RangeList &rlist);
865  void addRange(Scope *scope,AddrSpace *spc,uintb first,uintb last);
866  void removeRange(Scope *scope,AddrSpace *spc,uintb first,uintb last);
867  Scope *getGlobalScope(void) const { return globalscope; }
868  Scope *resolveScope(uint8 id) const;
869  Scope *resolveScopeFromSymbolName(const string &fullname,const string &delim,string &basename,Scope *start) const;
870  Scope *findCreateScope(uint8,const string &nm,Scope *parent);
871  Scope *findCreateScopeFromSymbolName(const string &fullname,const string &delim,string &basename,Scope *start);
872  const Scope *mapScope(const Scope *qpoint,const Address &addr,const Address &usepoint) const;
873  Scope *mapScope(Scope *qpoint,const Address &addr,const Address &usepoint);
874  uint4 getProperty(const Address &addr) const { return flagbase.getValue(addr); }
875  void setPropertyRange(uint4 flags,const Range &range);
876  void setProperties(const partmap<Address,uint4> &newflags) { flagbase = newflags; }
877  const partmap<Address,uint4> &getProperties(void) const { return flagbase; }
878  void saveXml(ostream &s) const;
879  void restoreXml(const Element *el);
880  void restoreXmlScope(const Element *el,Scope *newScope);
881 };
882 
886 inline Symbol::Symbol(Scope *sc,const string &nm,Datatype *ct)
887 
888 {
889  scope=sc;
890  name=nm;
891  nameDedup=0;
892  type=ct;
893  flags=0;
894  dispflags=0;
895  category=-1;
896  catindex = 0;
897  symbolId=0;
898  wholeCount=0;
899  depthScope = (const Scope *)0;
900  depthResolution = 0;
901 }
902 
905 
906 {
907  scope=sc;
908  nameDedup=0;
909  type = (Datatype *)0;
910  flags=0;
911  dispflags=0;
912  category=-1;
913  catindex = 0;
914  symbolId = 0;
915  wholeCount=0;
916  depthScope = (const Scope *)0;
917  depthResolution = 0;
918 }
919 
920 #endif
Database::mapScope
const Scope * mapScope(const Scope *qpoint, const Address &addr, const Address &usepoint) const
Determine the lowest-level Scope which might contain the given address as a Symbol.
Definition: database.cc:3077
Scope::clearUnlocked
virtual void clearUnlocked(void)=0
Clear all unlocked symbols from this scope.
MapIterator::operator++
MapIterator & operator++(void)
Pre-increment the iterator.
Definition: database.cc:787
ScopeInternal::getCategorySymbol
virtual Symbol * getCategorySymbol(int4 cat, int4 ind) const
Retrieve a Symbol by index within a specific category.
Definition: database.cc:2713
Scope::queryByAddr
SymbolEntry * queryByAddr(const Address &addr, const Address &usepoint) const
Get Symbol with matching address.
Definition: database.cc:1192
partmap::getValue
_valuetype & getValue(const _linetype &pnt)
Get the value object at a point.
Definition: partmap.hh:81
Scope::findByName
virtual void findByName(const string &name, vector< Symbol * > &res) const =0
Find a Symbol by name within this Scope.
ScopeInternal::nametree
SymbolNameTree nametree
The set of Symbol objects, sorted by name.
Definition: database.hh:737
Scope::getCategorySymbol
virtual Symbol * getCategorySymbol(int4 cat, int4 ind) const =0
Retrieve a Symbol by index within a specific category.
Varnode::namelock
@ namelock
The Name of the Varnode is locked.
Definition: varnode.hh:83
Symbol::flags
uint4 flags
Varnode-like properties of the symbol.
Definition: database.hh:161
PrintLanguage
The base class API for emitting a high-level language.
Definition: printlanguage.hh:134
FunctionSymbol::getBytesConsumed
virtual int4 getBytesConsumed(void) const
Get number of bytes consumed within the address->symbol map.
Definition: database.hh:262
Database::setRange
void setRange(Scope *scope, const RangeList &rlist)
Set the ownership range for a Scope.
Definition: database.cc:2933
Database::~Database
~Database(void)
Destructor.
Definition: database.cc:2830
Symbol::force_char
@ force_char
Force integer to be printed as a character constant.
Definition: database.hh:183
Scope::clearAttribute
virtual void clearAttribute(Symbol *sym, uint4 attr)=0
Clear boolean Varnode properties on a Symbol.
ExternRefSymbol::ExternRefSymbol
ExternRefSymbol(Scope *sc, const Address &ref, const string &nm)
Construct given a placeholder address.
Definition: database.cc:752
MapIterator::MapIterator
MapIterator(const vector< EntryMap * > *m, vector< EntryMap * >::const_iterator cm, list< SymbolEntry >::const_iterator ci)
Construct iterator at a specific position.
Definition: database.hh:342
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
Scope::isReadOnly
bool isReadOnly(const Address &addr, int4 size, const Address &usepoint) const
Is the given memory range marked as read-only.
Definition: database.cc:1711
Symbol::name
string name
The local name of the symbol.
Definition: database.hh:158
ScopeInternal::end
virtual MapIterator end(void) const
Ending iterator to mapped SymbolEntrys.
Definition: database.cc:1827
EquateSymbol::restoreXml
virtual void restoreXml(const Element *el)
Restore this Symbol from an XML stream.
Definition: database.cc:678
partmap.hh
The partmap<> template mapping a linear space to value objects.
Scope::restoreXml
virtual void restoreXml(const Element *el)=0
Restore this Scope from a <scope> XML tag.
Scope::resolveExternalRefFunction
virtual Funcdata * resolveExternalRefFunction(ExternRefSymbol *sym) const =0
Convert an external reference to the referenced function.
ScopeInternal::ScopeInternal
ScopeInternal(uint8 id, const string &nm, Architecture *g)
Construct the Scope.
Definition: database.cc:1861
Varnode::hiddenretparm
@ hiddenretparm
Does this varnode point to the return value storage location.
Definition: varnode.hh:104
Scope::buildDefaultName
string buildDefaultName(Symbol *sym, int4 &base, Varnode *vn) const
Create a default name for the given Symbol.
Definition: database.cc:1671
ScopeInternal::adjustCaches
virtual void adjustCaches(void)
Let scopes internally adjust any caches.
Definition: database.cc:2017
ExternRefSymbol
A function Symbol referring to an external location.
Definition: database.hh:296
Scope::addCodeLabel
LabSymbol * addCodeLabel(const Address &addr, const string &nm)
Create a code label at the given address in this Scope.
Definition: database.cc:1624
Scope::findDistinguishingScope
const Scope * findDistinguishingScope(const Scope *op2) const
Find first ancestor of this not shared by given scope.
Definition: database.cc:1442
SymbolEntry::EntrySubsort::EntrySubsort
EntrySubsort(const EntrySubsort &op2)
Copy constructor.
Definition: database.hh:100
ScopeInternal::nextUniqueId
uint8 nextUniqueId
Next available symbol id.
Definition: database.hh:742
Database::Database
Database(Architecture *g, bool idByName)
Constructor.
Definition: database.cc:2821
ScopeInternal::renameSymbol
virtual void renameSymbol(Symbol *sym, const string &newname)
Rename a Symbol within this Scope.
Definition: database.cc:2058
Scope::makeNameUnique
virtual string makeNameUnique(const string &nm) const =0
Produce a version of the given symbol name that won't collide with other names in this Scope.
Scope::discoverScope
Scope * discoverScope(const Address &addr, int4 sz, const Address &usepoint)
Find the owning Scope of a given memory range.
Definition: database.cc:1314
SymbolEntry::inUse
bool inUse(const Address &usepoint) const
Is this storage valid for the given code address.
Definition: database.cc:90
ScopeMapper::linetype
Address linetype
The linear element for a rangemap.
Definition: database.hh:813
Symbol::depthResolution
int4 depthResolution
Number of namespace elements required to resolve symbol in current scope.
Definition: database.hh:170
Symbol::force_hex
@ force_hex
Force hexadecimal printing of constant symbol.
Definition: database.hh:179
Scope::begin
virtual MapIterator begin(void) const =0
Beginning iterator to mapped SymbolEntrys.
ScopeInternal::findExternalRef
virtual ExternRefSymbol * findExternalRef(const Address &addr) const
Find an external reference at the given address.
Definition: database.cc:2243
ScopeInternal
An in-memory implementation of the Scope interface.
Definition: database.hh:726
Scope::findExternalRef
virtual ExternRefSymbol * findExternalRef(const Address &addr) const =0
Find an external reference at the given address.
Scope::resolveScope
Scope * resolveScope(const string &name, bool strategy) const
Find a child Scope of this.
Definition: database.cc:1276
RangeList::inRange
bool inRange(const Address &addr, int4 size) const
Check containment an address range.
Definition: address.cc:402
Symbol::depthScope
const Scope * depthScope
Scope associated with current depth resolution.
Definition: database.hh:169
SymbolEntry::getAllFlags
uint4 getAllFlags(void) const
Get all Varnode flags for this storage.
Definition: database.hh:239
Symbol::setDisplayFormat
void setDisplayFormat(uint4 val)
Set the display format for this Symbol.
Definition: database.hh:230
Scope::findClosestFit
virtual SymbolEntry * findClosestFit(const Address &addr, int4 size, const Address &usepoint) const =0
Find Symbol which is the closest fit to the given memory range.
Scope::queryCodeLabel
LabSymbol * queryCodeLabel(const Address &addr) const
Look-up a code label by address.
Definition: database.cc:1262
Database::setPropertyRange
void setPropertyRange(uint4 flags, const Range &range)
Set boolean properties over a given memory range.
Definition: database.cc:3112
Scope::addRange
virtual void addRange(AddrSpace *spc, uintb first, uintb last)
Add a memory range to the ownership of this Scope.
Definition: database.cc:1066
Scope::beginDynamic
virtual list< SymbolEntry >::const_iterator beginDynamic(void) const =0
Beginning iterator to dynamic SymbolEntrys.
SymbolEntry::printEntry
void printEntry(ostream &s) const
Dump a description of this to a stream.
Definition: database.cc:155
Scope::getFullName
string getFullName(void) const
Get the full name of this Scope.
Definition: database.cc:1404
Scope::overrideSizeLockType
void overrideSizeLockType(Symbol *sym, Datatype *ct)
Change the data-type of a Symbol that is sizelocked.
Definition: database.cc:1348
ExternRefSymbol::restoreXml
virtual void restoreXml(const Element *el)
Restore this Symbol from an XML stream.
Definition: database.cc:769
Scope::queryByName
void queryByName(const string &name, vector< Symbol * > &res) const
Look-up symbols by name.
Definition: database.cc:1159
Symbol::scope
Scope * scope
The scope that owns this symbol.
Definition: database.hh:157
Scope::setAttribute
virtual void setAttribute(Symbol *sym, uint4 attr)=0
Set boolean Varnode properties on a Symbol.
MapIterator::MapIterator
MapIterator(const MapIterator &op2)
Copy constructor.
Definition: database.hh:349
Scope::queryContainer
SymbolEntry * queryContainer(const Address &addr, int4 size, const Address &usepoint) const
Find the smallest containing Symbol.
Definition: database.cc:1207
Scope::stackAddr
static const Scope * stackAddr(const Scope *scope1, const Scope *scope2, const Address &addr, const Address &usepoint, SymbolEntry **addrmatch)
Query for Symbols starting at a given address, which match a given usepoint.
Definition: database.cc:870
rangemap
An interval map container.
Definition: rangemap.hh:64
ScopeMapper::inittype
Scope * inittype
Initialization data for a ScopeMapper.
Definition: database.hh:815
Symbol::isNameUndefined
bool isNameUndefined(void) const
Does this have an undefined name.
Definition: database.cc:239
LabSymbol::LabSymbol
LabSymbol(Scope *sc, const string &nm)
Construct given name.
Definition: database.cc:704
ScopeResolve
rangemap< ScopeMapper > ScopeResolve
A map from address to the owning Scope.
Definition: database.hh:828
Scope::adjustCaches
virtual void adjustCaches(void)=0
Let scopes internally adjust any caches.
ScopeInternal::printEntries
virtual void printEntries(ostream &s) const
Dump a description of all SymbolEntry objects to a stream.
Definition: database.cc:2690
Scope::clearUnlockedCategory
virtual void clearUnlockedCategory(int4 cat)=0
Clear unlocked symbols of the given category from this scope.
Scope::end
virtual MapIterator end(void) const =0
Ending iterator to mapped SymbolEntrys.
MapIterator
An iterator over SymbolEntry objects in multiple address spaces.
Definition: database.hh:330
Scope::isSubScope
bool isSubScope(const Scope *scp) const
Is this a sub-scope of the given Scope.
Definition: database.cc:1393
SymbolEntry::getSizedType
Datatype * getSizedType(const Address &addr, int4 sz) const
Get the data-type associated with (a piece of) this.
Definition: database.cc:127
SymbolEntry::inittype
EntryInitData inittype
Initialization data for a SymbolEntry in a rangemap.
Definition: database.hh:113
Scope::queryExternalRefFunction
Funcdata * queryExternalRefFunction(const Address &addr) const
Look-up a function thru an external reference.
Definition: database.cc:1377
Symbol::restoreXmlBody
void restoreXmlBody(List::const_iterator iter)
Restore details of the Symbol from XML.
Definition: database.cc:509
Scope::setCategory
virtual void setCategory(Symbol *sym, int4 cat, int4 ind)=0
Set the category and index for the given Symbol.
Database::adjustCaches
void adjustCaches(void)
Let scopes adjust after configuration is finished.
Definition: database.cc:2872
Scope::fd
Funcdata * fd
(If non-null) the function which this is the local Scope for
Definition: database.hh:415
Database::restoreXmlScope
void restoreXmlScope(const Element *el, Scope *newScope)
Register and fill out a single Scope from an XML <scope> tag.
Definition: database.cc:3233
Scope
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:402
Scope::addMapPoint
SymbolEntry * addMapPoint(Symbol *sym, const Address &addr, const Address &usepoint)
Map a Symbol to a specific address.
Definition: database.cc:1507
ScopeInternal::dynamicentry
list< SymbolEntry > dynamicentry
Dynamic symbol entries.
Definition: database.hh:740
Address::isInvalid
bool isInvalid(void) const
Is the address invalid?
Definition: address.hh:256
Address::getOffset
uintb getOffset(void) const
Get the address offset.
Definition: address.hh:300
Scope::addMapSym
Symbol * addMapSym(const Element *el)
Add a mapped Symbol from a <mapsym> XML tag.
Definition: database.cc:1523
Symbol::dispflags
uint4 dispflags
Flags affecting the display of this symbol.
Definition: database.hh:164
Symbol::wholeCount
uint4 wholeCount
Number of SymbolEntries that map to the whole Symbol.
Definition: database.hh:171
ScopeInternal::addDynamicMapInternal
virtual SymbolEntry * addDynamicMapInternal(Symbol *sym, uint4 exfl, uint8 hash, int4 off, int4 sz, const RangeList &uselim)
Create a new SymbolEntry for a Symbol given a dynamic hash.
Definition: database.cc:1787
ScopeMap
map< uint8, Scope * > ScopeMap
A map from id to Scope.
Definition: database.hh:379
Scope::stackExternalRef
static const Scope * stackExternalRef(const Scope *scope1, const Scope *scope2, const Address &addr, ExternRefSymbol **addrmatch)
Definition: database.cc:1001
ScopeInternal::findClosestFit
virtual SymbolEntry * findClosestFit(const Address &addr, int4 size, const Address &usepoint) const
Find Symbol which is the closest fit to the given memory range.
Definition: database.cc:2185
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
ScopeInternal::addSymbolInternal
virtual void addSymbolInternal(Symbol *sym)
Put a Symbol into the name map.
Definition: database.cc:1725
Database::clearUnlocked
void clearUnlocked(Scope *scope)
Clear unlocked Symbols owned by the given Scope.
Definition: database.cc:2917
Scope::removeSymbolMappings
virtual void removeSymbolMappings(Symbol *symbol)=0
Remove all SymbolEntrys from the given Symbol.
Varnode::typelock
@ typelock
The Dataype of the Varnode is locked.
Definition: varnode.hh:82
Symbol::Symbol
Symbol(Scope *sc, const string &nm, Datatype *ct)
Construct given a name and data-type.
Definition: database.hh:886
Scope::addSymbol
virtual SymbolEntry * addSymbol(const string &name, Datatype *ct, const Address &addr, const Address &usepoint)
Add a new Symbol to this Scope, given a name, data-type, and a single mapping.
Definition: database.cc:1491
SymbolEntry::EntryInitData
Initialization data for a SymbolEntry to facilitate a rangemap.
Definition: database.hh:67
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
SymbolEntry
A storage location for a particular Symbol.
Definition: database.hh:51
Symbol::is_this_ptr
@ is_this_ptr
We are the "this" symbol for a class method.
Definition: database.hh:187
Symbol::force_dec
@ force_dec
Force decimal printing of constant symbol.
Definition: database.hh:180
Symbol::nameDedup
uint4 nameDedup
id to distinguish symbols with the same name
Definition: database.hh:160
Scope::findCodeLabel
virtual LabSymbol * findCodeLabel(const Address &addr) const =0
Find a label Symbol at the given address.
ScopeInternal::findOverlap
virtual SymbolEntry * findOverlap(const Address &addr, int4 size) const
Find first Symbol overlapping the given memory range.
Definition: database.cc:2293
variable.hh
Definitions for high-level variables.
ScopeInternal::setDisplayFormat
virtual void setDisplayFormat(Symbol *sym, uint4 attr)
Set the display format for a Symbol.
Definition: database.cc:2119
MapIterator::operator==
bool operator==(const MapIterator &op2) const
Equality operator.
Definition: database.hh:365
Scope::clear
virtual void clear(void)=0
Clear all symbols from this scope.
Scope::isNameUsed
virtual bool isNameUsed(const string &nm, const Scope *op2) const =0
Check if the given name is occurs within the given scope path.
ScopeInternal::restoreXml
virtual void restoreXml(const Element *el)
Restore this Scope from a <scope> XML tag.
Definition: database.cc:2639
Scope::getScopePath
void getScopePath(vector< const Scope * > &vec) const
Get the ordered list of scopes up to this.
Definition: database.cc:1419
ScopeInternal::beginDynamic
virtual list< SymbolEntry >::const_iterator beginDynamic(void) const
Beginning iterator to dynamic SymbolEntrys.
Definition: database.cc:1834
ScopeInternal::category
vector< vector< Symbol * > > category
References to Symbol objects organized by category.
Definition: database.hh:739
Scope::restrictScope
virtual void restrictScope(Funcdata *f)
Convert this to a local Scope.
Definition: database.cc:1057
ScopeInternal::endDynamic
virtual list< SymbolEntry >::const_iterator endDynamic(void) const
Ending iterator to dynamic SymbolEntrys.
Definition: database.cc:1840
ScopeInternal::clearCategory
virtual void clearCategory(int4 cat)
Clear all symbols of the given category from this scope.
Definition: database.cc:1933
Scope::stackCodeLabel
static const Scope * stackCodeLabel(const Scope *scope1, const Scope *scope2, const Address &addr, LabSymbol **addrmatch)
Definition: database.cc:1035
ScopeInternal::multiEntrySet
SymbolNameTree multiEntrySet
Set of symbols with multiple entries.
Definition: database.hh:741
Scope::buildUndefinedName
virtual string buildUndefinedName(void) const =0
Build a formal undefined name, used internally when a Symbol is not given a name.
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
RangeList
A disjoint set of Ranges, possibly across multiple address spaces.
Definition: address.hh:203
Scope::Scope
Scope(uint8 id, const string &nm, Architecture *g, Scope *own)
Construct an empty scope, given a name and Architecture.
Definition: database.hh:504
Database::findCreateScopeFromSymbolName
Scope * findCreateScopeFromSymbolName(const string &fullname, const string &delim, string &basename, Scope *start)
Find (and if not found create) a specific subscope.
Definition: database.cc:3043
ScopeInternal::findFunction
virtual Funcdata * findFunction(const Address &addr) const
Find the function starting at the given address.
Definition: database.cc:2222
Scope::addMapInternal
virtual SymbolEntry * addMapInternal(Symbol *sym, uint4 exfl, const Address &addr, int4 off, int4 sz, const RangeList &uselim)=0
Create a new SymbolEntry for a Symbol given a memory range.
ScopeInternal::findByName
virtual void findByName(const string &name, vector< Symbol * > &res) const
Find a Symbol by name within this Scope.
Definition: database.cc:2306
ScopeInternal::getCategorySize
virtual int4 getCategorySize(int4 cat) const
Get the number of Symbols in the given category.
Definition: database.cc:2705
Symbol::isolate
@ isolate
Symbol should not speculatively merge automatically.
Definition: database.hh:185
LabSymbol::restoreXml
virtual void restoreXml(const Element *el)
Restore this Symbol from an XML stream.
Definition: database.cc:726
SymbolEntry::getSubsort
subsorttype getSubsort(void) const
Get the sub-sort object.
Definition: database.cc:73
EquateSymbol::isValueClose
bool isValueClose(uintb op2Value, int4 size) const
Is the given value similar to this equate.
Definition: database.cc:649
Scope::queryFunction
Funcdata * queryFunction(const string &name) const
Look-up a function by name.
Definition: database.cc:1173
ScopeInternal::saveXml
virtual void saveXml(ostream &s) const
Write out this as a <scope> XML tag.
Definition: database.cc:2517
Scope::glb
Architecture * glb
Architecture of this scope.
Definition: database.hh:413
FunctionSymbol::saveXml
virtual void saveXml(ostream &s) const
Save this Symbol to an XML stream.
Definition: database.cc:601
Scope::addFunction
FunctionSymbol * addFunction(const Address &addr, const string &nm)
Create a function Symbol at the given address in this Scope.
Definition: database.cc:1575
Scope::stackClosestFit
static const Scope * stackClosestFit(const Scope *scope1, const Scope *scope2, const Address &addr, int4 size, const Address &usepoint, SymbolEntry **addrmatch)
Definition: database.cc:938
SymbolEntry::getFirstUseAddress
Address getFirstUseAddress(void) const
Get the first code address where this storage is valid.
Definition: database.cc:98
Scope::addMap
SymbolEntry * addMap(SymbolEntry &entry)
Integrate a SymbolEntry into the range maps.
Definition: database.cc:1087
EquateSymbol
A Symbol that holds equate information for a constant.
Definition: database.hh:270
ScopeMapper
An Address range associated with the symbol Scope that owns it.
Definition: database.hh:802
Address::getSpace
AddrSpace * getSpace(void) const
Get the address space.
Definition: address.hh:294
SymbolEntry::restoreXml
List::const_iterator restoreXml(List::const_iterator iter, const AddrSpaceManager *manage)
Restore this from an XML stream.
Definition: database.cc:195
Database::resolveScope
Scope * resolveScope(uint8 id) const
Look-up a Scope by id.
Definition: database.cc:2989
ScopeInternal::findAddr
virtual SymbolEntry * findAddr(const Address &addr, const Address &usepoint) const
Find a Symbol at a given address and usepoint.
Definition: database.cc:2125
RangeList::printBounds
void printBounds(ostream &s) const
Print a description of this RangeList to stream.
Definition: address.cc:522
SymbolNameTree
set< Symbol *, SymbolCompareName > SymbolNameTree
A set of Symbol objects sorted by name.
Definition: database.hh:324
Scope::addExternalRef
ExternRefSymbol * addExternalRef(const Address &addr, const Address &refaddr, const string &nm)
Definition: database.cc:1602
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Database::addRange
void addRange(Scope *scope, AddrSpace *spc, uintb first, uintb last)
Add an address range to the ownership of a Scope.
Definition: database.cc:2947
ScopeInternal::assignDefaultNames
void assignDefaultNames(int4 &base)
Assign a default name (via buildVariableName) to any unnamed symbol.
Definition: database.cc:2747
Symbol::restoreXml
virtual void restoreXml(const Element *el)
Restore this Symbol from an XML stream.
Definition: database.cc:529
ScopeMapper::subsorttype
NullSubsort subsorttype
The sub-sort object for a rangemap.
Definition: database.hh:814
SymbolEntry::EntrySubsort::EntrySubsort
EntrySubsort(bool val)
Given a boolean value, construct the earliest/latest possible sub-sort.
Definition: database.hh:95
Funcdata
Container for data structures associated with a single function.
Definition: funcdata.hh:45
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
Scope::inScope
virtual bool inScope(const Address &addr, int4 size, const Address &usepoint) const
Query if the given range is owned by this Scope.
Definition: database.hh:535
ScopeInternal::maptable
vector< EntryMap * > maptable
Rangemaps of SymbolEntry, one map for each address space.
Definition: database.hh:738
ScopeInternal::setAttribute
virtual void setAttribute(Symbol *sym, uint4 attr)
Set boolean Varnode properties on a Symbol.
Definition: database.cc:2103
Symbol::merge_problems
@ merge_problems
Set if some SymbolEntrys did not get merged.
Definition: database.hh:186
Symbol::saveXmlBody
void saveXmlBody(ostream &s) const
Save details of the Symbol to XML.
Definition: database.cc:502
ScopeInternal::buildSubScope
virtual Scope * buildSubScope(uint8 id, const string &nm)
Build an unattached Scope to be associated as a sub-scope of this.
Definition: database.cc:1719
AddrSpace::getIndex
int4 getIndex(void) const
Get the integer identifier.
Definition: space.hh:319
Scope::getCategorySize
virtual int4 getCategorySize(int4 cat) const =0
Get the number of Symbols in the given category.
MapIterator::operator!=
bool operator!=(const MapIterator &op2) const
Inequality operator.
Definition: database.hh:372
Scope::buildVariableName
virtual string buildVariableName(const Address &addr, const Address &pc, Datatype *ct, int4 &index, uint4 flags) const =0
Given an address and data-type, build a suitable generic symbol name.
Varnode::precishi
@ precishi
Is this Varnode the high part of a double precision value.
Definition: varnode.hh:102
SymbolEntry::linetype
uintb linetype
The linear element for a rangemap of SymbolEntry.
Definition: database.hh:111
Scope::~Scope
virtual ~Scope(void)
Destructor.
Definition: database.cc:1143
Database
A manager for symbol scopes for a whole executable.
Definition: database.hh:844
Symbol::category
int2 category
Special category (-1==none 0=parameter 1=equate)
Definition: database.hh:165
Scope::findOverlap
virtual SymbolEntry * findOverlap(const Address &addr, int4 size) const =0
Find first Symbol overlapping the given memory range.
Database::removeRange
void removeRange(Scope *scope, AddrSpace *spc, uintb first, uintb last)
Remove an address range from ownership of a Scope.
Definition: database.cc:2961
FunctionSymbol::FunctionSymbol
FunctionSymbol(Scope *sc, const string &nm, int4 size)
Construct given the name.
Definition: database.cc:570
Symbol::force_oct
@ force_oct
Force octal printing of constant symbol.
Definition: database.hh:181
Varnode::precislo
@ precislo
Is this Varnode the low part of a double precision value.
Definition: varnode.hh:101
ScopeInternal::retypeSymbol
virtual void retypeSymbol(Symbol *sym, Datatype *ct)
Change the data-type of a Symbol within this Scope.
Definition: database.cc:2071
SymbolEntry::subsorttype
EntrySubsort subsorttype
The sub-sort object for a rangemap.
Definition: database.hh:112
SymbolEntry::updateType
bool updateType(Varnode *vn) const
Update a Varnode data-type from this.
Definition: database.cc:111
Database::resolveScopeFromSymbolName
Scope * resolveScopeFromSymbolName(const string &fullname, const string &delim, string &basename, Scope *start) const
Get the Scope (and base name) associated with a qualified Symbol name.
Definition: database.cc:3010
ExternRefSymbol::saveXml
virtual void saveXml(ostream &s) const
Save this Symbol to an XML stream.
Definition: database.cc:759
Scope::addSymbolInternal
virtual void addSymbolInternal(Symbol *sym)=0
Put a Symbol into the name map.
Database::deleteSubScopes
void deleteSubScopes(Scope *scope)
Delete all sub-scopes of the given Scope.
Definition: database.cc:2900
Symbol::setIsolated
void setIsolated(bool val)
Set whether this Symbol should be speculatively merged.
Definition: database.cc:248
Scope::addDynamicSymbol
Symbol * addDynamicSymbol(const string &nm, Datatype *ct, const Address &caddr, uint8 hash)
Create a dynamically mapped Symbol attached to a specific data-flow.
Definition: database.cc:1650
FunctionSymbol
A Symbol representing an executable function.
Definition: database.hh:251
Database::restoreXml
void restoreXml(const Element *el)
Recover the whole database from XML.
Definition: database.cc:3182
Scope::removeRange
virtual void removeRange(AddrSpace *spc, uintb first, uintb last)
Remove a memory range from the ownership of this Scope.
Definition: database.cc:1075
Symbol::symbolId
uint8 symbolId
Unique id, 0=unassigned.
Definition: database.hh:167
Scope::setDisplayFormat
virtual void setDisplayFormat(Symbol *sym, uint4 attr)=0
Set the display format for a Symbol.
SymbolEntry::EntrySubsort::operator<
bool operator<(const EntrySubsort &op2)
Compare this with another sub-sort.
Definition: database.hh:105
Symbol::force_bin
@ force_bin
Force binary printing of constant symbol.
Definition: database.hh:182
ScopeInternal::begin
virtual MapIterator begin(void) const
Beginning iterator to mapped SymbolEntrys.
Definition: database.cc:1802
Scope::endDynamic
virtual list< SymbolEntry >::const_iterator endDynamic(void) const =0
Ending iterator to dynamic SymbolEntrys.
Range
A contiguous range of bytes in some address space.
Definition: address.hh:161
LabSymbol
A Symbol that labels code internal to a function.
Definition: database.hh:281
Scope::clearCategory
virtual void clearCategory(int4 cat)=0
Clear all symbols of the given category from this scope.
Symbol::getResolutionDepth
int4 getResolutionDepth(const Scope *useScope) const
Get number of scope names needed to resolve this symbol.
Definition: database.cc:316
Symbol::saveXmlHeader
void saveXmlHeader(ostream &s) const
Save basic Symbol properties as XML attributes.
Definition: database.cc:356
Symbol::getMapEntry
SymbolEntry * getMapEntry(const Address &addr) const
Get first mapping of the symbol that contains the given Address.
Definition: database.cc:273
Symbol::ID_BASE
static uint8 ID_BASE
Base of internal ID's.
Definition: database.hh:225
Scope::findAddr
virtual SymbolEntry * findAddr(const Address &addr, const Address &usepoint) const =0
Find a Symbol at a given address and usepoint.
ScopeInternal::resolveExternalRefFunction
virtual Funcdata * resolveExternalRefFunction(ExternRefSymbol *sym) const
Convert an external reference to the referenced function.
Definition: database.cc:2263
Scope::printEntries
virtual void printEntries(ostream &s) const =0
Dump a description of all SymbolEntry objects to a stream.
ScopeInternal::makeNameUnique
virtual string makeNameUnique(const string &nm) const
Produce a version of the given symbol name that won't collide with other names in this Scope.
Definition: database.cc:2454
SymbolEntry::isAddrTied
bool isAddrTied(void) const
Is this storage address tied.
Definition: database.hh:243
ScopeInternal::clearAttribute
virtual void clearAttribute(Symbol *sym, uint4 attr)
Clear boolean Varnode properties on a Symbol.
Definition: database.cc:2111
Scope::name
string name
Name of this scope.
Definition: database.hh:414
Scope::addDynamicMapInternal
virtual SymbolEntry * addDynamicMapInternal(Symbol *sym, uint4 exfl, uint8 hash, int4 off, int4 sz, const RangeList &uselim)=0
Create a new SymbolEntry for a Symbol given a dynamic hash.
Scope::stackFunction
static const Scope * stackFunction(const Scope *scope1, const Scope *scope2, const Address &addr, Funcdata **addrmatch)
Definition: database.cc:970
ScopeInternal::removeSymbol
virtual void removeSymbol(Symbol *symbol)
Remove the given Symbol from this Scope.
Definition: database.cc:2044
Symbol::checkSizeTypeLock
void checkSizeTypeLock(void)
Calculate if size_typelock property is on.
Definition: database.cc:219
ScopeInternal::isNameUsed
virtual bool isNameUsed(const string &nm, const Scope *op2) const
Check if the given name is occurs within the given scope path.
Definition: database.cc:2318
Database::deleteScope
void deleteScope(Scope *scope)
Delete the given Scope and all its sub-scopes.
Definition: database.cc:2882
ScopeInternal::setCategory
virtual void setCategory(Symbol *sym, int4 cat, int4 ind)
Set the category and index for the given Symbol.
Definition: database.cc:2723
Symbol::setThisPointer
void setThisPointer(bool val)
Toggle whether this is the "this" pointer for a class method.
Definition: database.cc:228
SymbolCompareName::operator()
bool operator()(const Symbol *sym1, const Symbol *sym2) const
Compare two Symbol pointers.
Definition: database.hh:317
SymbolEntry::EntrySubsort
Class for sub-sorting different SymbolEntry objects at the same address.
Definition: database.hh:83
Scope::saveXmlRecursive
void saveXmlRecursive(ostream &s, bool onlyGlobal) const
Save all contained scopes as an XML stream.
Definition: database.cc:1332
Scope::removeSymbol
virtual void removeSymbol(Symbol *symbol)=0
Remove the given Symbol from this Scope.
ScopeInternal::findContainer
virtual SymbolEntry * findContainer(const Address &addr, int4 size, const Address &usepoint) const
Find the smallest Symbol containing the given memory range.
Definition: database.cc:2151
Scope::saveXml
virtual void saveXml(ostream &s) const =0
Write out this as a <scope> XML tag.
ScopeInternal::addMapInternal
virtual SymbolEntry * addMapInternal(Symbol *sym, uint4 exfl, const Address &addr, int4 off, int4 sz, const RangeList &uselim)
Create a new SymbolEntry for a Symbol given a memory range.
Definition: database.cc:1756
Symbol::getBytesConsumed
virtual int4 getBytesConsumed(void) const
Get number of bytes consumed within the address->symbol map.
Definition: database.cc:544
Scope::findContainer
virtual SymbolEntry * findContainer(const Address &addr, int4 size, const Address &usepoint) const =0
Find the smallest Symbol containing the given memory range.
Symbol::mapentry
vector< list< SymbolEntry >::iterator > mapentry
List of storage locations labeled with this Symbol.
Definition: database.hh:168
ScopeInternal::clear
virtual void clear(void)
Clear all symbols from this scope.
Definition: database.cc:1890
Symbol::getFirstWholeMap
SymbolEntry * getFirstWholeMap(void) const
Get the first entire mapping of the symbol.
Definition: database.cc:261
Symbol::size_typelock
@ size_typelock
Only the size of the symbol is typelocked.
Definition: database.hh:184
Scope::uniqueId
uint8 uniqueId
Unique id for the scope, for deduping scope names, assigning symbol ids.
Definition: database.hh:416
ScopeInternal::buildVariableName
virtual string buildVariableName(const Address &addr, const Address &pc, Datatype *ct, int4 &index, uint4 flags) const
Given an address and data-type, build a suitable generic symbol name.
Definition: database.cc:2335
ScopeInternal::findCodeLabel
virtual LabSymbol * findCodeLabel(const Address &addr) const
Find a label Symbol at the given address.
Definition: database.cc:2269
Scope::renameSymbol
virtual void renameSymbol(Symbol *sym, const string &newname)=0
Rename a Symbol within this Scope.
Database::findCreateScope
Scope * findCreateScope(uint8, const string &nm, Scope *parent)
Definition: database.cc:2975
partmap< Address, uint4 >
Database::attachScope
void attachScope(Scope *newscope, Scope *parent)
Register a new Scope.
Definition: database.cc:2843
LabSymbol::saveXml
virtual void saveXml(ostream &s) const
Save this Symbol to an XML stream.
Definition: database.cc:718
ScopeInternal::buildUndefinedName
virtual string buildUndefinedName(void) const
Build a formal undefined name, used internally when a Symbol is not given a name.
Definition: database.cc:2421
AddrSpaceManager
A manager for different address spaces.
Definition: translate.hh:218
Symbol::catindex
uint2 catindex
Index within category.
Definition: database.hh:166
Symbol::saveXml
virtual void saveXml(ostream &s) const
Save this Symbol to an XML stream.
Definition: database.cc:518
Scope::stackContainer
static const Scope * stackContainer(const Scope *scope1, const Scope *scope2, const Address &addr, int4 size, const Address &usepoint, SymbolEntry **addrmatch)
Definition: database.cc:904
EquateSymbol::saveXml
virtual void saveXml(ostream &s) const
Save this Symbol to an XML stream.
Definition: database.cc:668
EntryMap
rangemap< SymbolEntry > EntryMap
A rangemap of SymbolEntry.
Definition: database.hh:140
FunctionSymbol::getFunction
Funcdata * getFunction(void)
Get the underlying Funcdata object.
Definition: database.cc:592
ScopeInternal::clearUnlocked
virtual void clearUnlocked(void)
Clear all unlocked symbols from this scope.
Definition: database.cc:1955
SymbolEntry::saveXml
void saveXml(ostream &s) const
Save this to an XML stream.
Definition: database.cc:176
Scope::retypeSymbol
virtual void retypeSymbol(Symbol *sym, Datatype *ct)=0
Change the data-type of a Symbol within this Scope.
ScopeInternal::clearUnlockedCategory
virtual void clearUnlockedCategory(int4 cat)
Clear unlocked symbols of the given category from this scope.
Definition: database.cc:1977
Symbol::type
Datatype * type
The symbol's data-type.
Definition: database.hh:159
ScopeInternal::categorySanity
virtual void categorySanity(void)
Make sure Symbol categories are sane.
Definition: database.cc:1905
Symbol::restoreXmlHeader
void restoreXmlHeader(const Element *el)
Restore basic Symbol properties from XML.
Definition: database.cc:399
Symbol
The base class for a symbol in a symbol table or scope.
Definition: database.hh:152
SymbolCompareName
Comparator for sorting Symbol objects by name.
Definition: database.hh:309
Symbol::getMapEntryPosition
int4 getMapEntryPosition(const SymbolEntry *entry) const
Position of given SymbolEntry within this multi-entry Symbol.
Definition: database.cc:294
Scope::findFunction
virtual Funcdata * findFunction(const Address &addr) const =0
Find the function starting at the given address.
Scope::buildSubScope
virtual Scope * buildSubScope(uint8 id, const string &nm)=0
Build an unattached Scope to be associated as a sub-scope of this.
Varnode::indirectstorage
@ indirectstorage
Is this Varnode storing a pointer to the actual symbol.
Definition: varnode.hh:103
ScopeInternal::removeSymbolMappings
virtual void removeSymbolMappings(Symbol *symbol)
Remove all SymbolEntrys from the given Symbol.
Definition: database.cc:2023
Database::saveXml
void saveXml(ostream &s) const
Save the whole Database to an XML stream.
Definition: database.cc:3136
FunctionSymbol::restoreXml
virtual void restoreXml(const Element *el)
Restore this Symbol from an XML stream.
Definition: database.cc:615
Scope::queryProperties
SymbolEntry * queryProperties(const Address &addr, int4 size, const Address &usepoint, uint4 &flags) const
Find a Symbol or properties at the given address.
Definition: database.cc:1224
rangemap.hh
Templates to define interval map containers.
MapIterator::operator=
MapIterator & operator=(const MapIterator &op2)
Assignment operator.
Definition: database.hh:357
Varnode::addrtied
@ addrtied
High-level variable is tied to address.
Definition: varnode.hh:90
Scope::resetSizeLockType
void resetSizeLockType(Symbol *sym)
Clear a Symbol's size-locked data-type.
Definition: database.cc:1363