My Project
database_ghidra.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 __DATABASE_GHIDRA__
20 #define __DATABASE_GHIDRA__
21 
22 #include "database.hh"
23 #include "ghidra_arch.hh"
24 
35 class ScopeGhidra : public Scope {
36  ArchitectureGhidra *ghidra;
37  mutable ScopeInternal *cache;
38  mutable RangeList holes;
39  vector<int4> spacerange;
40  partmap<Address,uint4> flagbaseDefault;
41  mutable bool cacheDirty;
42  Symbol *dump2Cache(Document *doc) const;
43  Symbol *removeQuery(const Address &addr) const;
44  void processHole(const Element *el) const;
45  Scope *createNewScope(const string &nm,Scope *par) const;
46  Scope *reresolveScope(const vector<string> &path) const;
47  virtual void addRange(AddrSpace *spc,uintb first,uintb last);
48  virtual void removeRange(AddrSpace *spc,uintb first,uintb last) {
49  throw LowlevelError("remove_range should not be performed on ghidra scope");
50  }
51  virtual void addSymbolInternal(Symbol *sym) { throw LowlevelError("add_symbol_internal unimplemented"); }
52  virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,
53  const RangeList &uselim) { throw LowlevelError("addMap unimplemented"); }
54  virtual SymbolEntry *addDynamicMapInternal(Symbol *sym,uint4 exfl,uint8 hash,int4 off,int4 sz,
55  const RangeList &uselim) { throw LowlevelError("addMap unimplemented"); }
56 public:
58 
65  void lockDefaultProperties(void) { flagbaseDefault = ghidra->symboltab->getProperties(); cacheDirty = false; }
66  virtual ~ScopeGhidra(void);
67  virtual void clear(void);
68  virtual SymbolEntry *addSymbol(const string &name,Datatype *ct,
69  const Address &addr,const Address &usepoint);
70  virtual string buildVariableName(const Address &addr,
71  const Address &pc,
72  Datatype *ct,int4 &index,uint4 flags) const {
73  return cache->buildVariableName(addr,pc,ct,index,flags); }
74  virtual string buildUndefinedName(void) const { return cache->buildUndefinedName(); }
75  virtual void setAttribute(Symbol *sym,uint4 attr) { cache->setAttribute(sym,attr); }
76  virtual void clearAttribute(Symbol *sym,uint4 attr) { cache->clearAttribute(sym,attr); }
77  virtual void setDisplayFormat(Symbol *sym,uint4 attr) { cache->setDisplayFormat(sym,attr); }
78 
79  virtual SymbolEntry *findAddr(const Address &addr,const Address &usepoint) const;
80  virtual SymbolEntry *findContainer(const Address &addr,int4 size,
81  const Address &usepoint) const;
82  virtual SymbolEntry *findClosestFit(const Address &addr,int4 size,
83  const Address &usepoint) const {
84  throw LowlevelError("findClosestFit unimplemented"); }
85  virtual Funcdata *findFunction(const Address &addr) const;
86  virtual ExternRefSymbol *findExternalRef(const Address &addr) const;
87  virtual LabSymbol *findCodeLabel(const Address &addr) const;
89 
90  virtual SymbolEntry *findOverlap(const Address &addr,int4 size) const { throw LowlevelError("findOverlap unimplemented"); }
91  virtual void findByName(const string &name,vector<Symbol *> &res) const { throw LowlevelError("findByName unimplemented"); }
92  virtual bool isNameUsed(const string &name) const { throw LowlevelError("isNameUsed unimplemented"); }
93 
94  virtual MapIterator begin(void) const { throw LowlevelError("begin unimplemented"); }
95  virtual MapIterator end(void) const { throw LowlevelError("end unimplemented"); }
96  virtual list<SymbolEntry>::const_iterator beginDynamic(void) const { throw LowlevelError("beginDynamic unimplemented"); }
97  virtual list<SymbolEntry>::const_iterator endDynamic(void) const { throw LowlevelError("endDynamic unimplemented"); }
98  virtual list<SymbolEntry>::iterator beginDynamic(void) { throw LowlevelError("beginDynamic unimplemented"); }
99  virtual list<SymbolEntry>::iterator endDynamic(void) { throw LowlevelError("endDynamic unimplemented"); }
100  virtual void clearCategory(int4 cat) { throw LowlevelError("clearCategory unimplemented"); }
101  virtual void clearUnlockedCategory(int4 cat) { throw LowlevelError("clearUnlockedCategory unimplemented"); }
102  virtual void clearUnlocked(void) { throw LowlevelError("clearUnlocked unimplemented"); }
103  virtual void restrictScope(Funcdata *f) { throw LowlevelError("restrictScope unimplemented"); }
104  virtual void removeSymbolMappings(Symbol *symbol) { throw LowlevelError("removeSymbolMappings unimplemented"); }
105  virtual void removeSymbol(Symbol *symbol) { throw LowlevelError("removeSymbol unimplemented"); }
106  virtual void renameSymbol(Symbol *sym,const string &newname) { throw LowlevelError("renameSymbol unimplemented"); }
107  virtual void retypeSymbol(Symbol *sym,Datatype *ct) { throw LowlevelError("retypeSymbol unimplemented"); }
108  virtual string makeNameUnique(const string &nm) const { throw LowlevelError("makeNameUnique unimplemented"); }
109  virtual void saveXml(ostream &s) const { throw LowlevelError("saveXml unimplemented"); }
110  virtual void restoreXml(const Element *el) { throw LowlevelError("restoreXml unimplemented"); }
111  virtual void printEntries(ostream &s) const { throw LowlevelError("printEntries unimplemented"); }
112  virtual int4 getCategorySize(int4 cat) const { throw LowlevelError("getCategorySize unimplemented"); }
113  virtual Symbol *getCategorySymbol(int4 cat,int4 ind) const { throw LowlevelError("getCategorySymbol unimplemented"); }
114  virtual void setCategory(Symbol *sym,int4 cat,int4 ind) { throw LowlevelError("setCategory unimplemented"); }
115 };
116 
127  virtual SymbolEntry *addMapInternal(Symbol *sym,uint4 exfl,const Address &addr,int4 off,int4 sz,
128  const RangeList &uselim);
129 public:
130  ScopeGhidraNamespace(const string &nm,Architecture *g)
131  : ScopeInternal(nm,g) {}
132 };
133 
134 #endif
virtual Funcdata * resolveExternalRefFunction(ExternRefSymbol *sym) const
Convert an external reference to the referenced function.
Definition: database_ghidra.cc:358
A region where processor data is stored.
Definition: space.hh:73
virtual LabSymbol * findCodeLabel(const Address &addr) const
Find a label Symbol at the given address.
Definition: database_ghidra.cc:339
The base datatype class for the decompiler.
Definition: type.hh:62
virtual MapIterator begin(void) const
Beginning iterator to mapped SymbolEntrys.
Definition: database_ghidra.hh:94
A storage location for a particular Symbol.
Definition: database.hh:51
virtual list< SymbolEntry >::const_iterator beginDynamic(void) const
Beginning iterator to dynamic SymbolEntrys.
Definition: database_ghidra.hh:96
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_ghidra.hh:82
virtual list< SymbolEntry >::iterator beginDynamic(void)
Beginning iterator to dynamic SymbolEntrys.
Definition: database_ghidra.hh:98
virtual list< SymbolEntry >::const_iterator endDynamic(void) const
Ending iterator to dynamic SymbolEntrys.
Definition: database_ghidra.hh:97
Container for data structures associated with a single function.
Definition: funcdata.hh:45
virtual void clearCategory(int4 cat)
Clear all symbols of the given category from this scope.
Definition: database_ghidra.hh:100
A function Symbol referring to an external location.
Definition: database.hh:296
virtual void findByName(const string &name, vector< Symbol *> &res) const
Find a Symbol by name within this Scope.
Definition: database_ghidra.hh:91
virtual void setCategory(Symbol *sym, int4 cat, int4 ind)
Set the category and index for the given Symbol.
Definition: database_ghidra.hh:114
virtual void removeSymbolMappings(Symbol *symbol)
Remove all SymbolEntrys from the given Symbol.
Definition: database_ghidra.hh:104
ScopeGhidraNamespace(const string &nm, Architecture *g)
Constructor.
Definition: database_ghidra.hh:130
virtual void clearAttribute(Symbol *sym, uint4 attr)
Clear boolean Varnode properties on a Symbol.
Definition: database_ghidra.hh:76
virtual void setAttribute(Symbol *sym, uint4 attr)
Set boolean Varnode properties on a Symbol.
Definition: database.cc:2065
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_ghidra.cc:388
virtual SymbolEntry * findOverlap(const Address &addr, int4 size) const
Find first Symbol overlapping the given memory range.
Definition: database_ghidra.hh:90
A disjoint set of Ranges, possibly across multiple address spaces.
Definition: address.hh:203
virtual void printEntries(ostream &s) const
Dump a description of all SymbolEntry objects to a stream.
Definition: database_ghidra.hh:111
virtual SymbolEntry * findAddr(const Address &addr, const Address &usepoint) const
Find a Symbol at a given address and usepoint.
Definition: database_ghidra.cc:264
Database * symboltab
Memory map of global variables and functions.
Definition: architecture.hh:136
virtual void saveXml(ostream &s) const
Write out this as a <scope> XML tag.
Definition: database_ghidra.hh:109
An iterator over SymbolEntry objects in multiple address spaces.
Definition: database.hh:330
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:2289
virtual Funcdata * findFunction(const Address &addr) const
Find the function starting at the given address.
Definition: database_ghidra.cc:321
virtual void setDisplayFormat(Symbol *sym, uint4 attr)
Set the display format for a Symbol.
Definition: database.cc:2081
A Symbol that labels code internal to a function.
Definition: database.hh:281
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
virtual list< SymbolEntry >::iterator endDynamic(void)
Ending iterator to dynamic SymbolEntrys.
Definition: database_ghidra.hh:99
virtual void setDisplayFormat(Symbol *sym, uint4 attr)
Set the display format for a Symbol.
Definition: database_ghidra.hh:77
virtual string buildUndefinedName(void) const
Build a formal undefined name, used internally when a Symbol is not given a name. ...
Definition: database_ghidra.hh:74
ScopeGhidra(ArchitectureGhidra *g)
Constructor.
Definition: database_ghidra.cc:20
virtual void renameSymbol(Symbol *sym, const string &newname)
Rename a Symbol within this Scope.
Definition: database_ghidra.hh:106
virtual void clearUnlocked(void)
Clear all unlocked symbols from this scope.
Definition: database_ghidra.hh:102
virtual ExternRefSymbol * findExternalRef(const Address &addr) const
Find an external reference at the given address.
Definition: database_ghidra.cc:305
virtual int4 getCategorySize(int4 cat) const
Get the number of Symbols in the given category.
Definition: database_ghidra.hh:112
virtual void clearUnlockedCategory(int4 cat)
Clear unlocked symbols of the given category from this scope.
Definition: database_ghidra.hh:101
Manager for all the major decompiler subsystems.
Definition: architecture.hh:117
virtual void restoreXml(const Element *el)
Restore this Scope from a <scope> XML tag.
Definition: database_ghidra.hh:110
virtual void retypeSymbol(Symbol *sym, Datatype *ct)
Change the data-type of a Symbol within this Scope.
Definition: database_ghidra.hh:107
virtual void restrictScope(Funcdata *f)
Convert this to a local Scope.
Definition: database_ghidra.hh:103
The lowest level error generated by the decompiler.
Definition: error.hh:44
virtual bool isNameUsed(const string &name) const
Check if the given name is used within this scope.
Definition: database_ghidra.hh:92
virtual SymbolEntry * findContainer(const Address &addr, int4 size, const Address &usepoint) const
Find the smallest Symbol containing the given memory range.
Definition: database_ghidra.cc:284
string name
Name of this scope.
Definition: database.hh:425
An XML element. A node in the DOM tree.
Definition: xml.hh:150
A complete in-memory XML document.
Definition: xml.hh:206
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_ghidra.hh:70
virtual void clear(void)
Clear all symbols from this scope.
Definition: database_ghidra.cc:253
An in-memory implementation of the Scope interface.
Definition: database.hh:721
virtual MapIterator end(void) const
Ending iterator to mapped SymbolEntrys.
Definition: database_ghidra.hh:95
virtual void clearAttribute(Symbol *sym, uint4 attr)
Clear boolean Varnode properties on a Symbol.
Definition: database.cc:2073
Symbol and Scope objects for the decompiler.
virtual string makeNameUnique(const string &nm) const
Produce a version of the given symbol name that won&#39;t collide with other names in this Scope...
Definition: database_ghidra.hh:108
The base class for a symbol in a symbol table or scope.
Definition: database.hh:153
An implementation of the Scope interface by querying a Ghidra client for Symbol information.
Definition: database_ghidra.hh:35
Ghidra specific architecture information and connection to a Ghidra client.
virtual void setAttribute(Symbol *sym, uint4 attr)
Set boolean Varnode properties on a Symbol.
Definition: database_ghidra.hh:75
virtual Symbol * getCategorySymbol(int4 cat, int4 ind) const
Retrieve a Symbol by index within a specific category.
Definition: database_ghidra.hh:113
An implementation of the Architecture interface and connection to a Ghidra client.
Definition: ghidra_arch.hh:60
A global namespace Scope.
Definition: database_ghidra.hh:126
virtual void removeSymbol(Symbol *symbol)
Remove the given Symbol from this Scope.
Definition: database_ghidra.hh:105
virtual string buildUndefinedName(void) const
Build a formal undefined name, used internally when a Symbol is not given a name. ...
Definition: database.cc:2375
const partmap< Address, uint4 > & getProperties(void) const
Get the entire property map.
Definition: database.hh:867
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:413
void lockDefaultProperties(void)
Lock in the default state of the boolean property map.
Definition: database_ghidra.hh:65