decompiler
1.0.0
|
A container for Varnode objects from a specific function. More...
#include <varnode.hh>
Public Member Functions | |
VarnodeBank (AddrSpaceManager *m) | |
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. | |
Varnode * | create (int4 s, const Address &m, Datatype *ct) |
Create a free Varnode object. More... | |
Varnode * | createDef (int4 s, const Address &m, Datatype *ct, PcodeOp *op) |
Create a Varnode as the output of a PcodeOp. More... | |
Varnode * | createUnique (int4 s, Datatype *ct) |
Create a temporary varnode. More... | |
Varnode * | createDefUnique (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... | |
Varnode * | setInput (Varnode *vn) |
Mark a Varnode as an input to the function. More... | |
Varnode * | setDef (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... | |
Varnode * | find (int4 s, const Address &loc, const Address &pc, uintm uniq=~((uintm) 0)) const |
Find a Varnode. More... | |
Varnode * | findInput (int4 s, const Address &loc) const |
Find an input Varnode. More... | |
Varnode * | findCoveredInput (int4 s, const Address &loc) const |
Find an input Varnode contained within this range. More... | |
Varnode * | findCoveringInput (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... | |
uint4 | overlapLoc (VarnodeLocSet::const_iterator iter, vector< VarnodeLocSet::const_iterator > &bounds) const |
Given start, return maximal range of overlapping Varnodes. 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 | |
Varnode * | xref (Varnode *vn) |
Insert a Varnode into the sorted lists. More... | |
Private Attributes | |
AddrSpaceManager * | manage |
Underlying address space manager. | |
AddrSpace * | uniq_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. | |
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:
ghidra::VarnodeBank::VarnodeBank | ( | AddrSpaceManager * | m | ) |
Construct the container.
m | is the underlying address space manager |
References ghidra::Translate::ANALYSIS, create_index, ghidra::Varnode::flags, ghidra::AddrSpace::getTrans(), ghidra::AddrSpaceManager::getUniqueSpace(), ghidra::Translate::getUniqueStart(), ghidra::Varnode::input, manage, searchvn, uniq_space, uniqbase, and uniqid.
VarnodeDefSet::const_iterator ghidra::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:
fl | is the property restriction |
References ghidra::Varnode::def, def_tree, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, ghidra::Address::m_maximal, ghidra::Address::m_minimal, searchvn, and ghidra::Varnode::written.
VarnodeDefSet::const_iterator ghidra::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:
fl | is the property restriction |
addr | is the given starting address |
References def_tree, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, searchvn, and ghidra::Varnode::written.
VarnodeLocSet::const_iterator ghidra::VarnodeBank::beginLoc | ( | AddrSpace * | spaceid | ) | const |
Beginning of Varnodes in given address space sorted by location.
spaceid | is the given address space |
References ghidra::Varnode::loc, loc_tree, and searchvn.
VarnodeLocSet::const_iterator ghidra::VarnodeBank::beginLoc | ( | const Address & | addr | ) | const |
Beginning of Varnodes starting at a given address sorted by location.
addr | is the given starting address |
References ghidra::Varnode::loc, loc_tree, and searchvn.
VarnodeLocSet::const_iterator ghidra::VarnodeBank::beginLoc | ( | int4 | s, |
const Address & | addr | ||
) | const |
Beginning of Varnodes of given size and starting address sorted by location.
s | is the given size |
addr | is the given starting address |
References ghidra::Varnode::loc, loc_tree, searchvn, and ghidra::Varnode::size.
VarnodeLocSet::const_iterator ghidra::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
s | is the given size |
addr | is the given starting address |
fl | is the property restriction |
References ghidra::Varnode::def, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, loc_tree, ghidra::Address::m_maximal, ghidra::Address::m_minimal, searchvn, ghidra::Varnode::size, and ghidra::Varnode::written.
VarnodeLocSet::const_iterator ghidra::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
s | is the given size |
addr | is the given starting address |
pc | is the address of the PcodeOp defining the Varnode |
uniq | is the sequence number of the PcodeOp or -1 for now sequence number restriction |
References ghidra::Varnode::def, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, loc_tree, searchvn, ghidra::Varnode::size, and ghidra::Varnode::written.
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.
s | is the size of the Varnode in bytes |
m | is the starting address |
ct | is the data-type of the new varnode (must not be NULL) |
References ghidra::Varnode::create_index, create_index, def_tree, ghidra::Varnode::defiter, loc_tree, and ghidra::Varnode::lociter.
Referenced by ghidra::Funcdata::cloneVarnode(), createUnique(), ghidra::Funcdata::newCodeRef(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::newVarnode(), ghidra::Funcdata::newVarnodeCallSpecs(), ghidra::Funcdata::newVarnodeIop(), and ghidra::Funcdata::newVarnodeSpace().
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.
s | is the size in bytes |
m | is the starting address |
ct | is the data-type to associate |
op | is the given PcodeOp |
References ghidra::Varnode::create_index, create_index, ghidra::Varnode::setDef(), and xref().
Referenced by createDefUnique(), and ghidra::Funcdata::newVarnodeOut().
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.
s | is the size in bytes |
ct | is the data-type to associate |
op | is the given PcodeOp |
References createDef(), uniq_space, and uniqid.
Referenced by ghidra::Funcdata::newUniqueOut().
Create a temporary varnode.
The Varnode is allocated in the unique space and automatically assigned an offset. The Varnode is initially free.
s | is the size of the Varnode in bytes |
ct | is the data-type to assign (must not be NULL) |
References create(), uniq_space, and uniqid.
Referenced by ghidra::Funcdata::newUnique().
void ghidra::VarnodeBank::destroy | ( | Varnode * | vn | ) |
Remove a Varnode from the container.
The Varnode object is removed from the sorted lists and its memory reclaimed
vn | is the Varnode to remove |
References def_tree, ghidra::Varnode::defiter, ghidra::Varnode::getDef(), ghidra::Varnode::hasNoDescend(), loc_tree, and ghidra::Varnode::lociter.
Referenced by ghidra::Funcdata::clearDeadVarnodes(), ghidra::Funcdata::deleteVarnode(), and ghidra::Funcdata::destroyVarnode().
VarnodeDefSet::const_iterator ghidra::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:
fl | is the property restriction |
References ghidra::Varnode::def, def_tree, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, ghidra::Address::m_maximal, ghidra::Address::m_minimal, searchvn, and ghidra::Varnode::written.
VarnodeDefSet::const_iterator ghidra::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:
fl | is the property restriction |
addr | is the given starting address |
References def_tree, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, loc_tree, searchvn, ghidra::Varnode::size, and ghidra::Varnode::written.
VarnodeLocSet::const_iterator ghidra::VarnodeBank::endLoc | ( | AddrSpace * | spaceid | ) | const |
Ending of Varnodes in given address space sorted by location.
spaceid | is the given address space |
References ghidra::AddrSpaceManager::getNextSpaceInOrder(), ghidra::Varnode::loc, loc_tree, manage, and searchvn.
VarnodeLocSet::const_iterator ghidra::VarnodeBank::endLoc | ( | const Address & | addr | ) | const |
End of Varnodes starting at a given address sorted by location.
addr | is the given starting address |
References ghidra::AddrSpace::getHighest(), ghidra::AddrSpaceManager::getNextSpaceInOrder(), ghidra::Address::getOffset(), ghidra::Address::getSpace(), ghidra::Varnode::loc, loc_tree, manage, and searchvn.
VarnodeLocSet::const_iterator ghidra::VarnodeBank::endLoc | ( | int4 | s, |
const Address & | addr | ||
) | const |
End of Varnodes of given size and starting address sorted by location.
s | is the given size |
addr | is the given starting address |
References ghidra::Varnode::loc, loc_tree, searchvn, and ghidra::Varnode::size.
VarnodeLocSet::const_iterator ghidra::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
s | is the given size |
addr | is the given starting address |
fl | is the property restriction |
References ghidra::Varnode::def, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, loc_tree, ghidra::Address::m_maximal, searchvn, ghidra::Varnode::size, and ghidra::Varnode::written.
VarnodeLocSet::const_iterator ghidra::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
s | is the given size |
addr | is the given starting address |
pc | is the address of the PcodeOp defining the Varnode |
uniq | is the sequence number of the PcodeOp or -1 for now sequence number restriction |
References ghidra::Varnode::def, ghidra::Varnode::flags, ghidra::Varnode::input, ghidra::Varnode::loc, loc_tree, searchvn, ghidra::Varnode::size, and ghidra::Varnode::written.
Varnode * ghidra::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.
s | is the size of the Varnode |
loc | is its starting address |
pc | is the address where it is defined |
uniq | is the sequence number or -1 if not specified |
References beginLoc(), ghidra::PcodeOp::getAddr(), ghidra::Varnode::getAddr(), ghidra::Varnode::getDef(), ghidra::Varnode::getSize(), ghidra::PcodeOp::getTime(), and loc_tree.
Referenced by ghidra::Funcdata::findVarnodeWritten().
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.
s | is the size of the range |
loc | is the starting address of the range |
References beginDef(), endDef(), ghidra::AddrSpace::getHighest(), ghidra::Address::getOffset(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Address::getSpace(), and ghidra::Varnode::input.
Referenced by ghidra::Funcdata::findCoveredInput().
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.
s | is the size of the range |
loc | is the starting address of the range |
References beginDef(), def_tree, ghidra::Varnode::getAddr(), ghidra::Address::getOffset(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Address::getSpace(), ghidra::Varnode::getSpace(), ghidra::Varnode::input, and ghidra::Varnode::isInput().
Referenced by ghidra::Funcdata::findCoveringInput().
Find an input Varnode.
Find a Varnode marked as a function input given its size and address
s | is the size |
loc | is the starting address |
References beginLoc(), ghidra::Varnode::getAddr(), ghidra::Varnode::getSize(), ghidra::Varnode::input, ghidra::Varnode::isInput(), and loc_tree.
Referenced by ghidra::Funcdata::findSpacebaseInput(), and ghidra::Funcdata::findVarnodeInput().
void ghidra::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.
vn | is the Varnode to modify |
References ghidra::Varnode::clearFlags(), def_tree, ghidra::Varnode::defiter, ghidra::Varnode::indirect_creation, ghidra::Varnode::input, ghidra::Varnode::insert, loc_tree, ghidra::Varnode::lociter, and ghidra::Varnode::setDef().
Referenced by ghidra::Funcdata::clearDeadVarnodes(), and ghidra::Funcdata::opUnsetOutput().
uint4 ghidra::VarnodeBank::overlapLoc | ( | VarnodeLocSet::const_iterator | iter, |
vector< VarnodeLocSet::const_iterator > & | bounds | ||
) | const |
Given start, return maximal range of overlapping Varnodes.
Advance the iterator until no Varnodes after the iterator intersect any Varnodes from the initial Varnode through the current iterator. The range is returned as pairs of iterators to subranges. One subrange for each set of Varnodes with the same size and starting address. A final iterator to the next Varnode after the overlapping set is also passed back.
iter | is an iterator to the given start Varnode |
bounds | holds the array of iterator pairs passed back |
References endLoc(), ghidra::Varnode::getAddr(), ghidra::Varnode::getFlags(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Varnode::getSpace(), ghidra::Varnode::isFree(), loc_tree, and ghidra::Varnode::written.
Referenced by ghidra::Funcdata::overlapLoc().
Replace every read of one Varnode with another.
Any PcodeOps that read oldvn are changed to read newvn
References ghidra::Varnode::addDescend(), ghidra::PcodeOp::clearInput(), ghidra::Varnode::coverdirty, ghidra::Varnode::descend, ghidra::PcodeOp::getSlot(), ghidra::PcodeOp::output, ghidra::Varnode::setFlags(), and ghidra::PcodeOp::setInput().
Referenced by xref().
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.
References def_tree, ghidra::Varnode::defiter, ghidra::PcodeOp::getAddr(), ghidra::Address::getShortcut(), ghidra::Varnode::isConstant(), ghidra::Varnode::isFree(), loc_tree, ghidra::Varnode::lociter, ghidra::Varnode::setDef(), and xref().
Referenced by ghidra::Funcdata::opSetOutput().
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
vn | is the Varnode to mark |
References def_tree, ghidra::Varnode::defiter, ghidra::Varnode::isConstant(), ghidra::Varnode::isFree(), loc_tree, ghidra::Varnode::lociter, ghidra::Varnode::setInput(), and xref().
Referenced by ghidra::Funcdata::setInputVarnode().
Insert a Varnode into the sorted lists.
Enter the Varnode into both the location and definition based trees. Update the Varnode iterators and flags
vn | is the Varnode object to insert |
References def_tree, ghidra::Varnode::defiter, ghidra::Varnode::insert, loc_tree, ghidra::Varnode::lociter, replace(), and ghidra::Varnode::setFlags().
Referenced by createDef(), setDef(), and setInput().