Ghidra 11.3.2
Ghidra internal decompiler documentation.
|
A container for hints about the data-type layout of an address space. More...
#include <varmap.hh>
Public Member Functions | |
MapState (AddrSpace *spc, const RangeList &rn, const RangeList &pm, Datatype *dt) | |
Constructor. | |
~MapState (void) | |
Destructor. | |
bool | initialize (void) |
Initialize the hint collection for iteration. | |
void | sortAlias (void) |
Sort the alias starting offsets. | |
const vector< uintb > & | getAlias (void) |
Get the list of alias starting offsets. | |
void | gatherSymbols (const EntryMap *rangemap) |
Add Symbol information as hints to the collection. | |
void | gatherVarnodes (const Funcdata &fd) |
Add stack Varnodes as hints to the collection. | |
void | gatherOpen (const Funcdata &fd) |
Add pointer references as hints to the collection. | |
RangeHint * | next (void) |
Get the current RangeHint in the collection. | |
bool | getNext (void) |
Advance the iterator, return true if another hint is available. | |
Private Member Functions | |
void | addGuard (const LoadGuard &guard, OpCode opc, TypeFactory *typeFactory) |
Add LoadGuard record as a hint to the collection. | |
void | addRange (uintb st, Datatype *ct, uint4 fl, RangeHint::RangeType rt, int4 hi) |
Add a hint to the collection. | |
void | addFixedType (uintb start, Datatype *ct, uint4 flags, TypeFactory *types) |
Add a fixed reference to a specific data-type. | |
void | reconcileDatatypes (void) |
Decide on data-type for RangeHints at the same address. | |
Static Private Member Functions | |
static bool | isReadActive (Varnode *vn) |
Is the given Varnode read by an active operation. | |
Private Attributes | |
AddrSpace * | spaceid |
The address space being analyzed. | |
RangeList | range |
The subset of ranges, within the whole address space to analyze. | |
vector< RangeHint * > | maplist |
The list of collected RangeHints. | |
vector< RangeHint * >::iterator | iter |
The current iterator into the RangeHints. | |
Datatype * | defaultType |
The default data-type to use for RangeHints. | |
AliasChecker | checker |
A collection of pointer Varnodes into our address space. | |
A container for hints about the data-type layout of an address space.
A collection of data-type hints for the address space (as RangeHint objects) can be collected from Varnodes, HighVariables or other sources, using the gatherVarnodes(), gatherHighs(), and gatherOpen() methods. This class can then sort and iterate through the RangeHint objects.
ghidra::MapState::MapState | ( | AddrSpace * | spc, |
const RangeList & | rn, | ||
const RangeList & | pm, | ||
Datatype * | dt | ||
) |
spc | is the address space being analyzed |
rn | is the subset of addresses within the address space to analyze |
pm | is subset of ranges within the address space considered to be parameters |
dt | is the default data-type |
References ghidra::RangeList::begin(), defaultType, ghidra::RangeList::end(), range, ghidra::RangeList::removeRange(), and spaceid.
|
private |
Add a fixed reference to a specific data-type.
If the data-type is an array, partial struct, or partial union, the reference may be added as open.
start | is the starting offset of the range |
ct | is the data-type |
flags | indicates any boolean properties applied to the range |
types | is the TypeFactory used to construct unknown data-types |
References addRange(), ghidra::RangeHint::fixed, ghidra::TypeFactory::getBase(), ghidra::Datatype::getMetatype(), ghidra::TypePartialStruct::getOffset(), ghidra::TypePartialUnion::getOffset(), ghidra::TypePartialStruct::getParent(), ghidra::TypePartialUnion::getParentUnion(), ghidra::Datatype::getSize(), ghidra::RangeHint::open, ghidra::TYPE_ARRAY, ghidra::TYPE_PARTIALSTRUCT, ghidra::TYPE_PARTIALUNION, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNKNOWN.
Referenced by gatherVarnodes().
|
private |
Add LoadGuard record as a hint to the collection.
The given LoadGuard, which may be a LOAD or STORE, is converted into an appropriate RangeHint, attempting to make use of any data-type or index information.
guard | is the given LoadGuard |
opc | is the expected op-code (CPUI_LOAD or CPUI_STORE) |
typeFactory | is used to manufacture a data-type for the hint if necessary |
References addRange(), ghidra::CPUI_STORE, ghidra::Datatype::getAlignSize(), ghidra::TypeFactory::getBase(), ghidra::PcodeOp::getIn(), ghidra::LoadGuard::getMaximum(), ghidra::Datatype::getMetatype(), ghidra::LoadGuard::getMinimum(), ghidra::LoadGuard::getOp(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::LoadGuard::getStep(), ghidra::Varnode::getTypeReadFacing(), ghidra::LoadGuard::isRangeLocked(), ghidra::LoadGuard::isValid(), ghidra::RangeHint::open, ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, and ghidra::TYPE_UNKNOWN.
Referenced by gatherOpen().
|
private |
Add a hint to the collection.
A specific range of bytes is described for the hint, given a starting offset and other information. The size of range can be fixed or open-ended. A putative data-type can be provided.
st | is the starting offset of the range |
ct | is the (optional) data-type information, which may be NULL |
fl | is additional boolean properties |
rt | is the type of the hint |
hi | is the biggest guaranteed index for open range hints |
References ghidra::AddrSpace::addressToByte(), ghidra::AddrSpace::byteToAddress(), defaultType, ghidra::AddrSpace::getAddrSize(), ghidra::Datatype::getSize(), ghidra::AddrSpace::getWordSize(), ghidra::RangeList::inRange(), maplist, ghidra::Datatype::printRaw(), range, and spaceid.
Referenced by addFixedType(), addGuard(), gatherOpen(), and gatherSymbols().
void ghidra::MapState::gatherOpen | ( | const Funcdata & | fd | ) |
Add pointer references as hints to the collection.
For any Varnode that looks like a pointer into our address space, create an open RangeHint. The size of the object may not be known.
fd | is the given function |
References addGuard(), addRange(), checker, ghidra::CPUI_LOAD, ghidra::CPUI_STORE, ghidra::AliasChecker::gather(), ghidra::AliasChecker::getAddBase(), ghidra::AliasChecker::getAlias(), ghidra::Funcdata::getArch(), ghidra::Funcdata::getLoadGuards(), ghidra::Datatype::getMetatype(), ghidra::Funcdata::getStoreGuards(), ghidra::RangeHint::open, spaceid, ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, and ghidra::Architecture::types.
Referenced by ghidra::ScopeLocal::restructureVarnode().
void ghidra::MapState::gatherSymbols | ( | const EntryMap * | rangemap | ) |
Add Symbol information as hints to the collection.
Run through all Symbols in the given map and create a corresponding RangeHint to this collection for each Symbol.
rangemap | is the given map of Symbols |
References addRange(), ghidra::rangemap< _recordtype >::begin_list(), ghidra::rangemap< _recordtype >::end_list(), ghidra::RangeHint::fixed, ghidra::Symbol::getType(), ghidra::Symbol::isTypeLocked(), and ghidra::RangeHint::typelock.
Referenced by ghidra::ScopeLocal::restructureVarnode().
void ghidra::MapState::gatherVarnodes | ( | const Funcdata & | fd | ) |
Add stack Varnodes as hints to the collection.
Add a RangeHint corresponding to each Varnode stored in the address space for the given function. The current knowledge of the Varnode's data-type is included as part of the hint.
fd | is the given function |
References addFixedType(), ghidra::Funcdata::beginLoc(), ghidra::PcodeOp::code(), ghidra::RangeHint::copy_constant, ghidra::CPUI_COPY, ghidra::CPUI_INDIRECT, ghidra::CPUI_MULTIEQUAL, ghidra::CPUI_PIECE, ghidra::CPUI_SUBPIECE, ghidra::Funcdata::endLoc(), ghidra::Varnode::getAddr(), ghidra::Funcdata::getArch(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Address::getOffset(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::Varnode::getType(), ghidra::Address::isBigEndian(), ghidra::Varnode::isConstant(), ghidra::Varnode::isFree(), isReadActive(), ghidra::Varnode::isWritten(), ghidra::PcodeOp::numInput(), spaceid, and ghidra::Architecture::types.
Referenced by ghidra::ScopeLocal::restructureVarnode().
bool ghidra::MapState::initialize | ( | void | ) |
Initialize the hint collection for iteration.
Sort the collection and add a special terminating RangeHint
References ghidra::AddrSpace::addressToByte(), ghidra::AddrSpace::byteToAddress(), ghidra::RangeHint::compareRanges(), defaultType, ghidra::RangeHint::endpoint, ghidra::AddrSpace::getAddrSize(), ghidra::Range::getLast(), ghidra::RangeList::getLastSignedRange(), ghidra::AddrSpace::getWordSize(), iter, maplist, range, reconcileDatatypes(), spaceid, and ghidra::AddrSpace::wrapOffset().
Referenced by ghidra::ScopeLocal::restructure().
|
staticprivate |
Is the given Varnode read by an active operation.
Filter out INDIRECT, MULTIEQUAL, and PIECE operations that are just copying between the same storage location. If there is another operation reading the Varnode, return true, otherwise return false.
vn | is the given Varnode to test |
References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_PIECE, ghidra::CPUI_SUBPIECE, ghidra::Varnode::endDescend(), ghidra::Varnode::getAddr(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Address::isBigEndian(), ghidra::PcodeOp::isMarker(), and iter.
Referenced by gatherVarnodes().
|
private |
Decide on data-type for RangeHints at the same address.
Assuming a sorted list, from among a sequence of RangeHints with the same start and size, select the most specific data-type. Set all elements to use this data-type, and eliminate duplicates.
References ghidra::RangeHint::compare(), ghidra::RangeHint::flags, maplist, ghidra::RangeHint::size, ghidra::RangeHint::start, ghidra::RangeHint::type, and ghidra::Datatype::typeOrder().
Referenced by initialize().