decompiler
1.0.0
|
A manager for symbol scopes for a whole executable. More...
#include <database.hh>
Public Member Functions | |
Database (Architecture *g) | |
Constructor. | |
~Database (void) | |
Destructor. | |
Architecture * | getArch (void) const |
Get the Architecture associate with this. | |
void | attachScope (Scope *newscope, Scope *parent) |
Register a new Scope. More... | |
void | deleteScope (Scope *scope) |
Delete the given Scope and all its sub-scopes. More... | |
void | deleteSubScopes (Scope *scope) |
Delete all sub-scopes of the given Scope. More... | |
void | clearUnlocked (Scope *scope) |
Clear unlocked Symbols owned by the given Scope. More... | |
void | setRange (Scope *scope, const RangeList &rlist) |
Set the ownership range for a Scope. More... | |
void | addRange (Scope *scope, AddrSpace *spc, uintb first, uintb last) |
Add an address range to the ownership of a Scope. More... | |
void | removeRange (Scope *scope, AddrSpace *spc, uintb first, uintb last) |
Remove an address range from ownership of a Scope. More... | |
Scope * | getGlobalScope (void) const |
Get the global Scope. | |
Scope * | resolveScope (const vector< string > &subnames) const |
Look-up a Scope by name. More... | |
Scope * | resolveScopeSymbolName (const string &fullname, const string &delim, string &basename, Scope *start) const |
Get the Scope (and base name) associated with a qualified Symbol name. More... | |
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. More... | |
Scope * | mapScope (Scope *qpoint, const Address &addr, const Address &usepoint) |
A non-constant version of mapScope() More... | |
uint4 | getProperty (const Address &addr) const |
Get boolean properties at the given address. | |
void | setPropertyRange (uint4 flags, const Range &range) |
Set boolean properties over a given memory range. More... | |
void | setProperties (const partmap< Address, uint4 > &newflags) |
Replace the property map. | |
const partmap< Address, uint4 > & | getProperties (void) const |
Get the entire property map. | |
void | saveXml (ostream &s) const |
Save the whole Database to an XML stream. More... | |
void | restoreXml (const Element *el) |
Recover the whole database from XML. More... | |
void | restoreXmlScope (const Element *el, Scope *new_scope) |
Register and fill out a single Scope from XML. More... | |
Private Member Functions | |
void | clearResolve (Scope *scope) |
Clear the ownership ranges associated with the given Scope. More... | |
void | clearResolveRecursive (Scope *scope) |
Clear the ownership ranges of a given Scope and its children. More... | |
void | fillResolve (Scope *scope) |
Add the ownership ranges of the given Scope to the map. More... | |
Static Private Member Functions | |
static void | parseParentTag (const Element *el, string &name, vector< string > &parnames) |
Read an XML <parent> tag for a Scope path. More... | |
Private Attributes | |
Architecture * | glb |
The Architecture to which this symbol table is attached. | |
Scope * | globalscope |
A quick reference to the global Scope. | |
ScopeResolve | resolvemap |
The Address to namespace map. | |
partmap< Address, uint4 > | flagbase |
Map of global properties. | |
A manager for symbol scopes for a whole executable.
This is the highest level container for anything related to Scope and Symbol objects, it indirectly holds the Funcdata objects as well, through the FunctionSymbol. It acts as the formal symbol table for the decompiler. The API is mostly concerned with the management of Scope objects.
A Scope object is initially registered via attachScope(), then it can looked up by name. This class maintains the cross Scope search by address capability, implemented as a map from an Address to the Scope that owns it. For efficiency, this map is really only applied to namespace Scopes, the global Scope and function Scopes are not entered in the map. This class also maintains a set of boolean properties that label memory ranges. This allows important properties like read-only and volatile to be put down even if the Symbols aren't yet known.
Add an address range to the ownership of a Scope.
The new range will be merged with the existing ownership. The address to Scope map is updated
scope | is the given Scope |
spc | is the address space of the memory range being added |
first | is the offset of the first byte in the array |
last | is the offset of the last byte |
References Scope::addRange(), clearResolve(), and fillResolve().
Referenced by ScopeGhidraNamespace::addMapInternal(), Architecture::globalify(), Architecture::parseGlobal(), and ScopeInternal::restoreXml().
Register a new Scope.
The new Scope must be initially empty and this Database takes over ownership. Practically, this is just setting up the new Scope as a sub-scope of its parent. The parent Scope should already be registered with this Database, or NULL can be passed to register the global Scope.
References Scope::attachScope(), globalscope, and Scope::name.
Referenced by ArchitectureGhidra::buildGlobalScope(), Architecture::buildGlobalScope(), ScopeGhidra::createNewScope(), Funcdata::Funcdata(), restoreXml(), and restoreXmlScope().
|
private |
Clear the ownership ranges associated with the given Scope.
Check to make sure the Scope is a namespace then remove all its address ranges from the map.
scope | is the given Scope |
References RangeList::begin(), RangeList::end(), Scope::fd, Range::getFirstAddr(), globalscope, Scope::rangetree, and resolvemap.
Referenced by addRange(), clearResolveRecursive(), removeRange(), and setRange().
|
private |
Clear the ownership ranges of a given Scope and its children.
This recursively performs clearResolve() on the Scope and any sub-scopes
scope | is the given Scope to clear |
References Scope::children, and clearResolve().
Referenced by deleteScope(), and deleteSubScopes().
void Database::clearUnlocked | ( | Scope * | scope | ) |
Clear unlocked Symbols owned by the given Scope.
All unlocked symbols in this Scope, and recursively into its sub-scopes, are removed.
scope | is the given Scope |
References Scope::children, and Scope::clearUnlocked().
void Database::deleteScope | ( | Scope * | scope | ) |
Delete the given Scope and all its sub-scopes.
scope | is the given Scope |
References Scope::children, clearResolveRecursive(), Scope::dedupId, Scope::detachScope(), globalscope, Scope::name, and Scope::parent.
Referenced by ~Database(), and Funcdata::~Funcdata().
void Database::deleteSubScopes | ( | Scope * | scope | ) |
Delete all sub-scopes of the given Scope.
The given Scope is not deleted, only its children.
scope | is the given Scope |
References Scope::children, clearResolveRecursive(), and Scope::detachScope().
Referenced by FlushNative::rawAction().
|
private |
Add the ownership ranges of the given Scope to the map.
If the Scope is a namespace, iterate through all its ranges, adding each to the map
scope | is the given Scope to add |
References RangeList::begin(), RangeList::end(), Scope::fd, Range::getFirstAddr(), Range::getLastAddr(), globalscope, Scope::rangetree, and resolvemap.
Referenced by addRange(), removeRange(), and setRange().
const Scope * Database::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.
As currently implemented, this method can only find a namespace Scope. When searching for a Symbol by Address, the global Scope is always searched because it is the terminating Scope when recursively walking scopes through the parent relationship, so it isn't entered in this map. A function level Scope, also not entered in the map, is only returned as the Scope passed in as a default, when no namespace Scope claims the address.
qpoint | is the default Scope returned if no owner is found |
addr | is the address whose owner should be searched for |
usepoint | is a point in code where the address is being accessed (may be invalid) |
References resolvemap.
Referenced by Scope::discoverScope(), Scope::queryByAddr(), Scope::queryCodeLabel(), Scope::queryContainer(), Scope::queryExternalRefFunction(), Scope::queryFunction(), Scope::queryProperties(), and ScopeGhidra::resolveExternalRefFunction().
A non-constant version of mapScope()
qpoint | is the default Scope returned if no owner is found |
addr | is the address whose owner should be searched for |
usepoint | is a point in code where the address is being accessed (may be invalid) |
References resolvemap.
|
staticprivate |
Read an XML <parent> tag for a Scope path.
The <parent> tag is assumed to either be the first child of the given element, or the first child of the first child. From the <parent>, the name attribute is passed back and a Scope path is parsed from sub-tags.
el | is the given element (with <parent> as a child) |
name | will hold the name attribute |
parnames | will hold the Scope path |
References ScopeInternal::restorePathXml().
Referenced by restoreXml(), and restoreXmlScope().
Remove an address range from ownership of a Scope.
Addresses owned by the Scope that are disjoint from the given range are not affected.
scope | is the given Scope |
spc | is the address space of the memory range being removed |
first | is the offset of the first byte in the array |
last | is the offset of the last byte |
References clearResolve(), fillResolve(), and Scope::removeRange().
Scope * Database::resolveScope | ( | const vector< string > & | subnames | ) | const |
Look-up a Scope by name.
An absolute path of Scope names must be provided, from the global Scope down to the desired Scope. If the first path name is blank (""), it matches the global Scope. If the first path name is not blank, the global Scope is assumed, and the name is assumed to refer to a child.
subnames | is the path of names |
References globalscope, and Scope::resolveScope().
Referenced by restoreXml(), and restoreXmlScope().
Scope * Database::resolveScopeSymbolName | ( | const string & | fullname, |
const string & | delim, | ||
string & | basename, | ||
Scope * | start | ||
) | const |
Get the Scope (and base name) associated with a qualified Symbol name.
The name is parsed using a delimiter that is passed in. The name can be only partially qualified by passing in a starting Scope, which the name is assumed to be relative to. Otherwise the name is assumed to be relative to the global Scope. The unqualified (base) name of the Symbol is passed back to the caller.
fullname | is the qualified Symbol name |
delim | is the delimiter separating names |
basename | will hold the passed back base Symbol name |
start | is the Scope to start drilling down from, or NULL for the global scope |
References globalscope, and Scope::resolveScope().
void Database::restoreXml | ( | const Element * | el | ) |
Recover the whole database from XML.
The children of a <db> tag are examined to recover Scope and Symbol objects.
el | is the <db> element |
References attachScope(), flagbase, glb, globalscope, parseParentTag(), Scope::resolveScope(), resolveScope(), Address::restoreXml(), Scope::restoreXml(), and partmap< _linetype, _valuetype >::split().
Referenced by Architecture::restoreXml().
Register and fill out a single Scope from XML.
This allows incremental building of the Database from multiple XML sources. An empty Scope must already be allocated. It is registered with this Database, and then populated with Symbol objects based as the content of a given <scope> tag.
el | is the given <scope> element |
new_scope | is the empty Scope |
References attachScope(), Scope::name, parseParentTag(), resolveScope(), and Scope::restoreXml().
void Database::saveXml | ( | ostream & | s | ) | const |
Save the whole Database to an XML stream.
This writes a single <db> tag to the stream, which contains sub-tags for each Scope (which contain Symbol sub-tags in turn).
s | is the output stream |
References partmap< _linetype, _valuetype >::begin(), partmap< _linetype, _valuetype >::end(), flagbase, Address::getOffset(), Address::getSpace(), globalscope, AddrSpace::saveXmlAttributes(), and Scope::saveXmlRecursive().
Referenced by Architecture::saveXml().
void Database::setPropertyRange | ( | uint4 | flags, |
const Range & | range | ||
) |
Set boolean properties over a given memory range.
This allows the standard boolean Varnode properties like read-only and volatile to be put an a memory range, independent of whether a Symbol is there or not. These get picked up by the Scope::queryProperties() method in particular.
flags | is the set of boolean properties |
range | is the memory range to label |
References partmap< _linetype, _valuetype >::begin(), partmap< _linetype, _valuetype >::end(), flagbase, Range::getFirstAddr(), Range::getLastAddrOpen(), glb, Address::isInvalid(), and partmap< _linetype, _valuetype >::split().
Referenced by ScopeGhidra::dump2Cache(), Architecture::fillinReadOnlyFromLoader(), Architecture::parseIncidentalCopy(), Architecture::parseReadOnly(), Architecture::parseVolatile(), ScopeGhidra::processHole(), and ScopeInternal::processHole().
Set the ownership range for a Scope.
Any existing ownership is completely replaced. The address to Scope map is updated.
scope | is the given Scope |
rlist | is the set of addresses to mark as owned |
References clearResolve(), fillResolve(), and Scope::rangetree.
Referenced by ScopeInternal::restoreXml().