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

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. More...
 
 ~MapState (void)
 Destructor.
 
bool initialize (void)
 Initialize the hint collection for iteration. More...
 
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. More...
 
void gatherVarnodes (const Funcdata &fd)
 Add stack Varnodes as hints to the collection. More...
 
void gatherHighs (const Funcdata &fd)
 Add HighVariables as hints to the collection. More...
 
void gatherOpen (const Funcdata &fd)
 Add pointer references as hints to the collection. More...
 
RangeHintnext (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. More...
 
void addRange (uintb st, Datatype *ct, uint4 fl, RangeHint::RangeType rt, int4 hi)
 Add a hint to the collection. More...
 
void reconcileDatatypes (void)
 Decide on data-type for RangeHints at the same address. More...
 

Private Attributes

AddrSpacespaceid
 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.
 
DatatypedefaultType
 The default data-type to use for RangeHints.
 
AliasChecker checker
 A collection of pointer Varnodes into our address space.
 

Detailed Description

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.

Constructor & Destructor Documentation

MapState::MapState ( AddrSpace spc,
const RangeList rn,
const RangeList pm,
Datatype dt 
)

Constructor.

Parameters
spcis the address space being analyzed
rnis the subset of addresses within the address space to analyze
pmis subset of ranges within the address space considered to be parameters
dtis the default data-type

References RangeList::begin(), defaultType, RangeList::end(), iter, range, RangeList::removeRange(), and spaceid.

Member Function Documentation

void MapState::addGuard ( const LoadGuard guard,
OpCode  opc,
TypeFactory typeFactory 
)
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.

Parameters
guardis the given LoadGuard
opcis the expected op-code (CPUI_LOAD or CPUI_STORE)
typeFactoryis used to manufacture a data-type for the hint if necessary

References addRange(), CPUI_STORE, TypeFactory::getBase(), PcodeOp::getIn(), LoadGuard::getMaximum(), Datatype::getMetatype(), LoadGuard::getMinimum(), LoadGuard::getOp(), PcodeOp::getOut(), Datatype::getSize(), Varnode::getSize(), LoadGuard::getStep(), Varnode::getType(), LoadGuard::isRangeLocked(), LoadGuard::isValid(), RangeHint::open, TYPE_ARRAY, TYPE_PTR, and TYPE_UNKNOWN.

Referenced by gatherOpen().

void MapState::addRange ( uintb  st,
Datatype ct,
uint4  fl,
RangeHint::RangeType  rt,
int4  hi 
)
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.

Parameters
stis the starting offset of the range
ctis the (optional) data-type information, which may be NULL
flis additional boolean properties
rtis the type of the hint
hiis the biggest guaranteed index for open range hints

References AddrSpace::addressToByte(), AddrSpace::byteToAddress(), defaultType, AddrSpace::getAddrSize(), Datatype::getSize(), AddrSpace::getWordSize(), RangeList::inRange(), maplist, Datatype::printRaw(), range, sign_extend(), and spaceid.

Referenced by addGuard(), gatherHighs(), gatherOpen(), gatherSymbols(), and gatherVarnodes().

void MapState::gatherHighs ( const Funcdata fd)

Add HighVariables as hints to the collection.

Add a RangeHint corresponding to each HighVariable that is mapped to our address space for the given function.

Parameters
fdis the given function

References addRange(), Funcdata::beginLoc(), Funcdata::endLoc(), RangeHint::fixed, Varnode::getHigh(), Varnode::getOffset(), HighVariable::getTiedVarnode(), HighVariable::getType(), HighVariable::isAddrTied(), HighVariable::isMark(), iter, HighVariable::setMark(), and spaceid.

Referenced by ScopeLocal::restructureHigh().

void 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.

Parameters
fdis the given function

References addGuard(), addRange(), checker, CPUI_LOAD, CPUI_STORE, AliasChecker::gather(), AliasChecker::getAddBase(), AliasChecker::getAlias(), Funcdata::getArch(), Funcdata::getLoadGuards(), Datatype::getMetatype(), Funcdata::getStoreGuards(), iter, RangeHint::open, spaceid, TYPE_ARRAY, TYPE_PTR, and Architecture::types.

void 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.

Parameters
rangemapis the given map of Symbols

References addRange(), rangemap< _recordtype >::begin_list(), rangemap< _recordtype >::end_list(), RangeHint::fixed, Symbol::getFlags(), Symbol::getType(), and iter.

void 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.

Parameters
fdis the given function

References addRange(), Funcdata::beginLoc(), Funcdata::endLoc(), RangeHint::fixed, Varnode::getOffset(), Varnode::getType(), Varnode::isFree(), iter, and spaceid.

Referenced by ScopeLocal::restructureVarnode().

bool MapState::initialize ( void  )

Initialize the hint collection for iteration.

Sort the collection and add a special terminating RangeHint

Returns
true if the collection isn't empty (and iteration can begin)

References AddrSpace::addressToByte(), AddrSpace::byteToAddress(), RangeHint::compareRanges(), defaultType, RangeHint::endpoint, AddrSpace::getAddrSize(), Range::getLast(), RangeList::getLastSignedRange(), AddrSpace::getWordSize(), iter, maplist, range, reconcileDatatypes(), sign_extend(), spaceid, and AddrSpace::wrapOffset().

Referenced by ScopeLocal::restructure().

void MapState::reconcileDatatypes ( void  )
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 RangeHint::compare(), maplist, RangeHint::size, RangeHint::start, RangeHint::type, and Datatype::typeOrder().

Referenced by initialize().


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