decompiler
1.0.0
|
A collection of Symbol objects within a single (namespace or functional) scope. More...
#include <database.hh>
Public Member Functions | |
Scope (uint8 id, const string &nm, Architecture *g, Scope *own) | |
Construct an empty scope, given a name and Architecture. | |
virtual | ~Scope (void) |
Destructor. | |
virtual MapIterator | begin (void) const =0 |
Beginning iterator to mapped SymbolEntrys. | |
virtual MapIterator | end (void) const =0 |
Ending iterator to mapped SymbolEntrys. | |
virtual list< SymbolEntry >::const_iterator | beginDynamic (void) const =0 |
Beginning iterator to dynamic SymbolEntrys. | |
virtual list< SymbolEntry >::const_iterator | endDynamic (void) const =0 |
Ending iterator to dynamic SymbolEntrys. | |
virtual list< SymbolEntry >::iterator | beginDynamic (void)=0 |
Beginning iterator to dynamic SymbolEntrys. | |
virtual list< SymbolEntry >::iterator | endDynamic (void)=0 |
Ending iterator to dynamic SymbolEntrys. | |
virtual void | clear (void)=0 |
Clear all symbols from this scope. | |
virtual void | clearCategory (int4 cat)=0 |
Clear all symbols of the given category from this scope. | |
virtual void | clearUnlocked (void)=0 |
Clear all unlocked symbols from this scope. | |
virtual void | clearUnlockedCategory (int4 cat)=0 |
Clear unlocked symbols of the given category from this scope. | |
virtual void | adjustCaches (void)=0 |
Let scopes internally adjust any caches. More... | |
virtual bool | inScope (const Address &addr, int4 size, const Address &usepoint) const |
Query if the given range is owned by this Scope. More... | |
virtual void | removeSymbolMappings (Symbol *symbol)=0 |
Remove all SymbolEntrys from the given Symbol. | |
virtual void | removeSymbol (Symbol *symbol)=0 |
Remove the given Symbol from this Scope. | |
virtual void | renameSymbol (Symbol *sym, const string &newname)=0 |
Rename a Symbol within this Scope. | |
virtual void | retypeSymbol (Symbol *sym, Datatype *ct)=0 |
Change the data-type of a Symbol within this Scope. More... | |
virtual void | setAttribute (Symbol *sym, uint4 attr)=0 |
Set boolean Varnode properties on a Symbol. | |
virtual void | clearAttribute (Symbol *sym, uint4 attr)=0 |
Clear boolean Varnode properties on a Symbol. | |
virtual void | setDisplayFormat (Symbol *sym, uint4 attr)=0 |
Set the display format for a Symbol. | |
virtual SymbolEntry * | findAddr (const Address &addr, const Address &usepoint) const =0 |
Find a Symbol at a given address and usepoint. More... | |
virtual SymbolEntry * | findContainer (const Address &addr, int4 size, const Address &usepoint) const =0 |
Find the smallest Symbol containing the given memory range. More... | |
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. More... | |
virtual Funcdata * | findFunction (const Address &addr) const =0 |
Find the function starting at the given address. More... | |
virtual ExternRefSymbol * | findExternalRef (const Address &addr) const =0 |
Find an external reference at the given address. More... | |
virtual LabSymbol * | findCodeLabel (const Address &addr) const =0 |
Find a label Symbol at the given address. More... | |
virtual SymbolEntry * | findOverlap (const Address &addr, int4 size) const =0 |
Find first Symbol overlapping the given memory range. More... | |
virtual void | findByName (const string &name, vector< Symbol * > &res) const =0 |
Find a Symbol by name within this Scope. More... | |
virtual bool | isNameUsed (const string &nm, const Scope *op2) const =0 |
Check if the given name is occurs within the given scope path. More... | |
virtual Funcdata * | resolveExternalRefFunction (ExternRefSymbol *sym) const =0 |
Convert an external reference to the referenced function. More... | |
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. More... | |
virtual string | buildUndefinedName (void) const =0 |
Build a formal undefined name, used internally when a Symbol is not given a name. More... | |
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. More... | |
virtual void | saveXml (ostream &s) const =0 |
Write out this as a <scope> XML tag. | |
virtual void | restoreXml (const Element *el)=0 |
Restore this Scope from a <scope> XML tag. | |
virtual void | printEntries (ostream &s) const =0 |
Dump a description of all SymbolEntry objects to a stream. | |
virtual int4 | getCategorySize (int4 cat) const =0 |
Get the number of Symbols in the given category. More... | |
virtual Symbol * | getCategorySymbol (int4 cat, int4 ind) const =0 |
Retrieve a Symbol by index within a specific category. More... | |
virtual void | setCategory (Symbol *sym, int4 cat, int4 ind)=0 |
Set the category and index for the given Symbol. More... | |
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. More... | |
const string & | getName (void) const |
Get the name of the Scope. | |
uint8 | getId (void) const |
Get the globally unique id. | |
bool | isGlobal (void) const |
Return true if this scope is global. | |
void | queryByName (const string &name, vector< Symbol * > &res) const |
Look-up symbols by name. More... | |
Funcdata * | queryFunction (const string &name) const |
Look-up a function by name. More... | |
SymbolEntry * | queryByAddr (const Address &addr, const Address &usepoint) const |
Get Symbol with matching address. More... | |
SymbolEntry * | queryContainer (const Address &addr, int4 size, const Address &usepoint) const |
Find the smallest containing Symbol. More... | |
SymbolEntry * | queryProperties (const Address &addr, int4 size, const Address &usepoint, uint4 &flags) const |
Find a Symbol or properties at the given address. More... | |
Funcdata * | queryFunction (const Address &addr) const |
Look-up a function by address. More... | |
Funcdata * | queryExternalRefFunction (const Address &addr) const |
Look-up a function thru an external reference. More... | |
LabSymbol * | queryCodeLabel (const Address &addr) const |
Look-up a code label by address. More... | |
Scope * | resolveScope (const string &name, bool strategy) const |
Find a child Scope of this. More... | |
Scope * | discoverScope (const Address &addr, int4 sz, const Address &usepoint) |
Find the owning Scope of a given memory range. More... | |
ScopeMap::const_iterator | childrenBegin () const |
Beginning iterator of child scopes. | |
ScopeMap::const_iterator | childrenEnd () const |
Ending iterator of child scopes. | |
void | saveXmlRecursive (ostream &s, bool onlyGlobal) const |
Save all contained scopes as an XML stream. More... | |
void | overrideSizeLockType (Symbol *sym, Datatype *ct) |
Change the data-type of a Symbol that is sizelocked. More... | |
void | resetSizeLockType (Symbol *sym) |
Clear a Symbol's size-locked data-type. More... | |
void | setThisPointer (Symbol *sym, bool val) |
Toggle the given Symbol as the "this" pointer. | |
bool | isSubScope (const Scope *scp) const |
Is this a sub-scope of the given Scope. More... | |
string | getFullName (void) const |
Get the full name of this Scope. | |
void | getScopePath (vector< const Scope * > &vec) const |
Get the ordered list of scopes up to this. More... | |
const Scope * | findDistinguishingScope (const Scope *op2) const |
Find first ancestor of this not shared by given scope. More... | |
Architecture * | getArch (void) const |
Get the Architecture associated with this. | |
Scope * | getParent (void) const |
Get the parent Scope (or NULL if this is the global Scope) | |
Symbol * | addSymbol (const string &name, Datatype *ct) |
Add a new Symbol without mapping it to an address. More... | |
SymbolEntry * | addMapPoint (Symbol *sym, const Address &addr, const Address &usepoint) |
Map a Symbol to a specific address. More... | |
Symbol * | addMapSym (const Element *el) |
Add a mapped Symbol from a <mapsym> XML tag. More... | |
FunctionSymbol * | addFunction (const Address &addr, const string &nm) |
Create a function Symbol at the given address in this Scope. More... | |
ExternRefSymbol * | addExternalRef (const Address &addr, const Address &refaddr, const string &nm) |
LabSymbol * | addCodeLabel (const Address &addr, const string &nm) |
Create a code label at the given address in this Scope. More... | |
Symbol * | addDynamicSymbol (const string &nm, Datatype *ct, const Address &caddr, uint8 hash) |
Create a dynamically mapped Symbol attached to a specific data-flow. More... | |
string | buildDefaultName (Symbol *sym, int4 &base, Varnode *vn) const |
Create a default name for the given Symbol. More... | |
bool | isReadOnly (const Address &addr, int4 size, const Address &usepoint) const |
Is the given memory range marked as read-only. More... | |
void | printBounds (ostream &s) const |
Print a description of this Scope's owned memory ranges. | |
Protected Member Functions | |
const RangeList & | getRangeTree (void) const |
Access the address ranges owned by this Scope. | |
virtual Scope * | buildSubScope (uint8 id, const string &nm)=0 |
Build an unattached Scope to be associated as a sub-scope of this. More... | |
virtual void | restrictScope (Funcdata *f) |
Convert this to a local Scope. More... | |
virtual void | addRange (AddrSpace *spc, uintb first, uintb last) |
Add a memory range to the ownership of this Scope. More... | |
virtual void | removeRange (AddrSpace *spc, uintb first, uintb last) |
Remove a memory range from the ownership of this Scope. More... | |
virtual void | addSymbolInternal (Symbol *sym)=0 |
Put a Symbol into the name map. More... | |
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. More... | |
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. More... | |
SymbolEntry * | addMap (SymbolEntry &entry) |
Integrate a SymbolEntry into the range maps. More... | |
void | setSymbolId (Symbol *sym, uint8 id) const |
Adjust the id associated with a symbol. | |
Static Protected Member Functions | |
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. More... | |
static const Scope * | stackContainer (const Scope *scope1, const Scope *scope2, const Address &addr, int4 size, const Address &usepoint, SymbolEntry **addrmatch) |
static const Scope * | stackClosestFit (const Scope *scope1, const Scope *scope2, const Address &addr, int4 size, const Address &usepoint, SymbolEntry **addrmatch) |
static const Scope * | stackFunction (const Scope *scope1, const Scope *scope2, const Address &addr, Funcdata **addrmatch) |
static const Scope * | stackExternalRef (const Scope *scope1, const Scope *scope2, const Address &addr, ExternRefSymbol **addrmatch) |
static const Scope * | stackCodeLabel (const Scope *scope1, const Scope *scope2, const Address &addr, LabSymbol **addrmatch) |
Protected Attributes | |
Architecture * | glb |
Architecture of this scope. | |
string | name |
Name of this scope. | |
Funcdata * | fd |
(If non-null) the function which this is the local Scope for | |
uint8 | uniqueId |
Unique id for the scope, for deduping scope names, assigning symbol ids. | |
Private Member Functions | |
void | attachScope (Scope *child) |
Attach a new child Scope to this. More... | |
void | detachScope (ScopeMap::iterator iter) |
Detach a child Scope from this. More... | |
Static Private Member Functions | |
static uint8 | hashScopeName (uint8 baseId, const string &nm) |
Create a Scope id based on the scope's name and its parent's id. More... | |
Private Attributes | |
RangeList | rangetree |
Range of data addresses owned by this scope. | |
Scope * | parent |
The parent scope. | |
Scope * | owner |
Scope using this as a cache. | |
ScopeMap | children |
Sorted list of child scopes. | |
Friends | |
class | Database |
class | ScopeCompare |
A collection of Symbol objects within a single (namespace or functional) scope.
This acts as a traditional Symbol container, allowing them to be accessed by name, but it also keeps track of how a Symbol is mapped into memory. It allows a Symbol to be looked up by its location in memory, which is sensitive to the address of the code accessing the Symbol.
Capabilities include:
A scope also supports the idea of ownership of memory. In theory, for a Symbol in the scope, at the code locations where the Symbol storage is valid, the scope owns the storage memory. In practice, a Scope object knows about memory ranges where a Symbol might be discovered. For instance, the global Scope usually owns all memory in the ram address space.
Create a code label at the given address in this Scope.
A LabSymbol is created and mapped to the given address.
addr | is the given address to map to |
nm | is the name of the symbol/label |
References Symbol::getName(), and SymbolEntry::getSymbol().
Referenced by ScopeGhidra::findCodeLabel().
|
protectedpure virtual |
Create a new SymbolEntry for a Symbol given a dynamic hash.
The SymbolEntry is specified in terms of a hash and usepoint, which describe how to find the temporary Varnode holding the symbol value.
sym | is the given Symbol being mapped |
exfl | are any boolean Varnode properties |
hash | is the given dynamic hash |
off | is the byte offset of the new SymbolEntry (relative to the whole Symbol) |
sz | is the number of bytes occupied by the Varnode |
uselim | is the given usepoint |
Implemented in ScopeInternal, and ScopeGhidra.
Symbol * Scope::addDynamicSymbol | ( | const string & | nm, |
Datatype * | ct, | ||
const Address & | caddr, | ||
uint8 | hash | ||
) |
Create a dynamically mapped Symbol attached to a specific data-flow.
The Symbol is created and mapped to a dynamic hash and a code address where the Symbol is being used.
nm | is the name of the Symbol |
ct | is the data-type of the Symbol |
caddr | is the code address where the Symbol is being used |
hash | is the dynamic hash |
References Address::getOffset(), Datatype::getSize(), Address::getSpace(), RangeList::insertRange(), Address::isInvalid(), Varnode::mapped, and Symbol::Symbol().
Referenced by Funcdata::buildDynamicSymbol().
ExternRefSymbol * Scope::addExternalRef | ( | const Address & | addr, |
const Address & | refaddr, | ||
const string & | nm | ||
) |
Create an external reference at the given address in this Scope
An ExternRefSymbol is created and mapped to the given address and stores a reference address to the actual function.
addr | is the given address to map the Symbol to |
refaddr | is the reference address |
nm | is the name of the symbol/function |
References ExternRefSymbol::ExternRefSymbol(), Symbol::flags, Varnode::readonly, and SymbolEntry::symbol.
FunctionSymbol * Scope::addFunction | ( | const Address & | addr, |
const string & | nm | ||
) |
Create a function Symbol at the given address in this Scope.
The FunctionSymbol is created and mapped to the given address. A Funcdata object is only created once FunctionSymbol::getFunction() is called.
addr | is the entry address of the function |
nm | is the name of the function, within this Scope |
References Symbol::getName(), SymbolEntry::getSymbol(), and Symbol::name.
Referenced by Architecture::readLoaderSymbols().
|
protected |
Integrate a SymbolEntry into the range maps.
The mapping is given as an unintegrated SymbolEntry object. Memory may be specified in terms of join addresses, which this method must unravel. The offset, size, and extraflags fields of the SymbolEntry are not used. In particular, the SymbolEntry is assumed to map the entire Symbol.
entry | is the given SymbolEntry |
References SymbolEntry::addr, Varnode::addrtied, RangeList::clear(), RangeList::empty(), Symbol::flags, Symbol::getBytesConsumed(), Address::getOffset(), JoinRecord::getPiece(), SymbolEntry::hash, inScope(), Address::isBigEndian(), Address::isInvalid(), Address::isJoin(), Varnode::mapped, JoinRecord::numPieces(), Varnode::persist, Varnode::precishi, Varnode::precislo, SymbolEntry::symbol, and SymbolEntry::uselimit.
|
protectedpure virtual |
Create a new SymbolEntry for a Symbol given a memory range.
The SymbolEntry is specified in terms of a memory range and usepoint
sym | is the given Symbol being mapped |
exfl | are any boolean Varnode properties specific to the memory range |
addr | is the starting address of the given memory range |
off | is the byte offset of the new SymbolEntry (relative to the whole Symbol) |
sz | is the number of bytes in the range |
uselim | is the given usepoint (which may be invalid) |
Implemented in ScopeInternal, ScopeGhidraNamespace, and ScopeGhidra.
SymbolEntry * Scope::addMapPoint | ( | Symbol * | sym, |
const Address & | addr, | ||
const Address & | usepoint | ||
) |
Map a Symbol to a specific address.
Create a new SymbolEntry that maps the whole Symbol to the given address
sym | is the Symbol |
addr | is the given address to map to |
usepoint | is a point at which the Symbol is accessed at that address |
References SymbolEntry::addr, Address::getOffset(), Address::getSpace(), RangeList::insertRange(), Address::isInvalid(), and SymbolEntry::uselimit.
Referenced by ScopeInternal::retypeSymbol().
Add a mapped Symbol from a <mapsym> XML tag.
A tag describing the Symbol is parsed first, followed by sequences of <addr> or <hash> and <rangelist> which define 1 or more mappings of the Symbol The new Symbol and SymbolEntry mappings are integrated into this Scope
el | is the <mapsym> XML element |
References ExternRefSymbol::ExternRefSymbol(), Element::getChildren(), Element::getName(), SymbolEntry::isInvalid(), SymbolEntry::restoreXml(), Symbol::restoreXml(), and Symbol::Symbol().
Referenced by ScopeGhidra::dump2Cache(), and ScopeInternal::restoreXml().
|
protectedvirtual |
Add a memory range to the ownership of this Scope.
spc | is the address space of the range |
first | is the offset of the first byte in the range |
last | is the offset of the last byte in the range |
Reimplemented in ScopeGhidra.
Referenced by ScopeGhidra::addRange(), and Database::addRange().
|
virtual |
Add a new Symbol to this Scope, given a name, data-type, and a single mapping.
The Symbol object will be created with the given name and data-type. A single mapping (SymbolEntry) will be created for the Symbol based on a given storage address for the symbol and an address for code that accesses the Symbol at that storage location.
name | is the new name of the Symbol |
ct | is the data-type of the new Symbol |
addr | is the starting address of the Symbol storage |
usepoint | is the point accessing that storage (may be invalid) |
Reimplemented in ScopeGhidra.
References Symbol::Symbol().
Referenced by ScopeGhidra::addSymbol(), Funcdata::coverVarnodes(), ScopeLocal::createEntry(), Funcdata::linkSymbol(), Funcdata::mapGlobals(), and ScopeInternal::processCollision().
Add a new Symbol without mapping it to an address.
The Symbol is created and added to any name map, but no SymbolEntry objects are created for it.
References Symbol::Symbol().
|
protectedpure virtual |
Put a Symbol into the name map.
sym | is the preconstructed Symbol |
Implemented in ScopeInternal, and ScopeGhidra.
|
pure virtual |
Let scopes internally adjust any caches.
This is called once after Architecture configuration is complete.
Implemented in ScopeInternal, and ScopeGhidra.
|
private |
Attach a new child Scope to this.
Attach the child as an immediate sub-scope of this. Take responsibility of the child's memory: the child will be freed when this is freed.
child | is the Scope to make a child |
References parent, and uniqueId.
Referenced by Database::attachScope(), Database::findCreateScope(), and Database::restoreXmlScope().
Create a default name for the given Symbol.
Create default name given information in the Symbol and possibly a representative Varnode. This method extracts the crucial properties and then uses the buildVariableName method to construct the actual name.
sym | is the given Symbol to name |
base | is an index (which may get updated) used to uniquify the name |
vn | is an optional (may be null) Varnode representative of the Symbol |
References Varnode::addrtied, Symbol::flags, SymbolEntry::getAddr(), Varnode::getAddr(), Symbol::getCategory(), Symbol::getCategoryIndex(), SymbolEntry::getFirstUseAddress(), Varnode::getFlags(), Varnode::getHigh(), Symbol::getMapEntry(), Symbol::getType(), Varnode::getUsePoint(), Varnode::input, Varnode::isAddrTied(), Varnode::isConstant(), HighVariable::isInput(), Address::isInvalid(), and Symbol::numEntries().
Referenced by ActionNameVars::apply(), and ScopeInternal::assignDefaultNames().
|
protectedpure virtual |
Build an unattached Scope to be associated as a sub-scope of this.
This is a Scope object factory, intended to be called off of the global scope for building global namespace scopes. Function scopes are handled differently.
id | is the globally unique id associated with the scope |
nm | is the name of the new scope |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by Database::findCreateScope().
|
pure virtual |
Build a formal undefined name, used internally when a Symbol is not given a name.
Implemented in ScopeInternal, and ScopeGhidra.
|
pure virtual |
Given an address and data-type, build a suitable generic symbol name.
addr | is the given address |
pc | is the address at which the name is getting used |
ct | is a data-type used to inform the name |
index | is a reference to an index used to make the name unique, which will be updated |
flags | are boolean properties of the variable we need the name for |
Implemented in ScopeInternal, ScopeLocal, and ScopeGhidra.
Referenced by Funcdata::mapGlobals().
|
private |
Detach a child Scope from this.
The indicated child Scope is deleted
iter | points to the Scope to delete |
Referenced by Database::deleteScope(), and Database::deleteSubScopes().
Find the owning Scope of a given memory range.
Discover a sub-scope or containing Scope of this, that owns the given memory range at a specific usepoint. Note that ownership does not necessarily mean there is a known symbol there.
addr | is the starting address of the memory range |
sz | is the number of bytes in the range |
usepoint | is a point at which the memory is getting accesses |
References getParent(), inScope(), and Address::isConstant().
Referenced by Funcdata::mapGlobals().
|
pure virtual |
Find a Symbol at a given address and usepoint.
addr | is the given address |
usepoint | is the point at which the Symbol is accessed (may be invalid) |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by stackAddr().
|
pure virtual |
Find a Symbol by name within this Scope.
If there are multiple Symbols with the same name, all are passed back.
name | is the name to search for |
res | will contain any matching Symbols |
Implemented in ScopeInternal, and ScopeGhidra.
|
pure virtual |
Find Symbol which is the closest fit to the given memory range.
addr | is the starting address of the given memory range |
size | is the number of bytes in the range |
usepoint | is the point at which the Symbol is accessed (may be invalid) |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by stackClosestFit().
Find a label Symbol at the given address.
addr | is the given address |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by stackCodeLabel().
|
pure virtual |
Find the smallest Symbol containing the given memory range.
addr | is the starting address of the given memory range |
size | is the number of bytes in the range |
usepoint | is the point at which the Symbol is accessed (may be invalid) |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by Funcdata::coverVarnodes(), and stackContainer().
Find first ancestor of this not shared by given scope.
Any two scopes share at least the global scope as a common ancestor. We find the first scope that is not in common. The scope returned will always be an ancestor of this. If this is an ancestor of the other given scope, then null is returned.
op2 | is the other given Scope |
References getScopePath(), and parent.
Referenced by Symbol::getResolutionDepth().
|
pure virtual |
Find an external reference at the given address.
addr | is the given address |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by stackExternalRef().
Find the function starting at the given address.
addr | is the given starting address |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by stackFunction().
|
pure virtual |
Find first Symbol overlapping the given memory range.
addr | is the starting address of the given range |
size | is the number of bytes in the range |
Implemented in ScopeInternal, and ScopeGhidra.
|
pure virtual |
Get the number of Symbols in the given category.
cat | is the Symbol category |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by PrintC::emitScopeVarDecls().
|
pure virtual |
Retrieve a Symbol by index within a specific category.
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by PrintC::emitScopeVarDecls().
void Scope::getScopePath | ( | vector< const Scope * > & | vec | ) | const |
Get the ordered list of scopes up to this.
Put the parent scopes of this into an array in order, starting with the global scope.
vec | is storage for the array of scopes |
References parent.
Referenced by findDistinguishingScope().
|
staticprivate |
Create a Scope id based on the scope's name and its parent's id.
Create a globally unique id for a scope simply from its name.
baseId | is the scope id of the parent scope |
nm | is the name of scope |
References crc_update().
Referenced by Database::findCreateScopeFromSymbolName().
|
inlinevirtual |
Query if the given range is owned by this Scope.
All bytes in the range must be owned, and ownership can be informed by particular code that is accessing the range.
addr | is the starting address of the range |
size | is the number of bytes in the range |
usepoint | is the code address at which the given range is being accessed (may be invalid) |
References RangeList::inRange(), SymbolEntry::restoreXml(), SymbolEntry::saveXml(), SymbolEntry::size, and SymbolEntry::EntryInitData::symbol.
Referenced by addMap(), discoverScope(), stackAddr(), stackClosestFit(), stackCodeLabel(), stackContainer(), stackFunction(), and Funcdata::syncVarnodesWithSymbols().
|
pure virtual |
Check if the given name is occurs within the given scope path.
Test for the presence of a symbol with the given name in either this scope or an ancestor scope up to but not including the given terminating scope. If the name is used true is returned.
nm | is the given name to test |
op2 | is the terminating ancestor scope (or null) |
Implemented in ScopeInternal, ScopeGhidraNamespace, and ScopeGhidra.
Referenced by Symbol::getResolutionDepth(), and ScopeInternal::isNameUsed().
Is the given memory range marked as read-only.
Check for Symbols relative to this Scope that are marked as read-only, and look-up properties of the memory in general.
addr | is the starting address of the given memory range |
size | is the number of bytes in the range |
usepoint | is a point where the range is getting accessed |
References Symbol::flags, and Varnode::readonly.
Referenced by RulePtrsubCharConstant::applyOp(), and PrintC::pushPtrCharConstant().
bool Scope::isSubScope | ( | const Scope * | scp | ) | const |
|
pure virtual |
Produce a version of the given symbol name that won't collide with other names in this Scope.
nm | is the given name |
Implemented in ScopeInternal, and ScopeGhidra.
Change the data-type of a Symbol that is sizelocked.
Change (override) the data-type of a sizelocked Symbol, while preserving the lock. An exception is thrown if the new data-type doesn't fit the size.
References Datatype::getSize(), Symbol::isSizeTypeLocked(), and Symbol::type.
Referenced by ActionNameVars::linkSymbols().
SymbolEntry * Scope::queryByAddr | ( | const Address & | addr, |
const Address & | usepoint | ||
) | const |
Get Symbol with matching address.
Within a sub-scope or containing Scope of this, find a Symbol that is mapped to the given address, where the mapping is valid at a specific usepoint.
addr | is the given address |
usepoint | is the point at which code accesses that address (may be invalid) |
void Scope::queryByName | ( | const string & | name, |
vector< Symbol * > & | res | ||
) | const |
Look-up symbols by name.
Starting from this Scope, look for a Symbol with the given name. If there are no Symbols in this Scope, recurse into the parent Scope. If there are 1 (or more) Symbols matching in this Scope, add them to the result list
name | is the name to search for |
res | is the result list |
Referenced by ScopeGhidra::dump2Cache(), and Funcdata::findHigh().
Look-up a code label by address.
Within a sub-scope or containing Scope of this, find a label Symbol at the given address.
addr | is the given address |
Referenced by PrintC::emitLabel().
SymbolEntry * Scope::queryContainer | ( | const Address & | addr, |
int4 | size, | ||
const Address & | usepoint | ||
) | const |
Find the smallest containing Symbol.
Within a sub-scope or containing Scope of this, find the smallest Symbol that contains a given memory range and can be accessed at a given usepoint.
addr | is the given starting address of the memory range |
size | is the number of bytes in the range |
usepoint | is a point at which the Symbol is accessed (may be invalid) |
Referenced by ActionConstantPtr::isPointer(), Funcdata::linkSymbolReference(), and PrintC::pushAnnotation().
Look-up a function thru an external reference.
Given an address, search for an external reference. If no Symbol is found and this Scope does not own the address, recurse searching in the parent Scope. If an external reference is found, try to resolve the function it refers to and return it.
addr | is the given address where an external reference might be |
References resolveExternalRefFunction().
Referenced by ActionDeindirect::apply().
Funcdata * Scope::queryFunction | ( | const string & | name | ) | const |
Look-up a function by name.
Starting with this Scope, find a function with the given name. If there are no Symbols with that name in this Scope at all, recurse into the parent Scope.
name | if the name to search for |
References FunctionSymbol::getFunction().
Referenced by OptionExtraPop::apply(), OptionInline::apply(), OptionNoReturn::apply(), ActionDeindirect::apply(), PrintC::pushPtrCodeConstant(), FlowInfo::queryCall(), DecompileAt::rawAction(), ScopeInternal::resolveExternalRefFunction(), and Architecture::setPrototype().
SymbolEntry * Scope::queryProperties | ( | const Address & | addr, |
int4 | size, | ||
const Address & | usepoint, | ||
uint4 & | flags | ||
) | const |
Find a Symbol or properties at the given address.
Similarly to queryContainer(), this searches for the smallest containing Symbol, but whether a known Symbol is found or not, boolean properties associated with the memory range are also search for and passed back.
addr | is the starting address of the range |
size | is the number of bytes in the range |
usepoint | is a point at which the memory range is accessed (may be invalid) |
flags | is a reference used to pass back the boolean properties of the memory range |
References Varnode::addrtied, SymbolEntry::getAllFlags(), isGlobal(), Varnode::mapped, and Varnode::persist.
Referenced by TypeOpCallother::getInputLocal(), TypeOpCallother::getOutputLocal(), Funcdata::linkSymbol(), Funcdata::mapGlobals(), Funcdata::newVarnode(), Funcdata::newVarnodeOut(), and Funcdata::setVarnodeProperties().
|
protectedvirtual |
Remove a memory range from the ownership of this Scope.
spc | is the address space of the range |
first | is the offset of the first byte in the range |
last | is the offset of the last byte in the range |
Reimplemented in ScopeGhidra.
Referenced by Database::removeRange().
void Scope::resetSizeLockType | ( | Symbol * | sym | ) |
Clear a Symbol's size-locked data-type.
Replace any overriding data-type type with the locked UNKNOWN type of the correct size. The data-type is cleared, but the lock is preserved.
sym | is the Symbol to clear |
References Datatype::getMetatype(), Datatype::getSize(), Symbol::type, and TYPE_UNKNOWN.
Referenced by ScopeInternal::clearUnlocked(), and ScopeInternal::clearUnlockedCategory().
|
pure virtual |
Convert an external reference to the referenced function.
sym | is the Symbol marking the external reference |
Implemented in ScopeInternal, and ScopeGhidra.
Referenced by queryExternalRefFunction().
Scope * Scope::resolveScope | ( | const string & | name, |
bool | strategy | ||
) | const |
Find a child Scope of this.
Look for the immediate child of this with a given name
name | is the child's name |
strategy | is true if hash of the name determines id |
References name, and Symbol::scope.
Referenced by Database::findCreateScope(), Database::parseParentTag(), and Database::resolveScopeFromSymbolName().
|
protectedvirtual |
Convert this to a local Scope.
Attach this to the given function, which makes this the local scope for the function
f | is the given function to attach to |
Reimplemented in ScopeGhidra.
Referenced by ScopeLocal::ScopeLocal().
Change the data-type of a Symbol within this Scope.
If the size of the Symbol changes, any mapping (SymbolEntry) is adjusted
sym | is the given Symbol |
ct | is the new data-type |
Implemented in ScopeInternal, and ScopeGhidra.
void Scope::saveXmlRecursive | ( | ostream & | s, |
bool | onlyGlobal | ||
) | const |
Save all contained scopes as an XML stream.
This Scope and all of its sub-scopes are saved as a sequence of <scope> tags in post order. For each Scope, the saveXml() method is invoked.
s | is the output stream |
onlyGlobal | is true if only non-local Scopes should be saved |
References ExternRefSymbol::saveXml().
Referenced by Funcdata::saveXml().
|
pure virtual |
Set the category and index for the given Symbol.
sym | is the given Symbol |
cat | is the category to set for the Symbol |
ind | is the index position to set (within the category) |
Implemented in ScopeInternal, and ScopeGhidra.
|
staticprotected |
Query for Symbols starting at a given address, which match a given usepoint.
Searching starts at a first scope, continuing thru parents up to a second scope, which is not queried. If a Scope controls the memory at that address, the Scope object is returned. Additionally, if a symbol matching the criterion is found, the matching SymbolEntry is passed back.
scope1 | is the first Scope where searching starts |
scope2 | is the second Scope where searching ends |
addr | is the given address to search for |
usepoint | is the given point at which the memory is being accessed (can be an invalid address) |
addrmatch | is used to pass-back any matching SymbolEntry |
References findAddr(), getParent(), inScope(), and Address::isConstant().
|
staticprotected |
Query for a Symbol which most closely matches a given range and usepoint
Searching starts at a first scope, continuing thru parents up to a second scope, which is not queried. If a Scope controls the memory in the given range, the Scope object is returned. Among symbols that overlap the given range, the SymbolEntry which most closely matches the starting address and size is passed back.
scope1 | is the first Scope where searching starts |
scope2 | is the second Scope where searching ends |
addr | is the starting address of the given range |
size | is the number of bytes in the given range |
usepoint | is the point at which the memory is being accessed (can be an invalid address) |
addrmatch | is used to pass-back any matching SymbolEntry |
References findClosestFit(), getParent(), inScope(), and Address::isConstant().
|
staticprotected |
Query for a label Symbol for a given address.
Searching starts at a first scope, continuing thru parents up to a second scope, which is not queried. If a Scope controls the memory in the given range, the Scope object is returned. If there is a label at that address, pass back the corresponding LabSymbol object
scope1 | is the first Scope where searching starts |
scope2 | is the second Scope where searching ends |
addr | is the given address |
addrmatch | is used to pass-back any matching Symbol |
References findCodeLabel(), getParent(), inScope(), and Address::isConstant().
|
staticprotected |
Query for a Symbol containing a given range which is accessed at a given usepoint
Searching starts at a first scope, continuing thru parents up to a second scope, which is not queried. If a Scope controls the memory in the given range, the Scope object is returned. If a known Symbol contains the range, the matching SymbolEntry is passed back.
scope1 | is the first Scope where searching starts |
scope2 | is the second Scope where searching ends |
addr | is the starting address of the given range |
size | is the number of bytes in the given range |
usepoint | is the point at which the memory is being accessed (can be an invalid address) |
addrmatch | is used to pass-back any matching SymbolEntry |
References findContainer(), getParent(), inScope(), and Address::isConstant().
|
staticprotected |
Query for an external reference Symbol starting at the given address
Searching starts at a first scope, continuing thru parents up to a second scope, which is not queried. If a Scope controls the memory in the given range, the Scope object is returned. If an external reference is found at the address, pass back the matching ExternRefSymbol
scope1 | is the first Scope where searching starts |
scope2 | is the second Scope where searching ends |
addr | is the given address |
addrmatch | is used to pass-back any matching Symbol |
References findExternalRef(), getParent(), and Address::isConstant().
|
staticprotected |
Query for a function Symbol starting at the given address
Searching starts at a first scope, continuing thru parents up to a second scope, which is not queried. If a Scope controls the memory in the given range, the Scope object is returned. If a FunctionSymbol is found at the given address, the corresponding Funcdata object is passed back.
scope1 | is the first Scope where searching starts |
scope2 | is the second Scope where searching ends |
addr | is the given address where the function should start |
addrmatch | is used to pass-back any matching function |
References findFunction(), getParent(), inScope(), and Address::isConstant().
Referenced by ScopeGhidra::resolveExternalRefFunction().