decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::ScopeLocal Class Reference

A Symbol scope for local variables of a particular function. More...

#include <varmap.hh>

Inheritance diagram for ghidra::ScopeLocal:
ghidra::ScopeInternal ghidra::Scope

Public Member Functions

 ScopeLocal (uint8 id, AddrSpace *spc, Funcdata *fd, Architecture *g)
 Constructor. More...
 
virtual ~ScopeLocal (void)
 Destructor.
 
AddrSpacegetSpaceId (void) const
 Get the associated (stack) address space.
 
bool isUnaffectedStorage (Varnode *vn) const
 Is this a storage location for unaffected registers. More...
 
bool isUnmappedUnaliased (Varnode *vn) const
 Check if a given unmapped Varnode should be treated as unaliased. More...
 
void markNotMapped (AddrSpace *spc, uintb first, int4 sz, bool param)
 Mark a specific address range is not mapped. More...
 
virtual void encode (Encoder &encoder) const
 Encode this as a <scope> element.
 
virtual void decode (Decoder &decoder)
 Decode this Scope from a <scope> element.
 
virtual void decodeWrappingAttributes (Decoder &decoder)
 Restore attributes for this Scope from wrapping element.
 
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. More...
 
void resetLocalWindow (void)
 Reset the set of addresses that are considered mapped by the scope to the default. More...
 
void restructureVarnode (bool aliasyes)
 Layout mapped symbols based on Varnode information. More...
 
void restructureHigh (void)
 Layout mapped symbols based on HighVariable information. More...
 
SymbolEntryremapSymbol (Symbol *sym, const Address &addr, const Address &usepoint)
 Change the primary mapping for the given Symbol to be a specific storage address and use point. More...
 
SymbolEntryremapSymbolDynamic (Symbol *sym, uint8 hash, const Address &usepoint)
 Make the primary mapping for the given Symbol, dynamic. More...
 
void recoverNameRecommendationsForSymbols (void)
 Run through name recommendations, checking if any match unnamed symbols. More...
 
void applyTypeRecommendations (void)
 Try to apply recommended data-type information. More...
 
bool hasTypeRecommendations (void) const
 Are there data-type recommendations.
 
void addTypeRecommendation (const Address &addr, Datatype *dt)
 Add a new data-type recommendation. More...
 
- Public Member Functions inherited from ghidra::ScopeInternal
 ScopeInternal (uint8 id, const string &nm, Architecture *g)
 Construct the Scope. More...
 
 ScopeInternal (uint8 id, const string &nm, Architecture *g, Scope *own)
 Construct as a cache.
 
virtual void clear (void)
 Clear all symbols from this scope.
 
virtual void categorySanity (void)
 Make sure Symbol categories are sane. More...
 
virtual void clearCategory (int4 cat)
 Clear all symbols of the given category from this scope.
 
virtual void clearUnlocked (void)
 Clear all unlocked symbols from this scope.
 
virtual void clearUnlockedCategory (int4 cat)
 Clear unlocked symbols of the given category from this scope.
 
virtual void adjustCaches (void)
 Let scopes internally adjust any caches. More...
 
virtual MapIterator begin (void) const
 Beginning iterator to mapped SymbolEntrys.
 
virtual MapIterator end (void) const
 Ending iterator to mapped SymbolEntrys.
 
virtual list< SymbolEntry >::const_iterator beginDynamic (void) const
 Beginning iterator to dynamic SymbolEntrys.
 
virtual list< SymbolEntry >::const_iterator endDynamic (void) const
 Ending iterator to dynamic SymbolEntrys.
 
virtual list< SymbolEntry >::iterator beginDynamic (void)
 Beginning iterator to dynamic SymbolEntrys.
 
virtual list< SymbolEntry >::iterator endDynamic (void)
 Ending iterator to dynamic SymbolEntrys.
 
virtual void removeSymbolMappings (Symbol *symbol)
 Remove all SymbolEntrys from the given Symbol.
 
virtual void removeSymbol (Symbol *symbol)
 Remove the given Symbol from this Scope.
 
virtual void renameSymbol (Symbol *sym, const string &newname)
 Rename a Symbol within this Scope.
 
virtual void retypeSymbol (Symbol *sym, Datatype *ct)
 Change the data-type of a Symbol within this Scope. More...
 
virtual void setAttribute (Symbol *sym, uint4 attr)
 Set boolean Varnode properties on a Symbol.
 
virtual void clearAttribute (Symbol *sym, uint4 attr)
 Clear boolean Varnode properties on a Symbol.
 
virtual void setDisplayFormat (Symbol *sym, uint4 attr)
 Set the display format for a Symbol.
 
virtual SymbolEntryfindAddr (const Address &addr, const Address &usepoint) const
 Find a Symbol at a given address and usepoint. More...
 
virtual SymbolEntryfindContainer (const Address &addr, int4 size, const Address &usepoint) const
 Find the smallest Symbol containing the given memory range. More...
 
virtual SymbolEntryfindClosestFit (const Address &addr, int4 size, const Address &usepoint) const
 Find Symbol which is the closest fit to the given memory range. More...
 
virtual FuncdatafindFunction (const Address &addr) const
 Find the function starting at the given address. More...
 
virtual ExternRefSymbolfindExternalRef (const Address &addr) const
 Find an external reference at the given address. More...
 
virtual LabSymbolfindCodeLabel (const Address &addr) const
 Find a label Symbol at the given address. More...
 
virtual SymbolEntryfindOverlap (const Address &addr, int4 size) const
 Find first Symbol overlapping the given memory range. More...
 
virtual void findByName (const string &nm, vector< Symbol *> &res) const
 Find a Symbol by name within this Scope. More...
 
virtual bool isNameUsed (const string &nm, const Scope *op2) const
 Check if the given name is occurs within the given scope path. More...
 
virtual FuncdataresolveExternalRefFunction (ExternRefSymbol *sym) const
 Convert an external reference to the referenced function. More...
 
virtual string buildUndefinedName (void) const
 Build a formal undefined name, used internally when a Symbol is not given a name. More...
 
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. More...
 
virtual void printEntries (ostream &s) const
 Dump a description of all SymbolEntry objects to a stream.
 
virtual int4 getCategorySize (int4 cat) const
 Get the number of Symbols in the given category. More...
 
virtual SymbolgetCategorySymbol (int4 cat, int4 ind) const
 Retrieve a Symbol by index within a specific category. More...
 
virtual void setCategory (Symbol *sym, int4 cat, int4 ind)
 Set the category and index for the given Symbol. More...
 
void assignDefaultNames (int4 &base)
 Assign a default name (via buildVariableName) to any unnamed symbol. More...
 
set< Symbol * >::const_iterator beginMultiEntry (void) const
 Start of symbols with more than one entry.
 
set< Symbol * >::const_iterator endMultiEntry (void) const
 End of symbols with more than one entry.
 
- Public Member Functions inherited from ghidra::Scope
 Scope (uint8 id, const string &nm, Architecture *g, Scope *own)
 Construct an empty scope, given a name and Architecture.
 
virtual ~Scope (void)
 Destructor.
 
virtual bool inScope (const Address &addr, int4 size, const Address &usepoint) const
 Query if the given range is owned by this Scope. More...
 
virtual SymbolEntryaddSymbol (const string &nm, 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.
 
const string & getDisplayName (void) const
 Get name displayed in output.
 
uint8 getId (void) const
 Get the globally unique id.
 
bool isGlobal (void) const
 Return true if this scope is global.
 
void queryByName (const string &nm, vector< Symbol *> &res) const
 Look-up symbols by name. More...
 
FuncdataqueryFunction (const string &nm) const
 Look-up a function by name. More...
 
SymbolEntryqueryByAddr (const Address &addr, const Address &usepoint) const
 Get Symbol with matching address. More...
 
SymbolEntryqueryContainer (const Address &addr, int4 size, const Address &usepoint) const
 Find the smallest containing Symbol. More...
 
SymbolEntryqueryProperties (const Address &addr, int4 size, const Address &usepoint, uint4 &flags) const
 Find a Symbol or properties at the given address. More...
 
FuncdataqueryFunction (const Address &addr) const
 Look-up a function by address. More...
 
FuncdataqueryExternalRefFunction (const Address &addr) const
 Look-up a function thru an external reference. More...
 
LabSymbolqueryCodeLabel (const Address &addr) const
 Look-up a code label by address. More...
 
ScoperesolveScope (const string &nm, bool strategy) const
 Find a child Scope of this. More...
 
ScopediscoverScope (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 encodeRecursive (Encoder &encoder, bool onlyGlobal) const
 Encode all contained scopes to a 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 ScopefindDistinguishingScope (const Scope *op2) const
 Find first ancestor of this not shared by given scope. More...
 
ArchitecturegetArch (void) const
 Get the Architecture associated with this.
 
ScopegetParent (void) const
 Get the parent Scope (or NULL if this is the global Scope)
 
SymboladdSymbol (const string &nm, Datatype *ct)
 Add a new Symbol without mapping it to an address. More...
 
SymbolEntryaddMapPoint (Symbol *sym, const Address &addr, const Address &usepoint)
 Map a Symbol to a specific address. More...
 
SymboladdMapSym (Decoder &decoder)
 Parse a mapped Symbol from a <mapsym> element. More...
 
FunctionSymboladdFunction (const Address &addr, const string &nm)
 Create a function Symbol at the given address in this Scope. More...
 
ExternRefSymboladdExternalRef (const Address &addr, const Address &refaddr, const string &nm)
 
LabSymboladdCodeLabel (const Address &addr, const string &nm)
 Create a code label at the given address in this Scope. More...
 
SymboladdDynamicSymbol (const string &nm, Datatype *ct, const Address &caddr, uint8 hash)
 Create a dynamically mapped Symbol attached to a specific data-flow. More...
 
SymboladdEquateSymbol (const string &nm, uint4 format, uintb value, const Address &addr, uint8 hash)
 Create a symbol that forces display conversion on a constant. More...
 
SymboladdUnionFacetSymbol (const string &nm, Datatype *dt, int4 fieldNum, const Address &addr, uint8 hash)
 Create a symbol forcing a field interpretation for a specific access to a variable with union data-type. 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.
 

Private Member Functions

bool adjustFit (RangeHint &a) const
 Make the given RangeHint fit in the current Symbol map. More...
 
void createEntry (const RangeHint &a)
 Create a Symbol entry corresponding to the given (fitted) RangeHint. More...
 
bool restructure (MapState &state)
 Merge hints into a formal Symbol layout of the address space. More...
 
void markUnaliased (const vector< uintb > &alias)
 Mark all local symbols for which there are no aliases. More...
 
void fakeInputSymbols (void)
 Make sure all stack inputs have an associated Symbol. More...
 
void addRecommendName (Symbol *sym)
 Convert the given symbol to a name recommendation. More...
 
void collectNameRecs (void)
 Collect names of unlocked Symbols on the stack. More...
 
void annotateRawStackPtr (void)
 Generate placeholder PTRSUB off of stack pointer. More...
 

Private Attributes

AddrSpacespace
 Address space containing the local stack.
 
list< NameRecommendnameRecommend
 Symbol name recommendations for specific addresses.
 
list< DynamicRecommenddynRecommend
 Symbol name recommendations for dynamic locations.
 
list< TypeRecommendtypeRecommend
 Data-types for specific storage locations.
 
uintb minParamOffset
 Minimum offset of parameter passed (to a called function) on the stack.
 
uintb maxParamOffset
 Maximum offset of parameter passed (to a called function) on the stack.
 
bool stackGrowsNegative
 Marked true if the stack is considered to grow towards smaller offsets.
 
bool rangeLocked
 True if the subset of addresses mapped to this scope has been locked.
 

Additional Inherited Members

- Protected Member Functions inherited from ghidra::ScopeInternal
virtual ScopebuildSubScope (uint8 id, const string &nm)
 Build an unattached Scope to be associated as a sub-scope of this.
 
virtual void addSymbolInternal (Symbol *sym)
 Put a Symbol into the name map. More...
 
virtual SymbolEntryaddMapInternal (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. More...
 
virtual SymbolEntryaddDynamicMapInternal (Symbol *sym, uint4 exfl, uint8 hash, int4 off, int4 sz, const RangeList &uselim)
 Create a new SymbolEntry for a Symbol given a dynamic hash. More...
 
- Protected Member Functions inherited from ghidra::Scope
const RangeListgetRangeTree (void) const
 Access the address ranges owned by this Scope.
 
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...
 
SymbolEntryaddMap (SymbolEntry &entry)
 Integrate a SymbolEntry into the range maps. More...
 
void setSymbolId (Symbol *sym, uint8 id) const
 Adjust the id associated with a symbol.
 
void setDisplayName (const string &nm)
 Change name displayed in output.
 
- Static Protected Member Functions inherited from ghidra::Scope
static const ScopestackAddr (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 ScopestackContainer (const Scope *scope1, const Scope *scope2, const Address &addr, int4 size, const Address &usepoint, SymbolEntry **addrmatch)
 
static const ScopestackClosestFit (const Scope *scope1, const Scope *scope2, const Address &addr, int4 size, const Address &usepoint, SymbolEntry **addrmatch)
 
static const ScopestackFunction (const Scope *scope1, const Scope *scope2, const Address &addr, Funcdata **addrmatch)
 
static const ScopestackExternalRef (const Scope *scope1, const Scope *scope2, const Address &addr, ExternRefSymbol **addrmatch)
 
static const ScopestackCodeLabel (const Scope *scope1, const Scope *scope2, const Address &addr, LabSymbol **addrmatch)
 
- Protected Attributes inherited from ghidra::ScopeInternal
SymbolNameTree nametree
 The set of Symbol objects, sorted by name.
 
vector< EntryMap * > maptable
 Rangemaps of SymbolEntry, one map for each address space.
 
vector< vector< Symbol * > > category
 References to Symbol objects organized by category.
 
list< SymbolEntrydynamicentry
 Dynamic symbol entries.
 
SymbolNameTree multiEntrySet
 Set of symbols with multiple entries.
 
uint8 nextUniqueId
 Next available symbol id.
 
- Protected Attributes inherited from ghidra::Scope
Architectureglb
 Architecture of this scope.
 
string name
 Name of this scope.
 
string displayName
 Name to display in output.
 
Funcdatafd
 (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.
 

Detailed Description

A Symbol scope for local variables of a particular function.

This acts like any other variable Scope, but is associated with a specific function and the address space where the function maps its local variables and parameters, typically the stack space. This object in addition to managing the local Symbols, builds up information about the stack address space: what portions of it are used for mapped local variables, what portions are used for temporary storage (not mapped), and what portion is for parameters.

Constructor & Destructor Documentation

◆ ScopeLocal()

ghidra::ScopeLocal::ScopeLocal ( uint8  id,
AddrSpace spc,
Funcdata fd,
Architecture g 
)

Constructor.

Parameters
idis the globally unique id associated with the function scope
spcis the (stack) address space associated with this function's local variables
fdis the function associated with these local variables
gis the Architecture

References maxParamOffset, minParamOffset, rangeLocked, ghidra::Scope::restrictScope(), space, and stackGrowsNegative.

Member Function Documentation

◆ addRecommendName()

void ghidra::ScopeLocal::addRecommendName ( Symbol sym)
private

Convert the given symbol to a name recommendation.

The symbol is stored as a name recommendation and then removed from the scope. Name recommendations are associated either with a storage address and usepoint, or a dynamic hash. The name may be reattached to a Symbol after decompilation.

Parameters
symis the given Symbol to treat as a name recommendation

References ghidra::RangeList::empty(), ghidra::SymbolEntry::getAddr(), ghidra::Symbol::getCategory(), ghidra::Range::getFirst(), ghidra::RangeList::getFirstRange(), ghidra::SymbolEntry::getFirstUseAddress(), ghidra::Symbol::getFirstWholeMap(), ghidra::SymbolEntry::getHash(), ghidra::Symbol::getId(), ghidra::Symbol::getName(), ghidra::SymbolEntry::getSize(), ghidra::Range::getSpace(), ghidra::SymbolEntry::getUseLimit(), ghidra::SymbolEntry::isDynamic(), and ghidra::MapState::range.

Referenced by collectNameRecs().

◆ addTypeRecommendation()

void ghidra::ScopeLocal::addTypeRecommendation ( const Address addr,
Datatype dt 
)

Add a new data-type recommendation.

Associate a data-type with a particular storage address. If we see an input Varnode at this address, if no other info is available, the given data-type is applied.

Parameters
addris the storage address
dtis the given data-type

Referenced by collectNameRecs(), and ghidra::Funcdata::prepareThisPointer().

◆ adjustFit()

bool ghidra::ScopeLocal::adjustFit ( RangeHint a) const
private

Make the given RangeHint fit in the current Symbol map.

Shrink the RangeHint as necessary so that it fits in the mapped region of the Scope and doesn't overlap any other Symbols. If this is not possible, return false.

Parameters
ais the given RangeHint to fit
Returns
true if a valid adjustment was made

References ghidra::ScopeInternal::findOverlap(), ghidra::RangeHint::flags, ghidra::SymbolEntry::getAddr(), ghidra::Address::getOffset(), ghidra::Scope::getRangeTree(), ghidra::RangeList::longestFit(), ghidra::RangeHint::size, space, ghidra::RangeHint::start, and ghidra::Varnode::typelock.

◆ annotateRawStackPtr()

void ghidra::ScopeLocal::annotateRawStackPtr ( void  )
private

Generate placeholder PTRSUB off of stack pointer.

For any read of the input stack pointer by a non-additive p-code op, assume this constitutes a a zero offset reference into the stack frame. Replace the raw Varnode with the standard spacebase placeholder, PTRSUB(sp,#0), so that the data-type system can treat it as a reference.

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::Varnode::endDescend(), ghidra::Scope::fd, ghidra::Funcdata::findSpacebaseInput(), ghidra::PcodeOp::getEvalType(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::PcodeOp::getSlot(), ghidra::Funcdata::hasTypeRecoveryStarted(), ghidra::PcodeOp::isCall(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::newOpBefore(), ghidra::Funcdata::opSetInput(), space, and ghidra::PcodeOp::special.

◆ applyTypeRecommendations()

void ghidra::ScopeLocal::applyTypeRecommendations ( void  )

Try to apply recommended data-type information.

Run through the recommended list, search for an input Varnode matching the storage address and try to apply the data-type to it. Do not override existing type lock.

References ghidra::Datatype::getSize(), ghidra::MapState::iter, and ghidra::Varnode::updateType().

Referenced by ghidra::ActionInferTypes::apply().

◆ buildVariableName()

string ghidra::ScopeLocal::buildVariableName ( const Address addr,
const Address pc,
Datatype ct,
int4 &  index,
uint4  flags 
) const
virtual

Given an address and data-type, build a suitable generic symbol name.

Parameters
addris the given address
pcis the address at which the name is getting used
ctis a data-type used to inform the name
indexis a reference to an index used to make the name unique, which will be updated
flagsare boolean properties of the variable we need the name for
Returns
the new variable name

Reimplemented from ghidra::ScopeInternal.

References ghidra::Varnode::addrtied, ghidra::ScopeInternal::buildVariableName(), ghidra::AddrSpace::byteToAddress(), ghidra::Scope::fd, ghidra::Address::getAddrSize(), ghidra::Funcdata::getFuncProto(), ghidra::FuncProto::getLocalRange(), ghidra::AddrSpace::getName(), ghidra::Address::getOffset(), ghidra::Address::getSpace(), ghidra::AddrSpace::getWordSize(), ghidra::RangeList::inRange(), ghidra::ScopeInternal::makeNameUnique(), maxParamOffset, minParamOffset, ghidra::Varnode::persist, ghidra::Datatype::printNameBase(), space, and stackGrowsNegative.

◆ collectNameRecs()

void ghidra::ScopeLocal::collectNameRecs ( void  )
private

Collect names of unlocked Symbols on the stack.

Turn any symbols that are name locked but not type locked into name recommendations removing the symbol in the process. This allows the decompiler to decide on how the stack is layed out without forcing specific variables to mapped. But, if the decompiler does create a variable at the specific location, it will use the original name.

References addRecommendName(), addTypeRecommendation(), dynRecommend, ghidra::SymbolEntry::getAddr(), ghidra::Symbol::getFirstWholeMap(), ghidra::Datatype::getMetatype(), ghidra::Symbol::getType(), ghidra::Symbol::isNameLocked(), ghidra::Symbol::isThisPointer(), ghidra::Symbol::isTypeLocked(), nameRecommend, ghidra::ScopeInternal::nametree, ghidra::TYPE_PTR, and ghidra::TYPE_STRUCT.

Referenced by decode().

◆ createEntry()

void ghidra::ScopeLocal::createEntry ( const RangeHint a)
private

Create a Symbol entry corresponding to the given (fitted) RangeHint.

A name and final data-type is constructed for the RangeHint, and they are entered as a new Symbol into this scope.

Parameters
ais the given RangeHint to create a Symbol for

References ghidra::Scope::addSymbol(), ghidra::TypeFactory::concretize(), ghidra::Datatype::getSize(), ghidra::TypeFactory::getTypeArray(), ghidra::Scope::glb, ghidra::RangeHint::size, space, ghidra::RangeHint::start, ghidra::RangeHint::type, and ghidra::Architecture::types.

◆ fakeInputSymbols()

void ghidra::ScopeLocal::fakeInputSymbols ( void  )
private

Make sure all stack inputs have an associated Symbol.

This assigns a Symbol to any input Varnode stored in our address space, which could be a parameter but isn't in the formal prototype of the function (these should already be in the scope marked as category '0').

References ghidra::LowlevelError::explain, ghidra::Symbol::function_parameter, ghidra::Varnode::getAddr(), ghidra::Symbol::getCategory(), ghidra::Address::getOffset(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Address::getSpace(), ghidra::Varnode::getSpace(), ghidra::SymbolEntry::getSymbol(), ghidra::Varnode::input, ghidra::Varnode::isTypeLock(), ghidra::MapState::iter, and ghidra::TYPE_UNKNOWN.

◆ isUnaffectedStorage()

bool ghidra::ScopeLocal::isUnaffectedStorage ( Varnode vn) const
inline

Is this a storage location for unaffected registers.

Parameters
vnis the Varnode storing an unaffected register
Returns
true is the Varnode can be used as unaffected storage

References ghidra::NameRecommend::addr, and ghidra::Varnode::getSpace().

Referenced by ghidra::ActionRestrictLocal::apply().

◆ isUnmappedUnaliased()

bool ghidra::ScopeLocal::isUnmappedUnaliased ( Varnode vn) const

Check if a given unmapped Varnode should be treated as unaliased.

Currently we treat all unmapped Varnodes as not having an alias, unless the Varnode is on the stack and the location is also used to pass parameters. This should not be called until the second pass, in order to give markNotMapped a chance to be called. Return true if the Varnode can be treated as having no aliases.

Parameters
vnis the given Varnode
Returns
true if there are no aliases

References ghidra::Varnode::getOffset(), ghidra::Varnode::getSpace(), maxParamOffset, minParamOffset, and space.

Referenced by ghidra::Funcdata::syncVarnodesWithSymbols().

◆ markNotMapped()

void ghidra::ScopeLocal::markNotMapped ( AddrSpace spc,
uintb  first,
int4  sz,
bool  parameter 
)

Mark a specific address range is not mapped.

The given range can no longer hold a mapped local variable. This indicates the range is being used for temporary storage.

Parameters
spcis the address space holding the given range
firstis the starting offset of the given range
szis the number of bytes in the range
parameteris true if the range is being used to store a sub-function parameter

References ghidra::Scope::fd, ghidra::ScopeInternal::findOverlap(), ghidra::Symbol::function_parameter, ghidra::Symbol::getCategory(), ghidra::Symbol::getFlags(), ghidra::AddrSpace::getHighest(), ghidra::Symbol::getName(), ghidra::SymbolEntry::getSymbol(), ghidra::Scope::glb, maxParamOffset, minParamOffset, ghidra::Database::removeRange(), ghidra::ScopeInternal::removeSymbol(), space, ghidra::Architecture::symboltab, ghidra::Varnode::typelock, and ghidra::Funcdata::warningHeader().

Referenced by ghidra::ActionRestrictLocal::apply(), and ghidra::FuncCallSpecs::buildInputFromTrials().

◆ markUnaliased()

void ghidra::ScopeLocal::markUnaliased ( const vector< uintb > &  alias)
private

Mark all local symbols for which there are no aliases.

Given a set of alias starting offsets, calculate whether each Symbol within this scope might be aliased by a pointer. The method uses locked Symbol information when available to determine how far an alias start might extend. Otherwise a heuristic is used to determine if the Symbol is far enough away from the start of the alias to be considered unaliased.

Parameters
aliasis the given set of alias starting offsets

References ghidra::rangemap< _recordtype >::begin_list(), ghidra::rangemap< _recordtype >::end_list(), ghidra::SymbolEntry::getAddr(), ghidra::Range::getFirst(), ghidra::Range::getLast(), ghidra::Datatype::getMetatype(), ghidra::Address::getOffset(), ghidra::Symbol::getScope(), ghidra::SymbolEntry::getSize(), ghidra::Range::getSpace(), ghidra::SymbolEntry::getSymbol(), ghidra::Symbol::getType(), ghidra::Symbol::isTypeLocked(), ghidra::MapState::iter, ghidra::Varnode::nolocalalias, ghidra::Scope::setAttribute(), ghidra::TYPE_ARRAY, and ghidra::TYPE_STRUCT.

◆ recoverNameRecommendationsForSymbols()

void ghidra::ScopeLocal::recoverNameRecommendationsForSymbols ( void  )

Run through name recommendations, checking if any match unnamed symbols.

Unlocked symbols that are presented to the decompiler are stored off as recommended names. These can be reattached after the decompiler makes a determination of what the final Symbols are. This method runs through the recommended names and checks if they can be applied to an existing unnamed Symbol.

References ghidra::Varnode::addrtied, ghidra::DynamicHash::clear(), ghidra::DynamicHash::findVarnode(), ghidra::SymbolEntry::getAddr(), ghidra::DynamicRecommend::getAddress(), ghidra::Symbol::getFirstWholeMap(), ghidra::Symbol::getFlags(), ghidra::DynamicRecommend::getHash(), ghidra::Varnode::getHigh(), ghidra::DynamicRecommend::getName(), ghidra::Symbol::getScope(), ghidra::SymbolEntry::getSize(), ghidra::SymbolEntry::getSymbol(), ghidra::HighVariable::getSymbol(), ghidra::DynamicRecommend::getSymbolId(), ghidra::Varnode::isAnnotation(), ghidra::Symbol::isNameUndefined(), ghidra::MapState::iter, and ghidra::Varnode::namelock.

Referenced by ghidra::ActionNameVars::apply().

◆ remapSymbol()

SymbolEntry * ghidra::ScopeLocal::remapSymbol ( Symbol sym,
const Address addr,
const Address usepoint 
)

Change the primary mapping for the given Symbol to be a specific storage address and use point.

Remove any other mapping and create a mapping based on the given storage.

Parameters
symis the given Symbol to remap
addris the starting address of the storage
usepointis the use point for the mapping
Returns
the new mapping

References ghidra::SymbolEntry::getAddr(), ghidra::SymbolEntry::getFirstUseAddress(), ghidra::Symbol::getFirstWholeMap(), ghidra::Address::getOffset(), ghidra::SymbolEntry::getSize(), ghidra::Address::getSpace(), ghidra::RangeList::insertRange(), ghidra::SymbolEntry::isDynamic(), ghidra::Address::isInvalid(), and ghidra::Varnode::mapped.

Referenced by ghidra::Funcdata::remapVarnode().

◆ remapSymbolDynamic()

SymbolEntry * ghidra::ScopeLocal::remapSymbolDynamic ( Symbol sym,
uint8  hash,
const Address usepoint 
)

Make the primary mapping for the given Symbol, dynamic.

Remove any other mapping and create a new dynamic mapping based on a given size and hash

Parameters
symis the given Symbol to remap
hashis the dynamic hash
usepointis the use point for the mapping
Returns
the new dynamic mapping

References ghidra::SymbolEntry::getFirstUseAddress(), ghidra::Symbol::getFirstWholeMap(), ghidra::SymbolEntry::getHash(), ghidra::Address::getOffset(), ghidra::SymbolEntry::getSize(), ghidra::Address::getSpace(), ghidra::RangeList::insertRange(), ghidra::SymbolEntry::isDynamic(), ghidra::Address::isInvalid(), and ghidra::Varnode::mapped.

Referenced by ghidra::Funcdata::remapDynamicVarnode().

◆ resetLocalWindow()

void ghidra::ScopeLocal::resetLocalWindow ( void  )

Reset the set of addresses that are considered mapped by the scope to the default.

This resets the discovery process for new local variables mapped to the scope's address space. Any analysis removing specific ranges from the mapped set (via markNotMapped()) is cleared.

References ghidra::Scope::fd, ghidra::Funcdata::getFuncProto(), ghidra::FuncProto::getLocalRange(), ghidra::FuncProto::getParamRange(), ghidra::Scope::glb, ghidra::FuncProto::isStackGrowsNegative(), maxParamOffset, minParamOffset, rangeLocked, ghidra::Database::setRange(), stackGrowsNegative, and ghidra::Architecture::symboltab.

Referenced by ghidra::Funcdata::clear(), ghidra::Funcdata::decode(), and ghidra::Funcdata::Funcdata().

◆ restructure()

bool ghidra::ScopeLocal::restructure ( MapState state)
private

Merge hints into a formal Symbol layout of the address space.

RangeHints from the given collection are merged into a definitive set of Symbols for this scope. Overlapping or open RangeHints are adjusted to form a disjoint cover of the mapped portion of the address space. Names for the disjoint cover elements are chosen, and these form the final Symbols.

Parameters
stateis the given collection of RangeHints
Returns
true if there were overlaps that could not be reconciled

References ghidra::RangeHint::attemptJoin(), ghidra::MapState::getNext(), ghidra::MapState::initialize(), ghidra::RangeHint::merge(), ghidra::MapState::next(), ghidra::RangeHint::open, ghidra::RangeHint::rangeType, ghidra::RangeHint::size, and ghidra::RangeHint::sstart.

◆ restructureHigh()

void ghidra::ScopeLocal::restructureHigh ( void  )

Layout mapped symbols based on HighVariable information.

Define stack Symbols based on HighVariables. This method is called once at the end of decompilation to create the final set of stack Symbols after all data-type propagation has settled. It creates a consistent data-type for all Varnode instances of a HighVariable.

References ghidra::MapState::gatherHighs(), and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::ActionRestructureHigh::apply().

◆ restructureVarnode()

void ghidra::ScopeLocal::restructureVarnode ( bool  aliasyes)

Layout mapped symbols based on Varnode information.

Define stack Symbols based on Varnodes. This method can be called repeatedly during decompilation. It helps propagate data-types. Unaliased symbols can optionally be marked to facilitate removal of INDIRECT ops, but this is generally done later in the process.

Parameters
aliasyesis true if unaliased Symbols should be marked

References ghidra::MapState::gatherVarnodes(), and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::ActionRestructureVarnode::apply().


The documentation for this class was generated from the following files: