decompiler  1.0.0
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
HighVariable Class Reference

A high-level variable modeled as a list of low-level variables, each written once. More...

#include <variable.hh>

Public Types

enum  { flagsdirty = 1, typedirty = 2, coverdirty = 4 }
 Dirtiness flags for a HighVariable. More...
 

Public Member Functions

 HighVariable (Varnode *vn)
 Construct a HighVariable with a single member Varnode. More...
 
DatatypegetType (void) const
 Get the data-type.
 
void setSymbol (Symbol *sym, int4 off) const
 Set the Symbol associated with this HighVariable. More...
 
SymbolgetSymbol (void) const
 Get the Symbol associated with this.
 
int4 getSymbolOffset (void) const
 Get the Symbol offset associated with this.
 
int4 numInstances (void) const
 Get the number of member Varnodes this has.
 
VarnodegetInstance (int4 i) const
 Get the i-th member Varnode.
 
void flagsDirty (void) const
 Mark the boolean properties as dirty.
 
void coverDirty (void) const
 Mark the cover as dirty.
 
void typeDirty (void) const
 Mark the data-type as dirty.
 
void remove (Varnode *vn)
 Remove a member Varnode from this. More...
 
void printCover (ostream &s) const
 Print details of the cover for this (for debug purposes) More...
 
void printInfo (ostream &s) const
 Print information about this HighVariable to stream. More...
 
bool hasName (void) const
 Check if this HighVariable can be named. More...
 
VarnodegetTiedVarnode (void) const
 Find the first address tied member Varnode. More...
 
VarnodegetInputVarnode (void) const
 Find (the) input member Varnode. More...
 
VarnodegetTypeRepresentative (void) const
 Get a member Varnode with the strongest data-type. More...
 
VarnodegetNameRepresentative (void) const
 Get a member Varnode that dictates the naming of this HighVariable. More...
 
void merge (HighVariable *tv2, bool isspeculative)
 Merge another HighVariable into this. More...
 
bool isMapped (void) const
 Return true if this is mapped.
 
bool isPersist (void) const
 Return true if this is a global variable.
 
bool isAddrTied (void) const
 Return true if this is address ties.
 
bool isInput (void) const
 Return true if this is an input variable.
 
bool isImplied (void) const
 Return true if this is an implied variable.
 
bool isSpacebase (void) const
 Return true if this is a spacebase.
 
bool isConstant (void) const
 Return true if this is a constant.
 
bool isUnaffected (void) const
 Return true if this is an unaffected register.
 
bool isExtraOut (void) const
 Return true if this is an extra output.
 
void setMark (void) const
 Set the mark on this variable.
 
void clearMark (void) const
 Clear the mark on this variable.
 
bool isMark (void) const
 Return true if this is marked.
 
bool hasCover (void) const
 Determine if this HighVariable has an associated cover. More...
 
bool isUnattached (void) const
 Return true if this has no member Varnode.
 
bool isTypeLock (void) const
 Return true if this is typelocked.
 
bool isNameLock (void) const
 Return true if this is namelocked.
 

Static Public Member Functions

static bool compareName (Varnode *vn1, Varnode *vn2)
 Determine which given Varnode is most nameable. More...
 
static bool compareJustLoc (const Varnode *a, const Varnode *b)
 Compare based on storage location. More...
 

Private Member Functions

int4 instanceIndex (const Varnode *vn) const
 Find the index of a specific Varnode member. More...
 
void updateFlags (void) const
 (Re)derive boolean properties of this from the member Varnodes More...
 
void updateCover (void) const
 (Re)derive the cover of this from the member Varnodes More...
 
void updateType (void) const
 (Re)derive the data-type for this from the member Varnodes More...
 

Private Attributes

vector< Varnode * > inst
 The member Varnode objects making up this HighVariable.
 
int4 numMergeClasses
 Number of different speculative merge classes in this.
 
uint4 highflags
 Dirtiness flags.
 
uint4 flags
 Boolean properties inherited from Varnode members.
 
Datatypetype
 The data-type for this.
 
Cover wholecover
 The ranges of code addresses covered by this HighVariable.
 
Symbolsymbol
 The Symbol this HighVariable is tied to.
 
int4 symboloffset
 -1=perfect symbol match >=0, offset
 

Friends

class Merge
 

Detailed Description

A high-level variable modeled as a list of low-level variables, each written once.

In the Static Single Assignment (SSA) representation of a function's data-flow, the Varnode object represents a variable node. This is a low-level variable: it is written to at most once, and there is 1 or more reads. A high-level variable, in the source language may be written to multiple times. We model this idea as a list of Varnode objects, where a different Varnode holds the value of the variable for different parts of the code. The range(s) of code for which a single Varnode holds the high-level variable's value is the cover or range of that Varnode and is modeled by the class Cover. Within a high-level variable, HighVariable, the covers of member Varnode objects should not intersect, as that represents the variable holding two or more different values at the same place in the code. The HighVariable inherits a cover which is the union of the covers of its Varnodes.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Dirtiness flags for a HighVariable.

The HighVariable inherits its Cover, its data-type, and other boolean properties from its Varnodes. The object holds these explicitly, but the values may become stale as the data-flow transforms. So we keep track of when these inherited values are dirty

Enumerator
flagsdirty 

Boolean properties for the HighVariable are dirty.

typedirty 

The data-type for the HighVariable is dirty.

coverdirty 

The cover for the HighVariable is dirty.

Constructor & Destructor Documentation

◆ HighVariable()

HighVariable::HighVariable ( Varnode vn)

Construct a HighVariable with a single member Varnode.

The new instance starts off with no associate Symbol and all properties marked as dirty.

Parameters
vnis the single Varnode member

References coverdirty, flags, flagsdirty, highflags, inst, numMergeClasses, Varnode::setHigh(), symbol, symboloffset, type, and typedirty.

Member Function Documentation

◆ compareJustLoc()

bool HighVariable::compareJustLoc ( const Varnode a,
const Varnode b 
)
static

Compare based on storage location.

Compare two Varnode objects based just on their storage address

Parameters
ais the first Varnode to compare
bis the second Varnode
Returns
true if the first Varnode should be ordered before the second

References Varnode::getAddr().

Referenced by merge(), and remove().

◆ compareName()

bool HighVariable::compareName ( Varnode vn1,
Varnode vn2 
)
static

Determine which given Varnode is most nameable.

Given two Varnode (members), sort them based on naming properties:

Returns
true if the second Varnode's name would override the first's

References Varnode::getDef(), Varnode::getSpace(), PcodeOp::getTime(), AddrSpace::getType(), IPTR_INTERNAL, Varnode::isAddrTied(), Varnode::isInput(), Varnode::isNameLock(), Varnode::isPersist(), Varnode::isUnaffected(), and Varnode::isWritten().

Referenced by getNameRepresentative().

◆ getInputVarnode()

Varnode * HighVariable::getInputVarnode ( void  ) const

Find (the) input member Varnode.

This should only be called if isInput() returns true. If there is no input member, this will throw an exception.

Returns
the input Varnode member

References inst, and isInput().

Referenced by hasName(), and Merge::mergeTestAdjacent().

◆ getNameRepresentative()

Varnode * HighVariable::getNameRepresentative ( void  ) const

Get a member Varnode that dictates the naming of this HighVariable.

Members are scored based the properties that are most dominating in choosing a name.

Returns
the highest scoring Varnode member

References compareName(), and inst.

Referenced by ActionNameVars::apply(), PrintLanguage::pushVnExplicit(), PrintLanguage::pushVnLHS(), and Funcdata::saveXmlHigh().

◆ getTiedVarnode()

Varnode * HighVariable::getTiedVarnode ( void  ) const

Find the first address tied member Varnode.

This should only be called if isAddrTied() returns true. If there is no address tied member, this will throw an exception.

Returns
the first address tied member

References inst, and isAddrTied().

Referenced by ActionCopyMarker::apply(), and Merge::mergeTestRequired().

◆ getTypeRepresentative()

Varnode * HighVariable::getTypeRepresentative ( void  ) const

Get a member Varnode with the strongest data-type.

Using Datatype::typeOrder, find the member Varnode with the most specific data-type.

Returns
the representative member

References Varnode::getType(), inst, Varnode::isTypeLock(), and Datatype::typeOrder().

Referenced by updateType().

◆ hasCover()

bool HighVariable::hasCover ( void  ) const
inline

Determine if this HighVariable has an associated cover.

Constant and annotation variables do not have a cover

Returns
true if this has a cover

References Varnode::annotation, Varnode::constant, flags, Varnode::insert, and updateFlags().

Referenced by Merge::mergeTest(), and updateCover().

◆ hasName()

bool HighVariable::hasName ( void  ) const

Check if this HighVariable can be named.

All Varnode objects are assigned a HighVariable, including those that don't get names like indirect variables, constants, and annotations. Determine if this, as inherited from its member Varnodes, can have a name.

Returns
true if this can have a name

References getInputVarnode(), Varnode::hasCover(), inst, Varnode::isIllegalInput(), Varnode::isImplied(), Varnode::isIndirectOnly(), isInput(), Varnode::isSpacebase(), and isUnaffected().

Referenced by ActionNameVars::apply().

◆ instanceIndex()

int4 HighVariable::instanceIndex ( const Varnode vn) const
private

Find the index of a specific Varnode member.

Find the index, for use with getInstance(), that will retrieve the given Varnode member

Parameters
vnis the given Varnode member
Returns
the index of the member or -1 if it is not a member

References inst.

◆ merge()

void HighVariable::merge ( HighVariable tv2,
bool  isspeculative 
)

Merge another HighVariable into this.

The lists of members are merged and the other HighVariable is deleted.

Parameters
tv2is the other HighVariable to merge into this
isspeculativeis true to keep the new members in separate merge classes

References compareJustLoc(), coverdirty, flagsdirty, Varnode::getMergeGroup(), highflags, inst, Cover::merge(), numMergeClasses, Varnode::setHigh(), typedirty, and wholecover.

Referenced by Merge::merge().

◆ printCover()

void HighVariable::printCover ( ostream &  s) const
inline

Print details of the cover for this (for debug purposes)

Parameters
sis the output stream

References coverdirty, highflags, Cover::print(), and wholecover.

◆ printInfo()

void HighVariable::printInfo ( ostream &  s) const

Print information about this HighVariable to stream.

This is generally used for debug purposes.

Parameters
sis the output stream

References Varnode::getMergeGroup(), Symbol::getName(), inst, Varnode::printInfo(), Datatype::printRaw(), symbol, symboloffset, type, and updateType().

◆ remove()

void HighVariable::remove ( Varnode vn)

Remove a member Varnode from this.

Search for the given Varnode and cut it out of the list, marking all properties as dirty.

Parameters
vnis the given Varnode member to remove

References compareJustLoc(), coverdirty, flagsdirty, highflags, inst, and typedirty.

Referenced by Varnode::~Varnode().

◆ setSymbol()

void HighVariable::setSymbol ( Symbol sym,
int4  off 
) const
inline

Set the Symbol associated with this HighVariable.

This HighVariable does not need to be associated with the whole symbol. It can be associated with a part, like a sub-field, if the size of the member Varnodes and the Symbol don't match. In this case a non-zero offset may be passed in with the Symbol to indicate what part is represented by the this.

Parameters
symis the Symbol to associate with this
offis the offset in bytes, relative to the Symbol, where this HighVariable starts

References symbol, and symboloffset.

Referenced by ActionDynamicSymbols::apply(), Funcdata::buildDynamicSymbol(), and Funcdata::linkSymbol().

◆ updateCover()

void HighVariable::updateCover ( void  ) const
private

(Re)derive the cover of this from the member Varnodes

Only update if the cover is marked as dirty. Merge the covers of all Varnode instances. This is only called by the Merge class which knows when to call it properly.

References Cover::clear(), coverdirty, hasCover(), highflags, inst, Cover::merge(), and wholecover.

Referenced by Merge::merge(), and Merge::updateHigh().

◆ updateFlags()

void HighVariable::updateFlags ( void  ) const
private

(Re)derive boolean properties of this from the member Varnodes

Only update if flags are marked as dirty. Generally if any member Varnode possesses the property, this HighVariable should inherit it. The Varnode::typelock field is not set here, but in updateType().

References Varnode::directwrite, flags, flagsdirty, highflags, inst, Varnode::mark, and Varnode::typelock.

Referenced by hasCover(), isAddrTied(), isConstant(), isExtraOut(), isImplied(), isInput(), isMapped(), isNameLock(), isPersist(), isSpacebase(), and isUnaffected().

◆ updateType()

void HighVariable::updateType ( void  ) const
private

(Re)derive the data-type for this from the member Varnodes

Only update if the data-type is marked as dirty. Get the most locked, most specific data-type from member Varnode objects.

References flags, Varnode::getType(), getTypeRepresentative(), highflags, Varnode::isTypeLock(), type, typedirty, and Varnode::typelock.

Referenced by getType(), isTypeLock(), and printInfo().


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