decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
VarnodeBank Class Reference

A container for Varnode objects from a specific function. More...

#include <varnode.hh>

Public Member Functions

 VarnodeBank (AddrSpaceManager *m, AddrSpace *uspace, uintm ubase)
 Construct the container. More...
 
void clear (void)
 Clear out all Varnodes and reset counters.
 
 ~VarnodeBank (void)
 Destructor.
 
int4 numVarnodes (void) const
 Get number of Varnodes this contains.
 
Varnodecreate (int4 s, const Address &m, Datatype *ct)
 Create a free Varnode object. More...
 
VarnodecreateDef (int4 s, const Address &m, Datatype *ct, PcodeOp *op)
 Create a Varnode as the output of a PcodeOp. More...
 
VarnodecreateUnique (int4 s, Datatype *ct)
 Create a temporary varnode. More...
 
VarnodecreateDefUnique (int4 s, Datatype *ct, PcodeOp *op)
 Create a temporary Varnode as output of a PcodeOp. More...
 
void destroy (Varnode *vn)
 Remove a Varnode from the container. More...
 
VarnodesetInput (Varnode *vn)
 Mark a Varnode as an input to the function. More...
 
VarnodesetDef (Varnode *vn, PcodeOp *op)
 Change Varnode to be defined by the given PcodeOp. More...
 
void makeFree (Varnode *vn)
 Convert a Varnode to be free. More...
 
void replace (Varnode *oldvn, Varnode *newvn)
 Replace every read of one Varnode with another. More...
 
Varnodefind (int4 s, const Address &loc, const Address &pc, uintm uniq=~((uintm) 0)) const
 Find a Varnode. More...
 
VarnodefindInput (int4 s, const Address &loc) const
 Find an input Varnode. More...
 
VarnodefindCoveredInput (int4 s, const Address &loc) const
 Find an input Varnode contained within this range. More...
 
VarnodefindCoveringInput (int4 s, const Address &loc) const
 Find an input Varnode covering a range. More...
 
uint4 getCreateIndex (void) const
 Get the next creation index to be assigned.
 
VarnodeLocSet::const_iterator beginLoc (void) const
 Beginning of location list.
 
VarnodeLocSet::const_iterator endLoc (void) const
 End of location list.
 
VarnodeLocSet::const_iterator beginLoc (AddrSpace *spaceid) const
 Beginning of Varnodes in given address space sorted by location. More...
 
VarnodeLocSet::const_iterator endLoc (AddrSpace *spaceid) const
 Ending of Varnodes in given address space sorted by location. More...
 
VarnodeLocSet::const_iterator beginLoc (const Address &addr) const
 Beginning of Varnodes starting at a given address sorted by location. More...
 
VarnodeLocSet::const_iterator endLoc (const Address &addr) const
 End of Varnodes starting at a given address sorted by location. More...
 
VarnodeLocSet::const_iterator beginLoc (int4 s, const Address &addr) const
 Beginning of Varnodes of given size and starting address sorted by location. More...
 
VarnodeLocSet::const_iterator endLoc (int4 s, const Address &addr) const
 End of Varnodes of given size and starting address sorted by location. More...
 
VarnodeLocSet::const_iterator beginLoc (int4 s, const Address &addr, uint4 fl) const
 Beginning of Varnodes sorted by location. More...
 
VarnodeLocSet::const_iterator endLoc (int4 s, const Address &addr, uint4 fl) const
 End of Varnodes sorted by location. More...
 
VarnodeLocSet::const_iterator beginLoc (int4 s, const Address &addr, const Address &pc, uintm uniq) const
 Beginning of Varnodes sorted by location. More...
 
VarnodeLocSet::const_iterator endLoc (int4 s, const Address &addr, const Address &pc, uintm uniq) const
 End of Varnodes sorted by location. More...
 
VarnodeDefSet::const_iterator beginDef (void) const
 Beginning of Varnodes sorted by definition.
 
VarnodeDefSet::const_iterator endDef (void) const
 End of Varnodes sorted by definition.
 
VarnodeDefSet::const_iterator beginDef (uint4 fl) const
 Beginning of varnodes with set definition property. More...
 
VarnodeDefSet::const_iterator endDef (uint4 fl) const
 End of varnodes with set definition property. More...
 
VarnodeDefSet::const_iterator beginDef (uint4 fl, const Address &addr) const
 Beginning of varnodes starting at a given address with a set definition property. More...
 
VarnodeDefSet::const_iterator endDef (uint4 fl, const Address &addr) const
 End of varnodes starting at a given address with a set definition property. More...
 

Private Member Functions

Varnodexref (Varnode *vn)
 Insert a Varnode into the sorted lists. More...
 

Private Attributes

AddrSpaceManagermanage
 Underlying address space manager.
 
AddrSpaceuniq_space
 Space to allocate unique varnodes from.
 
uintm uniqbase
 Base for unique addresses.
 
uintm uniqid
 Counter for generating unique offsets.
 
uint4 create_index
 Number of varnodes created.
 
VarnodeLocSet loc_tree
 Varnodes sorted by location then def.
 
VarnodeDefSet def_tree
 Varnodes sorted by def then location.
 
Varnode searchvn
 Template varnode for searching trees.
 

Detailed Description

A container for Varnode objects from a specific function.

The API allows the creation, deletion, search, and iteration of Varnode objects from one function. The class maintains two ordering for efficiency:

Constructor & Destructor Documentation

VarnodeBank::VarnodeBank ( AddrSpaceManager m,
AddrSpace uspace,
uintm  ubase 
)

Construct the container.

Parameters
mis the underlying address space manager
uspaceis the unique space
ubaseis the base offset for allocating temporaries

References create_index, Varnode::flags, Varnode::input, manage, searchvn, uniq_space, uniqbase, and uniqid.

Member Function Documentation

VarnodeDefSet::const_iterator VarnodeBank::beginDef ( uint4  fl) const

Beginning of varnodes with set definition property.

Get an iterator to Varnodes in definition order restricted with the following properties:

  • Varnode::input for Varnodes which are inputs to the function
  • Varnode::written for Varnodes that are defined by a PcodeOp
  • 0 for free Varnodes
    Parameters
    flis the property restriction
    Returns
    the beginning iterator

References Varnode::def, def_tree, Varnode::flags, Varnode::input, Varnode::loc, Address::m_maximal, Address::m_minimal, searchvn, and Varnode::written.

VarnodeDefSet::const_iterator VarnodeBank::beginDef ( uint4  fl,
const Address addr 
) const

Beginning of varnodes starting at a given address with a set definition property.

Get an iterator to Varnodes in definition order. The starting address of the Varnodes must match the given address, and they are further restricted by the following properties:

  • Varnode::input for Varnodes which are inputs to the function
  • Varnode::written for Varnodes that are defined by a PcodeOp
  • 0 for free Varnodes
    Parameters
    flis the property restriction
    addris the given starting address
    Returns
    the beginning iterator

References def_tree, Varnode::flags, Varnode::input, Varnode::loc, searchvn, and Varnode::written.

VarnodeLocSet::const_iterator VarnodeBank::beginLoc ( AddrSpace spaceid) const

Beginning of Varnodes in given address space sorted by location.

Parameters
spaceidis the given address space
Returns
the beginning iterator

References Varnode::loc, loc_tree, and searchvn.

VarnodeLocSet::const_iterator VarnodeBank::beginLoc ( const Address addr) const

Beginning of Varnodes starting at a given address sorted by location.

Parameters
addris the given starting address
Returns
the beginning iterator

References Varnode::loc, loc_tree, and searchvn.

VarnodeLocSet::const_iterator VarnodeBank::beginLoc ( int4  s,
const Address addr 
) const

Beginning of Varnodes of given size and starting address sorted by location.

Parameters
sis the given size
addris the given starting address
Returns
the beginning iterator

References Varnode::loc, loc_tree, searchvn, and Varnode::size.

VarnodeLocSet::const_iterator VarnodeBank::beginLoc ( int4  s,
const Address addr,
uint4  fl 
) const

Beginning of Varnodes sorted by location.

Varnodes are restricted by a given size and location and by the property

  • Varnode::input for Varnodes that are inputs to the function
  • Varnode::written for Varnodes that are defined by a PcodeOp
  • 0 for free Varnodes
    Parameters
    sis the given size
    addris the given starting address
    flis the property restriction
    Returns
    the beginning iterator

References Varnode::def, Varnode::flags, Varnode::input, Varnode::loc, loc_tree, Address::m_maximal, Address::m_minimal, searchvn, Varnode::size, and Varnode::written.

VarnodeLocSet::const_iterator VarnodeBank::beginLoc ( int4  s,
const Address addr,
const Address pc,
uintm  uniq 
) const

Beginning of Varnodes sorted by location.

Varnodes are restricted by a given size and location and by the sequence number of the PcodeOp defining it

Parameters
sis the given size
addris the given starting address
pcis the address of the PcodeOp defining the Varnode
uniqis the sequence number of the PcodeOp or -1 for now sequence number restriction
Returns
the beginning iterator

References Varnode::def, Varnode::flags, Varnode::input, Varnode::loc, loc_tree, searchvn, Varnode::size, and Varnode::written.

Varnode * VarnodeBank::create ( int4  s,
const Address m,
Datatype ct 
)

Create a free Varnode object.

The Varnode is created and inserted into the maps as free: not defined as the output of a p-code op or the input to a function.

Parameters
sis the size of the Varnode in bytes
mis the starting address
ctis the data-type of the new varnode (must not be NULL)
Returns
the newly allocated Varnode object

References Varnode::create_index, create_index, def_tree, Varnode::defiter, loc_tree, and Varnode::lociter.

Referenced by Funcdata::cloneVarnode(), createUnique(), Funcdata::newCodeRef(), Funcdata::newConstant(), Funcdata::newVarnode(), Funcdata::newVarnodeCallSpecs(), Funcdata::newVarnodeIop(), and Funcdata::newVarnodeSpace().

Varnode * VarnodeBank::createDef ( int4  s,
const Address m,
Datatype ct,
PcodeOp op 
)

Create a Varnode as the output of a PcodeOp.

The new Varnode object will already be put in the definition list as if it were the output of the given PcodeOp. The Varnode must still be set as the output.

Parameters
sis the size in bytes
mis the starting address
ctis the data-type to associate
opis the given PcodeOp

References Varnode::create_index, create_index, Varnode::setDef(), and xref().

Referenced by createDefUnique(), and Funcdata::newVarnodeOut().

Varnode * VarnodeBank::createDefUnique ( int4  s,
Datatype ct,
PcodeOp op 
)

Create a temporary Varnode as output of a PcodeOp.

The new Varnode will be assigned from the unique space, and it will already be put in the definition list as if it were the output of the given PcodeOp. The Varnode must still be set as the output.

Parameters
sis the size in bytes
ctis the data-type to associate
opis the given PcodeOp

References createDef(), uniq_space, and uniqid.

Referenced by Funcdata::newUniqueOut().

Varnode * VarnodeBank::createUnique ( int4  s,
Datatype ct 
)

Create a temporary varnode.

The Varnode is allocated in the unique space and automatically assigned an offset. The Varnode is initially free.

Parameters
sis the size of the Varnode in bytes
ctis the data-type to assign (must not be NULL)

References create(), uniq_space, and uniqid.

Referenced by Funcdata::newUnique().

void VarnodeBank::destroy ( Varnode vn)

Remove a Varnode from the container.

The Varnode object is removed from the sorted lists and its memory reclaimed

Parameters
vnis the Varnode to remove

References def_tree, Varnode::defiter, Varnode::getDef(), Varnode::hasNoDescend(), loc_tree, and Varnode::lociter.

Referenced by Funcdata::clearDeadVarnodes(), Funcdata::deleteVarnode(), and Funcdata::destroyVarnode().

VarnodeDefSet::const_iterator VarnodeBank::endDef ( uint4  fl) const

End of varnodes with set definition property.

Get an iterator to Varnodes in definition order restricted with the following properties:

  • Varnode::input for Varnodes which are inputs to the function
  • Varnode::written for Varnodes that are defined by a PcodeOp
  • 0 for free Varnodes
    Parameters
    flis the property restriction
    Returns
    the ending iterator

References Varnode::def, def_tree, Varnode::flags, Varnode::input, Varnode::loc, Address::m_maximal, Address::m_minimal, searchvn, and Varnode::written.

VarnodeDefSet::const_iterator VarnodeBank::endDef ( uint4  fl,
const Address addr 
) const

End of varnodes starting at a given address with a set definition property.

Get an iterator to Varnodes in definition order. The starting address of the Varnodes must match the given address, and they are further restricted by the following properties:

  • Varnode::input for Varnodes which are inputs to the function
  • Varnode::written for Varnodes that are defined by a PcodeOp
  • 0 for free Varnodes
    Parameters
    flis the property restriction
    addris the given starting address
    Returns
    the ending iterator

References def_tree, Varnode::flags, Varnode::input, Varnode::loc, loc_tree, searchvn, Varnode::size, and Varnode::written.

VarnodeLocSet::const_iterator VarnodeBank::endLoc ( AddrSpace spaceid) const

Ending of Varnodes in given address space sorted by location.

Parameters
spaceidis the given address space
Returns
the ending iterator

References AddrSpaceManager::getNextSpaceInOrder(), Varnode::loc, loc_tree, manage, and searchvn.

VarnodeLocSet::const_iterator VarnodeBank::endLoc ( const Address addr) const

End of Varnodes starting at a given address sorted by location.

Parameters
addris the given starting address
Returns
the ending iterator

References AddrSpace::getHighest(), AddrSpaceManager::getNextSpaceInOrder(), Address::getOffset(), Address::getSpace(), Varnode::loc, loc_tree, manage, and searchvn.

VarnodeLocSet::const_iterator VarnodeBank::endLoc ( int4  s,
const Address addr 
) const

End of Varnodes of given size and starting address sorted by location.

Parameters
sis the given size
addris the given starting address
Returns
the ending iterator

References Varnode::loc, loc_tree, searchvn, and Varnode::size.

VarnodeLocSet::const_iterator VarnodeBank::endLoc ( int4  s,
const Address addr,
uint4  fl 
) const

End of Varnodes sorted by location.

Varnodes are restricted by a given size and location and by the property

  • Varnode::input for Varnodes that are inputs to the function
  • Varnode::written for Varnodes that are defined by a PcodeOp
  • 0 for free Varnodes
    Parameters
    sis the given size
    addris the given starting address
    flis the property restriction
    Returns
    the ending iterator

References Varnode::def, Varnode::flags, Varnode::input, Varnode::loc, loc_tree, Address::m_maximal, searchvn, Varnode::size, and Varnode::written.

VarnodeLocSet::const_iterator VarnodeBank::endLoc ( int4  s,
const Address addr,
const Address pc,
uintm  uniq 
) const

End of Varnodes sorted by location.

Varnodes are restricted by a given size and location and by the sequence number of the PcodeOp defining it

Parameters
sis the given size
addris the given starting address
pcis the address of the PcodeOp defining the Varnode
uniqis the sequence number of the PcodeOp or -1 for now sequence number restriction
Returns
the ending iterator

References Varnode::def, Varnode::flags, Varnode::input, Varnode::loc, loc_tree, searchvn, Varnode::size, and Varnode::written.

Varnode * VarnodeBank::find ( int4  s,
const Address loc,
const Address pc,
uintm  uniq = ~((uintm)0) 
) const

Find a Varnode.

Find a Varnode given its (loc,size) and the address where it is defined.

Parameters
sis the size of the Varnode
locis its starting address
pcis the address where it is defined
uniqis the sequence number or -1 if not specified
Returns
the matching Varnode or NULL

References beginLoc(), PcodeOp::getAddr(), Varnode::getAddr(), Varnode::getDef(), Varnode::getSize(), PcodeOp::getTime(), and loc_tree.

Referenced by Funcdata::findVarnodeWritten().

Varnode * VarnodeBank::findCoveredInput ( int4  s,
const Address loc 
) const

Find an input Varnode contained within this range.

Find the first Varnode completely contained within the given range, which is also marked as a function input.

Parameters
sis the size of the range
locis the starting address of the range
Returns
the Varnode object or NULL if no Varnode met the conditions

References beginDef(), endDef(), AddrSpace::getHighest(), Address::getOffset(), Varnode::getOffset(), Varnode::getSize(), Address::getSpace(), and Varnode::input.

Referenced by Funcdata::findCoveredInput().

Varnode * VarnodeBank::findCoveringInput ( int4  s,
const Address loc 
) const

Find an input Varnode covering a range.

Search for the Varnode that completely contains the given range and is marked as an input to the function. If it exists, it is unique.

Parameters
sis the size of the range
locis the starting address of the range

References beginDef(), def_tree, Varnode::getAddr(), Address::getOffset(), Varnode::getOffset(), Varnode::getSize(), Address::getSpace(), Varnode::getSpace(), Varnode::input, and Varnode::isInput().

Referenced by Funcdata::findCoveringInput().

Varnode * VarnodeBank::findInput ( int4  s,
const Address loc 
) const

Find an input Varnode.

Find a Varnode marked as a function input given its size and address

Parameters
sis the size
locis the starting address
Returns
the match Varnode object or NULL

References beginLoc(), Varnode::getAddr(), Varnode::getSize(), Varnode::input, Varnode::isInput(), and loc_tree.

Referenced by Funcdata::findSpacebaseInput(), and Funcdata::findVarnodeInput().

void VarnodeBank::makeFree ( Varnode vn)

Convert a Varnode to be free.

The Varnode is removed from the cross-referencing lists and reinserted as as if it were not defined by any PcodeOp and not an input to the function. If the Varnode was originally a PcodeOp output, this must be explicitly cleared.

Parameters
vnis the Varnode to modify

References Varnode::clearFlags(), def_tree, Varnode::defiter, Varnode::indirect_creation, Varnode::input, Varnode::insert, loc_tree, Varnode::lociter, and Varnode::setDef().

Referenced by Funcdata::clearDeadVarnodes(), and Funcdata::opUnsetOutput().

void VarnodeBank::replace ( Varnode oldvn,
Varnode newvn 
)

Replace every read of one Varnode with another.

Any PcodeOps that read oldvn are changed to read newvn

Parameters
oldvnis the old Varnode
newvnis the Varnode to replace it with

References Varnode::addDescend(), PcodeOp::clearInput(), Varnode::coverdirty, Varnode::descend, PcodeOp::getSlot(), PcodeOp::output, Varnode::setFlags(), and PcodeOp::setInput().

Referenced by xref().

Varnode * VarnodeBank::setDef ( Varnode vn,
PcodeOp op 
)

Change Varnode to be defined by the given PcodeOp.

The Varnode must initially be free. It will be removed from the cross-referencing lists and reinserted as if its were the output of the given PcodeOp. It still must be explicitly set as the output.

Parameters
vnis the Varnode to modify
opis the given PcodeOp
Returns
the modified Varnode, which may be a different object than the original

References def_tree, Varnode::defiter, PcodeOp::getAddr(), Address::getShortcut(), Varnode::isConstant(), Varnode::isFree(), loc_tree, Varnode::lociter, Varnode::setDef(), and xref().

Referenced by Funcdata::opSetOutput().

Varnode * VarnodeBank::setInput ( Varnode vn)

Mark a Varnode as an input to the function.

Define the Varnode as an input formally; it is no longer considered free. Its position in the cross-referencing lists will change

Parameters
vnis the Varnode to mark
Returns
the modified Varnode, which be a different object than the original

References def_tree, Varnode::defiter, Varnode::isConstant(), Varnode::isFree(), loc_tree, Varnode::lociter, Varnode::setInput(), and xref().

Referenced by Funcdata::setInputVarnode().

Varnode * VarnodeBank::xref ( Varnode vn)
private

Insert a Varnode into the sorted lists.

Enter the Varnode into both the location and definition based trees. Update the Varnode iterators and flags

Parameters
vnis the Varnode object to insert
Returns
the inserted object, which may not be the same as the input Varnode

References def_tree, Varnode::defiter, Varnode::insert, loc_tree, Varnode::lociter, replace(), and Varnode::setFlags().

Referenced by createDef(), setDef(), and setInput().


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