decompiler  1.0.0
Public Member Functions | Private Attributes | List of all members
ghidra::ParamActive Class Reference

Container class for ParamTrial objects. More...

#include <fspec.hh>

Public Member Functions

 ParamActive (bool recoversub)
 Construct an empty container. More...
 
void clear (void)
 Reset to an empty container.
 
void registerTrial (const Address &addr, int4 sz)
 Add a new trial to the container. More...
 
int4 getNumTrials (void) const
 Get the number of trials in this container.
 
ParamTrialgetTrial (int4 i)
 Get the i-th trial.
 
const ParamTrialgetTrialForInputVarnode (int4 slot) const
 Get trial corresponding to the given input Varnode. More...
 
int4 whichTrial (const Address &addr, int4 sz) const
 Get the trial overlapping with the given memory range. More...
 
bool needsFinalCheck (void) const
 Is a final check required.
 
void markNeedsFinalCheck (void)
 Mark that a final check is required.
 
bool isRecoverSubcall (void) const
 Are these trials for a call to a sub-function.
 
bool isFullyChecked (void) const
 Are all trials checked with no new trials expected.
 
void markFullyChecked (void)
 Mark that all trials are checked.
 
void setPlaceholderSlot (void)
 Establish a stack placedholder slot.
 
void freePlaceholderSlot (void)
 Free the stack placeholder slot. More...
 
int4 getNumPasses (void) const
 How many trial analysis passes were performed.
 
int4 getMaxPass (void) const
 What is the maximum number of passes.
 
void setMaxPass (int4 val)
 Set the maximum number of passes.
 
void finishPass (void)
 Mark that an analysis pass has completed.
 
void sortTrials (void)
 Sort the trials in formal parameter order.
 
void deleteUnusedTrials (void)
 Remove trials that were found not to be parameters. More...
 
void splitTrial (int4 i, int4 sz)
 Split the given trial in two. More...
 
void joinTrial (int4 slot, const Address &addr, int4 sz)
 Join adjacent parameter trials. More...
 
int4 getNumUsed (void) const
 Get number of trials marked as formal parameters. More...
 
bool testShrink (int4 i, const Address &addr, int4 sz) const
 Test if the given trial can be shrunk to the given range. More...
 
void shrink (int4 i, const Address &addr, int4 sz)
 Shrink the given trial to a new given range. More...
 
void sortFixedPosition (void)
 sort the trials by fixed position then <
 

Private Attributes

vector< ParamTrialtrial
 The list of parameter trials.
 
int4 slotbase
 Slot where next parameter will go.
 
int4 stackplaceholder
 Which call input slot holds the stack placeholder.
 
int4 numpasses
 Number of attempts at evaluating parameters.
 
int4 maxpass
 Number of passes before we assume we have seen all params.
 
bool isfullychecked
 True if all trials are fully examined (and no new trials are expected)
 
bool needsfinalcheck
 Should a final pass be made on trials (to take into account control-flow changes)
 
bool recoversubcall
 True if this is being used to recover prototypes of a sub-function call.
 

Detailed Description

Container class for ParamTrial objects.

The parameter analysis algorithms use this class to maintain the collection of parameter trials being actively considered for a given function. It holds the ParamTrial objects and other information about the current state of analysis.

Trials are maintained in two stages, before parameter decisions have been made and after. Before, trials are in input index order relative to the CALL or CALLIND op for a sub-function, or they are in address order for input Varnodes to the active function. After, the trials are put into formal parameter order, as dictated by the PrototypeModel.

Constructor & Destructor Documentation

◆ ParamActive()

ghidra::ParamActive::ParamActive ( bool  recoversub)

Construct an empty container.

Parameters
recoversubselects whether a sub-function or the active function is being tested

Member Function Documentation

◆ deleteUnusedTrials()

void ghidra::ParamActive::deleteUnusedTrials ( void  )

Remove trials that were found not to be parameters.

Delete any trial for which isUsed() returns false. This is used in conjunction with setting the active Varnodes on a call, so the slot number is reordered too.

References ghidra::ParamTrial::isUsed(), and ghidra::ParamTrial::setSlot().

Referenced by ghidra::FuncCallSpecs::buildInputFromTrials(), and ghidra::FuncCallSpecs::buildOutputFromTrials().

◆ freePlaceholderSlot()

void ghidra::ParamActive::freePlaceholderSlot ( void  )

Free the stack placeholder slot.

Free up the stack placeholder slot, which may cause trial slots to get adjusted.

References ghidra::ParamEntry::getSlot().

Referenced by ghidra::FuncCallSpecs::clearStackPlaceholderSlot().

◆ getNumUsed()

int4 ghidra::ParamActive::getNumUsed ( void  ) const

Get number of trials marked as formal parameters.

This assumes the trials have been sorted. So used trials are first.

Returns
the number of formally used trials

References ghidra::FspecSpace::NAME.

◆ getTrialForInputVarnode()

const ParamTrial & ghidra::ParamActive::getTrialForInputVarnode ( int4  slot) const
inline

Get trial corresponding to the given input Varnode.

Return the trial associated with the input Varnode to the associated p-code CALL or CALLIND. We take into account the call address parameter (subtract 1) and if the index occurs after the index holding the stackpointer placeholder, we subtract an additional 1.

Parameters
slotis the input index of the input Varnode
Returns
the corresponding parameter trial

Referenced by ghidra::Funcdata::checkCallDoubleUse(), ghidra::FuncCallSpecs::checkInputJoin(), and ghidra::FuncCallSpecs::doInputJoin().

◆ joinTrial()

void ghidra::ParamActive::joinTrial ( int4  slot,
const Address addr,
int4  sz 
)

Join adjacent parameter trials.

Join the trial at the given slot with the trial in the next slot

Parameters
slotis the given slot
addris the address of the new joined memory range
szis the size of the new memory range

References ghidra::ParamTrial::getSize(), and ghidra::ParamTrial::getSlot().

Referenced by ghidra::FuncCallSpecs::doInputJoin().

◆ registerTrial()

void ghidra::ParamActive::registerTrial ( const Address addr,
int4  sz 
)

◆ shrink()

void ghidra::ParamActive::shrink ( int4  i,
const Address addr,
int4  sz 
)
inline

Shrink the given trial to a new given range.

Parameters
iis the index of the given trial
addris the new range's starting address
szis the new range's size in bytes

◆ splitTrial()

void ghidra::ParamActive::splitTrial ( int4  i,
int4  sz 
)

Split the given trial in two.

Split the trial into two trials, where the first piece has the given size.

Parameters
iis the index of the given trial
szis the given size

References ghidra::ParamEntry::getSize().

Referenced by ghidra::ActionParamDouble::apply().

◆ testShrink()

bool ghidra::ParamActive::testShrink ( int4  i,
const Address addr,
int4  sz 
) const
inline

Test if the given trial can be shrunk to the given range.

Parameters
iis the index of the given trial
addris the new address
szis the new size
Returns
true if the trial can be shrunk to the new range

◆ whichTrial()

int4 ghidra::ParamActive::whichTrial ( const Address addr,
int4  sz 
) const

Get the trial overlapping with the given memory range.

The (index of) the first overlapping trial is returned.

Parameters
addris the starting address of the given range
szis the number of bytes in the range
Returns
the index of the overlapping trial, or -1 if no trial overlaps

References ghidra::Address::overlap().

Referenced by ghidra::FuncCallSpecs::collectOutputTrialVarnodes(), ghidra::Heritage::guardCallOverlappingInput(), ghidra::Heritage::guardCallOverlappingOutput(), and ghidra::Heritage::guardCalls().


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