|
decompiler 1.0.0
|
A standard model for parameters as an ordered list of storage resources. More...
#include <fspec.hh>
Public Member Functions | |
| ParamListStandard (void) | |
| Construct for use with restoreXml() | |
| ParamListStandard (const ParamListStandard &op2) | |
| Copy constructor. | |
| const list< ParamEntry > & | getEntry (void) const |
| Get the list of parameter entries. | |
| virtual uint4 | getType (void) const |
| Get the type of parameter list. More... | |
| virtual void | assignMap (const vector< Datatype * > &proto, TypeFactory &typefactory, vector< ParameterPieces > &res) const |
| Given list of data-types, map the list positions to storage locations. More... | |
| virtual void | fillinMap (ParamActive *active) const |
| Given an unordered list of storage locations, calculate a function prototype. More... | |
| virtual bool | checkJoin (const Address &hiaddr, int4 hisize, const Address &loaddr, int4 losize) const |
| Check if the given two storage locations can represent a single logical parameter. More... | |
| virtual bool | checkSplit (const Address &loc, int4 size, int4 splitpoint) const |
| Check if it makes sense to split a single storage location into two parameters. More... | |
| virtual int4 | characterizeAsParam (const Address &loc, int4 size) const |
| Characterize whether the given range overlaps parameter storage. More... | |
| virtual bool | possibleParam (const Address &loc, int4 size) const |
| Does the given storage location make sense as a parameter. More... | |
| virtual bool | possibleParamWithSlot (const Address &loc, int4 size, int4 &slot, int4 &slotsize) const |
| Pass-back the slot and slot size for the given storage location as a parameter. More... | |
| virtual bool | getBiggestContainedParam (const Address &loc, int4 size, VarnodeData &res) const |
| Pass-back the biggest parameter contained within the given range. More... | |
| virtual bool | unjustifiedContainer (const Address &loc, int4 size, VarnodeData &res) const |
| Check if the given storage location looks like an unjustified parameter. More... | |
| virtual OpCode | assumedExtension (const Address &addr, int4 size, VarnodeData &res) const |
| Get the type of extension and containing parameter for the given storage. More... | |
| virtual AddrSpace * | getSpacebase (void) const |
| Get the address space associated with any stack based parameters in this list. More... | |
| virtual void | getRangeList (AddrSpace *spc, RangeList &res) const |
| For a given address space, collect all the parameter locations within that space. More... | |
| virtual int4 | getMaxDelay (void) const |
| Return the maximum heritage delay across all possible parameters. More... | |
| virtual void | restoreXml (const Element *el, const AddrSpaceManager *manage, vector< EffectRecord > &effectlist, bool normalstack) |
| Restore the model from an XML stream. More... | |
| virtual ParamList * | clone (void) const |
| Clone this parameter list model. More... | |
Public Member Functions inherited from ParamList | |
| virtual | ~ParamList (void) |
| Destructor. | |
| virtual uint4 | getType (void) const =0 |
| Get the type of parameter list. More... | |
| virtual void | assignMap (const vector< Datatype * > &proto, TypeFactory &typefactory, vector< ParameterPieces > &res) const =0 |
| Given list of data-types, map the list positions to storage locations. More... | |
| virtual void | fillinMap (ParamActive *active) const =0 |
| Given an unordered list of storage locations, calculate a function prototype. More... | |
| virtual bool | checkJoin (const Address &hiaddr, int4 hisize, const Address &loaddr, int4 losize) const =0 |
| Check if the given two storage locations can represent a single logical parameter. More... | |
| virtual bool | checkSplit (const Address &loc, int4 size, int4 splitpoint) const =0 |
| Check if it makes sense to split a single storage location into two parameters. More... | |
| virtual int4 | characterizeAsParam (const Address &loc, int4 size) const =0 |
| Characterize whether the given range overlaps parameter storage. More... | |
| virtual bool | possibleParam (const Address &loc, int4 size) const =0 |
| Does the given storage location make sense as a parameter. More... | |
| virtual bool | possibleParamWithSlot (const Address &loc, int4 size, int4 &slot, int4 &slotsize) const =0 |
| Pass-back the slot and slot size for the given storage location as a parameter. More... | |
| virtual bool | getBiggestContainedParam (const Address &loc, int4 size, VarnodeData &res) const =0 |
| Pass-back the biggest parameter contained within the given range. More... | |
| virtual bool | unjustifiedContainer (const Address &loc, int4 size, VarnodeData &res) const =0 |
| Check if the given storage location looks like an unjustified parameter. More... | |
| virtual OpCode | assumedExtension (const Address &addr, int4 size, VarnodeData &res) const =0 |
| Get the type of extension and containing parameter for the given storage. More... | |
| virtual AddrSpace * | getSpacebase (void) const =0 |
| Get the address space associated with any stack based parameters in this list. More... | |
| virtual void | getRangeList (AddrSpace *spc, RangeList &res) const =0 |
| For a given address space, collect all the parameter locations within that space. More... | |
| virtual int4 | getMaxDelay (void) const =0 |
| Return the maximum heritage delay across all possible parameters. More... | |
| virtual void | restoreXml (const Element *el, const AddrSpaceManager *manage, vector< EffectRecord > &effectlist, bool normalstack)=0 |
| Restore the model from an XML stream. More... | |
| virtual ParamList * | clone (void) const =0 |
| Clone this parameter list model. More... | |
Protected Member Functions | |
| const ParamEntry * | findEntry (const Address &loc, int4 size) const |
| Given storage location find matching ParamEntry. More... | |
| Address | assignAddress (const Datatype *tp, vector< int4 > &status) const |
| Assign storage for given parameter data-type. More... | |
| void | buildTrialMap (ParamActive *active) const |
| Build map from parameter trials to model ParamEntrys. More... | |
| void | separateSections (ParamActive *active, int4 &oneStart, int4 &oneStop, int4 &twoStart, int4 &twoStop) const |
| Calculate the range of trials in each of the two resource sections. More... | |
| void | forceExclusionGroup (ParamActive *active) const |
| Enforce exclusion rules for the given set of parameter trials. More... | |
| void | forceNoUse (ParamActive *active, int4 start, int4 stop) const |
| Mark every trial above the first "definitely not used" as inactive. More... | |
| void | forceInactiveChain (ParamActive *active, int4 maxchain, int4 start, int4 stop, int4 groupstart) const |
| Enforce rules about chains of inactive slots. More... | |
| void | calcDelay (void) |
| Calculate the maximum heritage delay for any potential parameter in this list. | |
| void | populateResolver (void) |
| Build the ParamEntry resolver maps. More... | |
| void | parsePentry (const Element *el, const AddrSpaceManager *manage, vector< EffectRecord > &effectlist, int4 groupid, bool normalstack, bool autokill, bool splitFloat, bool grouped) |
| Read a <pentry> tag and add it to this list. More... | |
| void | parseGroup (const Element *el, const AddrSpaceManager *manage, vector< EffectRecord > &effectlist, int4 groupid, bool normalstack, bool autokill, bool splitFloat) |
| Read a group of <pentry> tags that are allocated as a group. More... | |
Protected Attributes | |
| int4 | numgroup |
| Number of groups in this parameter convention. | |
| int4 | maxdelay |
| Maximum heritage delay across all parameters. | |
| int4 | pointermax |
| If non-zero, maximum size of a data-type before converting to a pointer. | |
| bool | thisbeforeret |
| Does a this parameter come before a hidden return parameter. | |
| int4 | resourceTwoStart |
| If there are two resource sections, the group of the first entry in the second section. | |
| list< ParamEntry > | entry |
| The ordered list of parameter entries. | |
| vector< ParamEntryResolver * > | resolverMap |
| Map from space id to resolver. | |
| AddrSpace * | spacebase |
| Address space containing relative offset parameters. | |
Additional Inherited Members | |
Public Types inherited from ParamList | |
| enum | { p_standard , p_standard_out , p_register , p_register_out , p_merged } |
A standard model for parameters as an ordered list of storage resources.
This is a configurable model for passing (input) parameters as a list to a function. The model allows 1 or more resource lists based on data-type, either TYPE_UNKNOWN for general purpose or TYPE_FLOAT for floating-point registers. Within a resource list, any number of parameters can be used but they must come starting at the beginning of the list with no holes (skipped resources). A resource list can include (at the end) stack parameters that are allocated based on an alignment. Optionally, the model supports converting data-types larger than a specified size to pointers within the parameter list.
|
protected |
Assign storage for given parameter data-type.
Given the next data-type and the status of previously allocated slots, select the storage location for the parameter. The status array is indexed by group: a positive value indicates how many slots have been allocated from that group, and a -1 indicates the group/resource is fully consumed.
| tp | is the data-type of the next parameter |
| status | is an array marking how many slots have already been consumed in a group |
References entry, ParamEntry::getAddrBySlot(), ParamEntry::getGroup(), ParamEntry::getGroupSize(), Datatype::getMetatype(), Datatype::getSize(), ParamEntry::getType(), ParamEntry::isExclusion(), Address::isInvalid(), and TYPE_UNKNOWN.
Referenced by assignMap(), ParamListRegisterOut::assignMap(), and ParamListStandardOut::assignMap().
|
virtual |
Given list of data-types, map the list positions to storage locations.
If we know the function prototype, recover how parameters are actually stored using the model.
| proto | is the ordered list of data-types |
| typefactory | is the TypeFactory (for constructing pointers) |
| res | will contain the storage locations corresponding to the datatypes |
Implements ParamList.
Reimplemented in ParamListRegisterOut, ParamListStandardOut, and ParamListMerged.
References assignAddress(), Datatype::flags, AddrSpace::getAddrSize(), TypeFactory::getArch(), AddrSpaceManager::getDefaultDataSpace(), TypeFactory::getTypePointer(), AddrSpace::getWordSize(), ParameterPieces::hiddenretparm, ParameterPieces::indirectstorage, numgroup, pointermax, and spacebase.
|
virtual |
Get the type of extension and containing parameter for the given storage.
If the given storage is properly contained within a normal parameter and the model typically extends a small value into the full container, pass back the full container and the type of extension.
| addr | is the starting address of the given storage |
| size | is the number of bytes in the given storage |
| res | is the parameter storage to pass back |
Implements ParamList.
|
protected |
Build map from parameter trials to model ParamEntrys.
Given a set of trials (putative Varnode parameters) as ParamTrial objects, associate each trial with a model ParamEntry within this list. Trials for for which there are no matching entries are marked as unused. Any holes in the resource list are filled with unreferenced trials. The trial list is sorted.
| active | is the set of trials to map and organize |
References entry, findEntry(), ParamEntry::getAddrBySlot(), ParamTrial::getAddress(), ParamEntry::getAlign(), ParamTrial::getEntry(), ParamEntry::getGroup(), ParamActive::getNumTrials(), ParamEntry::getSize(), ParamTrial::getSize(), ParamEntry::getSlot(), ParamActive::getTrial(), ParamEntry::getType(), ParamEntry::isExclusion(), ParamTrial::markNoUse(), ParamTrial::markUnref(), ParamActive::registerTrial(), ParamTrial::setEntry(), ParamActive::sortTrials(), and TYPE_FLOAT.
Referenced by fillinMap().
|
virtual |
Characterize whether the given range overlaps parameter storage.
Does the range naturally fit inside a potential parameter entry from this list or does it contain a parameter entry. Return one of three values indicating this characterization:
| loc | is the starting address of the given range |
| size | is the number of bytes in the given range |
Implements ParamList.
References ParamEntry::containedBy(), rangemap< _recordtype >::end(), rangemap< _recordtype >::find(), rangemap< _recordtype >::find_end(), AddrSpace::getIndex(), ParamEntry::getMinSize(), Address::getOffset(), Address::getSpace(), ParamEntry::isExclusion(), ParamEntry::justifiedContain(), and resolverMap.
|
virtual |
Check if the given two storage locations can represent a single logical parameter.
Within the conventions of this model, do the two (hi/lo) locations represent consecutive parameter locations that can be replaced by a single logical parameter.
| hiaddr | is the address of the most significant part of the value |
| hisize | is the size of the most significant part in bytes |
| loaddr | is the address of the least significant part of the value |
| losize | is the size of the least significant part in bytes |
Implements ParamList.
References entry, findEntry(), ParamEntry::getAlign(), ParamEntry::getBase(), ParamEntry::getGroup(), Address::getOffset(), Address::isContiguous(), and ParamEntry::isExclusion().
|
virtual |
Check if it makes sense to split a single storage location into two parameters.
A storage location and split point is provided, implying two new storage locations. Does this model allow these locations to be considered parameters.
| loc | is the starting address of provided storage location |
| size | is the size of the location in bytes |
| splitpoint | is the number of bytes to consider in the first (in address order) piece |
Implements ParamList.
References findEntry().
|
virtual |
Clone this parameter list model.
Implements ParamList.
Reimplemented in ParamListRegisterOut, ParamListRegister, ParamListStandardOut, and ParamListMerged.
References ParamListStandard().
|
virtual |
Given an unordered list of storage locations, calculate a function prototype.
A list of input (or output) trials is given, which may have holes, invalid inputs etc. Decide on the formal ordered parameter list. Trials within the ParamActive are added, removed, or reordered as needed.
| active | is the given list of trials |
Implements ParamList.
Reimplemented in ParamListRegisterOut, ParamListRegister, and ParamListMerged.
References buildTrialMap(), forceExclusionGroup(), forceInactiveChain(), forceNoUse(), ParamActive::getNumTrials(), ParamActive::getTrial(), ParamTrial::isActive(), ParamTrial::markUsed(), resourceTwoStart, and separateSections().
|
protected |
Given storage location find matching ParamEntry.
Find the (first) entry containing the given memory range
| loc | is the starting address of the range |
| size | is the number of bytes in the range |
References rangemap< _recordtype >::find(), AddrSpace::getIndex(), ParamEntry::getMinSize(), Address::getOffset(), Address::getSpace(), ParamEntry::justifiedContain(), and resolverMap.
Referenced by buildTrialMap(), checkJoin(), checkSplit(), ParamListRegister::fillinMap(), possibleParam(), and possibleParamWithSlot().
|
protected |
Enforce exclusion rules for the given set of parameter trials.
If there are more than one active trials in a single group, and if that group is an exclusion group, mark all but the first trial to inactive.
| active | is the set of trials |
References ParamTrial::getEntry(), ParamEntry::getGroup(), ParamEntry::getGroupSize(), ParamActive::getNumTrials(), ParamActive::getTrial(), ParamTrial::isActive(), ParamEntry::isExclusion(), and ParamTrial::markInactive().
Referenced by fillinMap().
|
protected |
Enforce rules about chains of inactive slots.
If there is a chain of slots whose length is greater than maxchain, where all trials are inactive, mark trials in any later slot as inactive. Mark any inactive trials before this (that aren't in a maximal chain) as active. The parameter entries in the model may be split up into different resource sections, as in floating-point vs general purpose. This method must be called on a single section at a time. The start and stop indices describe the range of trials in the particular section.
| active | is the set of trials, which must be sorted |
| maxchain | is the maximum number of inactive trials to allow in a chain |
| start | is the first index in the range of trials to consider |
| stop | is the last index (+1) in the range of trials to consider |
| groupstart | is the smallest group id in the particular section |
References ParamTrial::getAddress(), ParamTrial::getEntry(), Address::getSpace(), ParamActive::getTrial(), AddrSpace::getType(), IPTR_SPACEBASE, ParamTrial::isActive(), ParamTrial::isDefinitelyNotUsed(), ParamActive::isRecoverSubcall(), ParamTrial::isUnref(), ParamTrial::markActive(), ParamTrial::markInactive(), and ParamTrial::slotGroup().
Referenced by fillinMap().
|
protected |
Mark every trial above the first "definitely not used" as inactive.
Inspection and marking only occurs within an indicated range of trials, allowing floating-point and general purpose resources to be treated separately.
| active | is the set of trials, which must already be ordered |
| start | is the index of the first trial in the range to consider |
| stop | is the index (+1) of the last trial in the range to consider |
References ParamTrial::getEntry(), ParamEntry::getGroup(), ParamEntry::getGroupSize(), ParamActive::getTrial(), ParamTrial::isDefinitelyNotUsed(), ParamEntry::isExclusion(), and ParamTrial::markInactive().
Referenced by fillinMap().
|
virtual |
Pass-back the biggest parameter contained within the given range.
| loc | is the starting address of the given range |
| size | is the number of bytes in the range |
| res | will hold the parameter storage description being passed back |
Implements ParamList.
References ParamEntry::containedBy(), rangemap< _recordtype >::find_begin(), rangemap< _recordtype >::find_end(), ParamEntry::getBase(), AddrSpace::getIndex(), Address::getOffset(), ParamEntry::getSize(), Address::getSpace(), ParamEntry::getSpace(), ParamEntry::isExclusion(), VarnodeData::offset, resolverMap, VarnodeData::size, and VarnodeData::space.
|
inlinevirtual |
Return the maximum heritage delay across all possible parameters.
Depending on the address space, data-flow for a parameter may not be available until extra transform passes have completed. This method returns the number of passes that must occur before we can guarantee that all parameters have data-flow info.
Implements ParamList.
References maxdelay.
For a given address space, collect all the parameter locations within that space.
Pass back the memory ranges for any parameter that is stored in the given address space.
| spc | is the given address space |
| res | will hold the set of matching memory ranges |
Implements ParamList.
References entry, and RangeList::insertRange().
|
inlinevirtual |
Get the address space associated with any stack based parameters in this list.
Implements ParamList.
References spacebase.
Referenced by ParamListMerged::foldIn().
|
inlinevirtual |
Get the type of parameter list.
Implements ParamList.
Reimplemented in ParamListRegisterOut, ParamListRegister, ParamListStandardOut, and ParamListMerged.
References ParamList::p_standard.
|
protected |
Read a group of <pentry> tags that are allocated as a group.
All ParamEntry objects will share the same group id.
| el | is the <pentry element |
| manage | is manager for parsing address spaces |
| effectlist | holds any passed back effect records |
| groupid | is the group to which all ParamEntry elements are assigned |
| normalstack | is true if the parameters should be allocated from the front of the range |
| autokill | is true if parameters are automatically added to the killedbycall list |
| splitFloat | is true if floating-point parameters are in their own resource section |
References entry, Element::getChildren(), Element::getName(), ParamEntry::getSpace(), AddrSpace::getType(), IPTR_JOIN, numgroup, ParamEntry::orderWithinGroup(), and parsePentry().
Referenced by restoreXml().
|
protected |
Read a <pentry> tag and add it to this list.
| el | is the <pentry element |
| manage | is manager for parsing address spaces |
| effectlist | holds any passed back effect records |
| groupid | is the group to which the new ParamEntry is assigned |
| normalstack | is true if the parameters should be allocated from the front of the range |
| autokill | is true if parameters are automatically added to the killedbycall list |
| splitFloat | is true if floating-point parameters are in their own resource section |
| grouped | is true if the new ParamEntry is grouped with other entries |
References entry, AddrSpace::getType(), IPTR_SPACEBASE, EffectRecord::killedbycall, numgroup, resourceTwoStart, spacebase, and TYPE_FLOAT.
Referenced by parseGroup(), and restoreXml().
|
protected |
Build the ParamEntry resolver maps.
Enter all the ParamEntry objects into an interval map (based on address space)
References entry, ParamEntry::getBase(), AddrSpace::getIndex(), ParamEntry::getSize(), ParamEntry::getSpace(), rangemap< _recordtype >::insert(), and resolverMap.
Referenced by ParamListMerged::finalize(), ParamListStandard(), and restoreXml().
|
virtual |
Does the given storage location make sense as a parameter.
Within this model, decide if the storage location can be considered a parameter.
| loc | is the starting address of the storage location |
| size | is the number of bytes in the storage location |
Implements ParamList.
Reimplemented in ParamListRegisterOut.
References findEntry().
|
virtual |
Pass-back the slot and slot size for the given storage location as a parameter.
This checks if the given storage location acts as a parameter in this model and passes back the number of slots that it occupies.
| loc | is the starting address of the storage location |
| size | is the number of bytes in the storage location |
| slot | if the slot number to pass back |
| slotsize | is the number of consumed slots to pass back |
Implements ParamList.
References findEntry(), ParamEntry::getAlign(), ParamEntry::getGroupSize(), ParamEntry::getSlot(), and ParamEntry::isExclusion().
|
virtual |
Restore the model from an XML stream.
| el | is the root <input> or <output> element |
| manage | is used to resolve references to address spaces |
| effectlist | is a container collecting EffectRecords across all parameters |
| normalstack | is true if parameters are pushed on the stack in the normal order |
Implements ParamList.
Reimplemented in ParamListRegisterOut, and ParamListStandardOut.
References calcDelay(), ParamEntry::countJoinOverlap(), entry, Element::getAttributeName(), Element::getAttributeValue(), Element::getChildren(), Element::getName(), Element::getNumAttributes(), ParamEntry::isNonOverlappingJoin(), numgroup, parseGroup(), parsePentry(), pointermax, populateResolver(), resourceTwoStart, spacebase, thisbeforeret, and xml_readbool().
Referenced by ParamListRegisterOut::restoreXml().
|
protected |
Calculate the range of trials in each of the two resource sections.
The trials must already be mapped, which should put them in group order. The sections split at the group given by resourceTwoStart. We pass back the range of trial indices for each section. If resourceTwoStart is 0, then there is really only one section, and the empty range [0,0] is passed back for the second section.
| active | is the given set of parameter trials |
| oneStart | will pass back the index of the first trial in the first section |
| oneStop | will pass back the index (+1) of the last trial in the first section |
| twoStart | will pass back the index of the first trial in the second section |
| twoStop | will pass back the index (+1) of the last trial in the second section |
References ParamTrial::getEntry(), ParamEntry::getGroup(), ParamActive::getNumTrials(), ParamActive::getTrial(), and resourceTwoStart.
Referenced by fillinMap().
|
virtual |
Check if the given storage location looks like an unjustified parameter.
The storage for a value may be contained in a normal parameter location but be unjustified within that container, i.e. the least significant bytes are not being used. If this is the case, pass back the full parameter location and return true.
| loc | is the starting address of the given storage |
| size | is the number of bytes in the given storage |
| res | is the full parameter storage to pass back |
Implements ParamList.
References entry.