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

A function prototype. More...

#include <fspec.hh>

Inheritance diagram for ghidra::FuncProto:
ghidra::FuncCallSpecs

Public Member Functions

 FuncProto (void)
 Constructor.
 
 ~FuncProto (void)
 Destructor.
 
ArchitecturegetArch (void) const
 Get the Architecture owning this.
 
void copy (const FuncProto &op2)
 Copy another function prototype. More...
 
void copyFlowEffects (const FuncProto &op2)
 Copy properties that affect data-flow.
 
void getPieces (PrototypePieces &pieces) const
 Get the raw pieces of the prototype. More...
 
void setPieces (const PrototypePieces &pieces)
 Set this prototype based on raw pieces. More...
 
void setScope (Scope *s, const Address &startpoint)
 Set a backing symbol Scope for this. More...
 
void setInternal (ProtoModel *m, Datatype *vt)
 Set internal backing storage for this. More...
 
void setModel (ProtoModel *m)
 Set the prototype model for this. More...
 
bool hasModel (void) const
 Does this prototype have a model.
 
bool hasMatchingModel (const ProtoModel *op2) const
 Does this use the given model.
 
const string & getModelName (void) const
 Get the prototype model name.
 
int4 getModelExtraPop (void) const
 Get the extrapop of the prototype model.
 
bool isModelUnknown (void) const
 Return true if the prototype model is unknown.
 
bool printModelInDecl (void) const
 Return true if the name should be printed in declarations.
 
bool isInputLocked (void) const
 Are input data-types locked.
 
bool isOutputLocked (void) const
 Is the output data-type locked.
 
bool isModelLocked (void) const
 Is the prototype model for this locked.
 
bool hasCustomStorage (void) const
 Is this a "custom" function prototype.
 
void setInputLock (bool val)
 Toggle the data-type lock on input parameters. More...
 
void setOutputLock (bool val)
 Toggle the data-type lock on the return value. More...
 
void setModelLock (bool val)
 Toggle the lock on the prototype model for this. More...
 
bool isInline (void) const
 Does this function get in-lined during decompilation.
 
void setInline (bool val)
 Toggle the in-line setting for functions with this prototype. More...
 
int4 getInjectId (void) const
 Get the injection id associated with this. More...
 
int4 getReturnBytesConsumed (void) const
 Get an estimate of the number of bytes consumed by callers of this prototype. More...
 
bool setReturnBytesConsumed (int4 val)
 Set the number of bytes consumed by callers of this. More...
 
bool isNoReturn (void) const
 Does a function with this prototype never return.
 
void setNoReturn (bool val)
 Toggle the no-return setting for functions with this prototype. More...
 
bool hasThisPointer (void) const
 Is this a prototype for a class method, taking a this pointer.
 
bool isConstructor (void) const
 Is this prototype for a class constructor method.
 
void setConstructor (bool val)
 Toggle whether this prototype is a constructor method. More...
 
bool isDestructor (void) const
 Is this prototype for a class destructor method.
 
void setDestructor (bool val)
 Toggle whether this prototype is a destructor method. More...
 
bool hasInputErrors (void) const
 Has this prototype been marked as having an incorrect input parameter descriptions.
 
bool hasOutputErrors (void) const
 Has this prototype been marked as having an incorrect return value description.
 
void setInputErrors (bool val)
 Toggle the input error setting for this prototype. More...
 
void setOutputErrors (bool val)
 Toggle the output error setting for this prototype. More...
 
int4 getExtraPop (void) const
 Get the general extrapop setting for this prototype.
 
void setExtraPop (int4 ep)
 Set the general extrapop for this prototype.
 
int4 getInjectUponEntry (void) const
 Get any upon-entry injection id (or -1)
 
int4 getInjectUponReturn (void) const
 Get any upon-return injection id (or -1)
 
void resolveExtraPop (void)
 Assuming this prototype is locked, calculate the extrapop. More...
 
void clearUnlockedInput (void)
 Clear input parameters that have not been locked.
 
void clearUnlockedOutput (void)
 Clear the return value if it has not been locked.
 
void clearInput (void)
 Clear all input parameters regardless of lock.
 
void setInjectId (int4 id)
 Associate a given injection with this prototype. More...
 
void cancelInjectId (void)
 Turn-off any in-lining for this function.
 
void resolveModel (ParamActive *active)
 If this has a merged model, pick the most likely model (from the merged set) More...
 
void deriveInputMap (ParamActive *active) const
 Given a list of input trials, derive the most likely inputs for this prototype. More...
 
void deriveOutputMap (ParamActive *active) const
 Given a list of output trials, derive the most likely return value for this prototype. More...
 
bool checkInputJoin (const Address &hiaddr, int4 hisz, const Address &loaddr, int4 losz) const
 Check if the given two input storage locations can represent a single logical parameter. More...
 
bool checkInputSplit (const Address &loc, int4 size, int4 splitpoint) const
 Check if it makes sense to split a single storage location into two input parameters. More...
 
void updateInputTypes (Funcdata &data, const vector< Varnode *> &triallist, ParamActive *activeinput)
 Update input parameters based on Varnode trials. More...
 
void updateInputNoTypes (Funcdata &data, const vector< Varnode *> &triallist, ParamActive *activeinput)
 Update input parameters based on Varnode trials, but do not store the data-type. More...
 
void updateOutputTypes (const vector< Varnode *> &triallist)
 Update the return value based on Varnode trials. More...
 
void updateOutputNoTypes (const vector< Varnode *> &triallist, TypeFactory *factory)
 Update the return value based on Varnode trials, but don't store the data-type. More...
 
void updateAllTypes (const vector< string > &namelist, const vector< Datatype *> &typelist, bool dtdtdt)
 Set this entire function prototype based on a list of names and data-types. More...
 
ProtoParametergetParam (int4 i) const
 Get the i-th input parameter.
 
void removeParam (int4 i)
 Remove the i-th input parameter.
 
int4 numParams (void) const
 Get the number of input parameters.
 
ProtoParametergetOutput (void) const
 Get the return value.
 
DatatypegetOutputType (void) const
 Get the return value data-type.
 
const RangeListgetLocalRange (void) const
 Get the range of potential local stack variables.
 
const RangeListgetParamRange (void) const
 Get the range of potential stack parameters.
 
bool isStackGrowsNegative (void) const
 Return true if the stack grows toward smaller addresses.
 
bool isDotdotdot (void) const
 Return true if this takes a variable number of arguments.
 
void setDotdotdot (bool val)
 Toggle whether this takes variable arguments.
 
bool isOverride (void) const
 Return true if this is a call site override.
 
void setOverride (bool val)
 Toggle whether this is a call site override.
 
uint4 hasEffect (const Address &addr, int4 size) const
 Calculate the effect this has an a given storage location. More...
 
vector< EffectRecord >::const_iterator effectBegin (void) const
 Get iterator to front of EffectRecord list.
 
vector< EffectRecord >::const_iterator effectEnd (void) const
 Get iterator to end of EffectRecord list.
 
vector< VarnodeData >::const_iterator trashBegin (void) const
 Get iterator to front of likelytrash list. More...
 
vector< VarnodeData >::const_iterator trashEnd (void) const
 Get iterator to end of likelytrash list. More...
 
int4 characterizeAsInputParam (const Address &addr, int4 size) const
 Decide whether a given storage location could be, or could hold, an input parameter. More...
 
int4 characterizeAsOutput (const Address &addr, int4 size) const
 Decide whether a given storage location could be, or could hold, the return value. More...
 
bool possibleInputParam (const Address &addr, int4 size) const
 Decide whether a given storage location could be an input parameter. More...
 
bool possibleOutputParam (const Address &addr, int4 size) const
 Decide whether a given storage location could be a return value. More...
 
int4 getMaxInputDelay (void) const
 Return the maximum heritage delay across all possible input parameters. More...
 
int4 getMaxOutputDelay (void) const
 Return the maximum heritage delay across all possible return values. More...
 
bool unjustifiedInputParam (const Address &addr, int4 size, VarnodeData &res) const
 Check if the given storage location looks like an unjustified input parameter. More...
 
OpCode assumedInputExtension (const Address &addr, int4 size, VarnodeData &res) const
 Get the type of extension and containing input parameter for the given storage. More...
 
OpCode assumedOutputExtension (const Address &addr, int4 size, VarnodeData &res) const
 Get the type of extension and containing return value location for the given storage. More...
 
bool getBiggestContainedInputParam (const Address &loc, int4 size, VarnodeData &res) const
 Pass-back the biggest potential input parameter contained within the given range. More...
 
bool getBiggestContainedOutput (const Address &loc, int4 size, VarnodeData &res) const
 Pass-back the biggest potential output storage location contained within the given range. More...
 
Address getThisPointerStorage (Datatype *dt)
 Get the storage location associated with the "this" pointer. More...
 
bool isCompatible (const FuncProto &op2) const
 Decide if this can be safely restricted to match another prototype. More...
 
AddrSpacegetSpacebase (void) const
 Get the stack address space.
 
void printRaw (const string &funcname, ostream &s) const
 Print this prototype as a single line of text. More...
 
uint4 getComparableFlags (void) const
 Get the comparable properties of this prototype. More...
 
void encode (Encoder &encoder) const
 Encode this to a stream as a <prototype> element. More...
 
void decode (Decoder &decoder, Architecture *glb)
 Restore this from a <prototype> element in the given stream. More...
 

Protected Member Functions

void paramShift (int4 paramshift)
 Add parameters to the front of the input parameter list. More...
 
bool isParamshiftApplied (void) const
 
void setParamshiftApplied (bool val)
 Toggle whether a parameter shift has been applied.
 

Private Types

enum  {
  dotdotdot = 1, voidinputlock = 2, modellock = 4, is_inline = 8,
  no_return = 16, paramshift_applied = 32, error_inputparam = 64, error_outputparam = 128,
  custom_storage = 256, is_constructor = 0x200, is_destructor = 0x400, has_thisptr = 0x800,
  is_override = 0x1000
}
 

Private Member Functions

void updateThisPointer (void)
 Make sure any "this" parameter is properly marked. More...
 
void encodeEffect (Encoder &encoder) const
 Encode any overriding EffectRecords to stream. More...
 
void encodeLikelyTrash (Encoder &encoder) const
 Encode any overriding likelytrash registers to stream. More...
 
void decodeEffect (void)
 Merge in any EffectRecord overrides. More...
 
void decodeLikelyTrash (void)
 Merge in any likelytrash overrides. More...
 

Private Attributes

ProtoModelmodel
 Model of for this prototype.
 
ProtoStorestore
 Storage interface for parameters.
 
int4 extrapop
 Extra bytes popped from stack.
 
uint4 flags
 Boolean properties of the function prototype.
 
vector< EffectRecordeffectlist
 Side-effects associated with non-parameter storage locations.
 
vector< VarnodeDatalikelytrash
 Locations that may contain trash values.
 
int4 injectid
 (If non-negative) id of p-code snippet that should replace this function
 
int4 returnBytesConsumed
 Number of bytes of return value that are consumed by callers (0 = all bytes)
 

Detailed Description

A function prototype.

A description of the parameters and return value for a specific function. Parameter descriptions include both source code features like name and data-type but also give the storage location. Storage follows a specific parameter passing convention (ProtoModel), although individual parameters may be customized. The prototype describes numerous properties related to calling the specific function:

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
dotdotdot 

Set if this prototype takes variable arguments (varargs)

voidinputlock 

Set if this prototype takes no inputs and is locked.

modellock 

Set if the PrototypeModel is locked for this prototype.

is_inline 

Should this be inlined (within calling function) by decompiler.

no_return 

Function does not return.

paramshift_applied 

paramshift parameters have been added and removed

error_inputparam 

Set if the input parameters are not properly represented.

error_outputparam 

Set if the return value(s) are not properly represented.

custom_storage 

Parameter storage is custom (not derived from ProtoModel)

is_constructor 

Function is an (object-oriented) constructor.

is_destructor 

Function is an (object-oriented) destructor.

has_thisptr 

Function is a method with a 'this' pointer as an argument.

is_override 

Set if this prototype is created to override a single call site.

Member Function Documentation

◆ assumedInputExtension()

OpCode ghidra::FuncProto::assumedInputExtension ( const Address addr,
int4  size,
VarnodeData res 
) const
inline

Get the type of extension and containing input 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.

Parameters
addris the starting address of the given storage
sizeis the number of bytes in the given storage
resis the parameter storage to pass back
Returns
the extension operator (INT_ZEXT INT_SEXT) or INT_COPY if there is no extension. INT_PIECE indicates the extension is determined by the specific prototype.

References ghidra::ProtoModel::assumedInputExtension().

Referenced by ghidra::ActionPrototypeTypes::extendInput().

◆ assumedOutputExtension()

OpCode ghidra::FuncProto::assumedOutputExtension ( const Address addr,
int4  size,
VarnodeData res 
) const
inline

Get the type of extension and containing return value location for the given storage.

If the given storage is properly contained within a normal return value location and the model typically extends a small value into the full container, pass back the full container and the type of extension.

Parameters
addris the starting address of the given storage
sizeis the number of bytes in the given storage
resis the parameter storage to pass back
Returns
the extension operator (INT_ZEXT INT_SEXT) or INT_COPY if there is no extension. INT_PIECE indicates the extension is determined by the specific prototype.

References ghidra::ProtoModel::assumedOutputExtension().

Referenced by ghidra::FuncCallSpecs::commitNewOutputs(), and ghidra::ActionFuncLink::funcLinkOutput().

◆ characterizeAsInputParam()

int4 ghidra::FuncProto::characterizeAsInputParam ( const Address addr,
int4  size 
) const

Decide whether a given storage location could be, or could hold, an input parameter.

If the input is locked, check if the location overlaps one of the current parameters. Otherwise, check if the location overlaps an entry in the prototype model. Return:

  • no_containment - there is no containment between the range and any input parameter
  • contains_unjustified - at least one parameter contains the range
  • contains_justified - at least one parameter contains this range as its least significant bytes
  • contained_by - no parameter contains this range, but the range contains at least one parameter
    Parameters
    addris the starting address of the given storage location
    sizeis the number of bytes in the storage
    Returns
    the characterization code

References ghidra::ParamEntry::contained_by, ghidra::Address::containedBy(), ghidra::ParamEntry::contains_justified, ghidra::ParamEntry::contains_unjustified, ghidra::AddrSpace::flags, ghidra::ProtoParameter::getAddress(), ghidra::ProtoParameter::getSize(), ghidra::ProtoParameter::isTypeLocked(), ghidra::Address::justifiedContain(), and ghidra::ParamEntry::no_containment.

Referenced by ghidra::Heritage::guardCalls().

◆ characterizeAsOutput()

int4 ghidra::FuncProto::characterizeAsOutput ( const Address addr,
int4  size 
) const

Decide whether a given storage location could be, or could hold, the return value.

If the output is locked, check if the location overlaps the current return storage. Otherwise, check if the location overlaps an entry in the prototype model. Return:

  • no_containment - there is no containment between the range and any output storage
  • contains_unjustified - at least one output storage contains the range
  • contains_justified - at least one output storage contains this range as its least significant bytes
  • contained_by - no output storage contains this range, but the range contains at least one output storage
    Parameters
    addris the starting address of the given storage location
    sizeis the number of bytes in the storage
    Returns
    the characterization code

References ghidra::ParamEntry::contained_by, ghidra::Address::containedBy(), ghidra::ParamEntry::contains_justified, ghidra::ParamEntry::contains_unjustified, ghidra::ProtoParameter::getAddress(), ghidra::Datatype::getMetatype(), ghidra::ProtoParameter::getSize(), ghidra::ProtoParameter::getType(), ghidra::Address::justifiedContain(), ghidra::ParamEntry::no_containment, and ghidra::TYPE_VOID.

Referenced by ghidra::Heritage::guardCalls().

◆ checkInputJoin()

bool ghidra::FuncProto::checkInputJoin ( const Address hiaddr,
int4  hisz,
const Address loaddr,
int4  losz 
) const
inline

Check if the given two input storage locations can represent a single logical parameter.

For this prototype, do the two (hi/lo) locations represent consecutive input parameter locations that can be replaced by a single logical parameter.

Parameters
hiaddris the address of the most significant part of the value
hiszis the size of the most significant part in bytes
loaddris the address of the least significant part of the value
loszis the size of the least significant part in bytes
Returns
true if the two pieces can be joined

References ghidra::ProtoModel::checkInputJoin().

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

◆ checkInputSplit()

bool ghidra::FuncProto::checkInputSplit ( const Address loc,
int4  size,
int4  splitpoint 
) const
inline

Check if it makes sense to split a single storage location into two input parameters.

A storage location and split point is provided, implying two new storage locations. Does this prototype allow these locations to be considered separate parameters.

Parameters
locis the starting address of provided storage location
sizeis the size of the location in bytes
splitpointis the number of bytes to consider in the first (in address order) piece
Returns
true if the storage location can be split

References ghidra::ProtoModel::checkInputSplit().

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

◆ copy()

void ghidra::FuncProto::copy ( const FuncProto op2)

◆ decode()

void ghidra::FuncProto::decode ( Decoder decoder,
Architecture glb 
)

◆ decodeEffect()

void ghidra::FuncProto::decodeEffect ( void  )
private

Merge in any EffectRecord overrides.

EffectRecords read into effectlist by decode() override the list from ProtoModel. If this list is not empty, set up effectlist as a complete override containing all EffectRecords from ProtoModel plus all the overrides.

References ghidra::EffectRecord::compareByAddress(), ghidra::EffectRecord::getAddress(), ghidra::EffectRecord::getSize(), and ghidra::ProtoModel::lookupRecord().

◆ decodeLikelyTrash()

void ghidra::FuncProto::decodeLikelyTrash ( void  )
private

Merge in any likelytrash overrides.

VarnodeData read into likelytrash by decode() are additional registers over what is already in ProtoModel. Make likelytrash in this a complete list by merging in everything from ProtoModel.

◆ deriveInputMap()

void ghidra::FuncProto::deriveInputMap ( ParamActive active) const
inline

Given a list of input trials, derive the most likely inputs for this prototype.

Trials are sorted and marked as used or not.

Parameters
activeis the collection of Varnode input trials

References ghidra::ProtoModel::deriveInputMap().

Referenced by ghidra::ActionActiveParam::apply(), and ghidra::ActionInputPrototype::apply().

◆ deriveOutputMap()

void ghidra::FuncProto::deriveOutputMap ( ParamActive active) const
inline

Given a list of output trials, derive the most likely return value for this prototype.

One trial (at most) is marked used and moved to the front of the list

Parameters
activeis the collection of output trials

References ghidra::ProtoModel::deriveOutputMap().

Referenced by ghidra::ActionActiveReturn::apply(), and ghidra::ActionReturnRecovery::apply().

◆ encode()

void ghidra::FuncProto::encode ( Encoder encoder) const

◆ encodeEffect()

void ghidra::FuncProto::encodeEffect ( Encoder encoder) const
private

Encode any overriding EffectRecords to stream.

If the effectlist for this is non-empty, it contains the complete set of EffectRecords. Save just those that override the underlying list from ProtoModel

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), ghidra::EffectRecord::encode(), ghidra::EffectRecord::getAddress(), ghidra::EffectRecord::getSize(), ghidra::EffectRecord::getType(), ghidra::EffectRecord::killedbycall, ghidra::Encoder::openElement(), ghidra::EffectRecord::return_address, ghidra::AddrSpace::type, and ghidra::EffectRecord::unaffected.

◆ encodeLikelyTrash()

void ghidra::FuncProto::encodeLikelyTrash ( Encoder encoder) const
private

Encode any overriding likelytrash registers to stream.

If the likelytrash list is not empty it overrides the underlying ProtoModel's list. Encode any VarnodeData that does not appear in the ProtoModel to the stream.

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), ghidra::AddrSpace::encodeAttributes(), ghidra::VarnodeData::offset, ghidra::Encoder::openElement(), ghidra::VarnodeData::size, and ghidra::VarnodeData::space.

◆ getBiggestContainedInputParam()

bool ghidra::FuncProto::getBiggestContainedInputParam ( const Address loc,
int4  size,
VarnodeData res 
) const

Pass-back the biggest potential input parameter contained within the given range.

Parameters
locis the starting address of the given range
sizeis the number of bytes in the range
reswill hold the parameter storage description being passed back
Returns
true if there is at least one parameter contained in the range

References ghidra::Address::containedBy(), ghidra::AddrSpace::flags, ghidra::ProtoParameter::getAddress(), ghidra::Address::getOffset(), ghidra::ProtoParameter::getSize(), ghidra::Address::getSpace(), ghidra::ProtoParameter::isTypeLocked(), ghidra::VarnodeData::offset, ghidra::VarnodeData::size, and ghidra::VarnodeData::space.

Referenced by ghidra::Heritage::guardCallOverlappingInput().

◆ getBiggestContainedOutput()

bool ghidra::FuncProto::getBiggestContainedOutput ( const Address loc,
int4  size,
VarnodeData res 
) const

Pass-back the biggest potential output storage location contained within the given range.

Parameters
locis the starting address of the given range
sizeis the number of bytes in the range
reswill hold the output storage description being passed back
Returns
true if there is at least one possible output contained in the range

References ghidra::Address::containedBy(), ghidra::ProtoParameter::getAddress(), ghidra::Datatype::getMetatype(), ghidra::Address::getOffset(), ghidra::ProtoParameter::getSize(), ghidra::Address::getSpace(), ghidra::ProtoParameter::getType(), ghidra::VarnodeData::offset, ghidra::VarnodeData::size, ghidra::VarnodeData::space, and ghidra::TYPE_VOID.

Referenced by ghidra::Heritage::guardCallOverlappingOutput().

◆ getComparableFlags()

uint4 ghidra::FuncProto::getComparableFlags ( void  ) const
inline

Get the comparable properties of this prototype.

Get properties not including locking, error, and inlining flags.

Returns
the active set of flags for this prototype

Referenced by ghidra::TypeCode::compareBasic().

◆ getInjectId()

int4 ghidra::FuncProto::getInjectId ( void  ) const
inline

Get the injection id associated with this.

A non-negative id indicates a call-fixup is used to in-line function's with this prototype.

Returns
the id value corresponding to the specific call-fixup or -1 if there is no call-fixup

Referenced by ghidra::FlowInfo::injectPcode(), and ghidra::FlowInfo::injectSubFunction().

◆ getMaxInputDelay()

int4 ghidra::FuncProto::getMaxInputDelay ( void  ) const
inline

Return the maximum heritage delay across all possible input 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.

Returns
the maximum number of passes across all input parameters in this prototype

References ghidra::ProtoModel::getMaxInputDelay().

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

◆ getMaxOutputDelay()

int4 ghidra::FuncProto::getMaxOutputDelay ( void  ) const
inline

Return the maximum heritage delay across all possible return values.

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 any return value has data-flow info.

Returns
the maximum number of passes across all output parameters in this prototype

References ghidra::ProtoModel::getMaxOutputDelay().

Referenced by ghidra::Funcdata::initActiveOutput().

◆ getPieces()

void ghidra::FuncProto::getPieces ( PrototypePieces pieces) const

Get the raw pieces of the prototype.

Copy out the raw pieces of this prototype as stand-alone objects, includings model, names, and data-types

Parameters
pieceswill hold the raw pieces

References ghidra::PrototypePieces::dotdotdot, ghidra::ProtoParameter::getName(), ghidra::ProtoParameter::getType(), ghidra::PrototypePieces::innames, ghidra::PrototypePieces::intypes, ghidra::PrototypePieces::model, and ghidra::PrototypePieces::outtype.

◆ getReturnBytesConsumed()

int4 ghidra::FuncProto::getReturnBytesConsumed ( void  ) const
inline

Get an estimate of the number of bytes consumed by callers of this prototype.

A value of 0 means all possible bytes of the storage location are consumed.

Returns
the number of bytes or 0

Referenced by ghidra::ActionDeadCode::gatherConsumedReturn().

◆ getThisPointerStorage()

Address ghidra::FuncProto::getThisPointerStorage ( Datatype dt)

Get the storage location associated with the "this" pointer.

A likely pointer data-type for "this" pointer is passed in, which can be pointer to void. As the storage of "this" may depend on the full prototype, if the prototype is not already locked in, we assume the prototype returns void and takes the given data-type as the single input parameter.

Parameters
dtis the given input data-type
Returns
the starting address of storage for the "this" pointer

References ghidra::AddrSpace::flags, and ghidra::ParameterPieces::hiddenretparm.

Referenced by ghidra::Funcdata::prepareThisPointer().

◆ hasEffect()

uint4 ghidra::FuncProto::hasEffect ( const Address addr,
int4  size 
) const

Calculate the effect this has an a given storage location.

For a storage location that is active before and after a call to a function with this prototype, we determine the type of side-effect the function will have on the storage.

Parameters
addris the starting address of the storage location
sizeis the number of bytes in the storage
Returns
the type of side-effect: EffectRecord::unaffected, EffectRecord::killedbycall, etc.

References ghidra::ProtoModel::lookupEffect().

Referenced by ghidra::FuncCallSpecs::hasEffectTranslate(), and ghidra::Funcdata::setInputVarnode().

◆ isCompatible()

bool ghidra::FuncProto::isCompatible ( const FuncProto op2) const

Decide if this can be safely restricted to match another prototype.

Do this and another given function prototype share enough of their model, that if we restrict this to the other prototype, we know we won't miss data-flow.

Parameters
op2is the other restricting prototype
Returns
true if the two prototypes are compatible enough to restrict

References effectlist, extrapop, ghidra::ProtoModel::extrapop_unknown, ghidra::AddrSpace::flags, flags, ghidra::ProtoStore::getOutput(), injectid, isDotdotdot(), isOutputLocked(), likelytrash, model, and store.

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

◆ isParamshiftApplied()

bool ghidra::FuncProto::isParamshiftApplied ( void  ) const
inlineprotected

Has a parameter shift been applied

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

◆ paramShift()

void ghidra::FuncProto::paramShift ( int4  paramshift)
protected

Add parameters to the front of the input parameter list.

Prepend the indicated number of input parameters to this. The new parameters have a data-type of xunknown4. If they were originally locked, the existing parameters are preserved.

Parameters
paramshiftis the number of parameters to add (must be >0)

References ghidra::AddrSpace::flags, ghidra::TypeFactory::getArch(), ghidra::TypeFactory::getBase(), ghidra::ProtoParameter::getName(), ghidra::ProtoParameter::getType(), ghidra::TypeFactory::getTypeVoid(), ghidra::ParameterPieces::hiddenretparm, ghidra::ProtoStoreInternal::setOutput(), ghidra::TYPE_UNKNOWN, and ghidra::Architecture::types.

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

◆ possibleInputParam()

bool ghidra::FuncProto::possibleInputParam ( const Address addr,
int4  size 
) const

Decide whether a given storage location could be an input parameter.

If the input is locked, check if the location matches one of the current parameters. Otherwise, check if the location could be a parameter based on the prototype model.

Parameters
addris the starting address of the given storage location
sizeis the number of bytes in the storage
Returns
false if the location is definitely not an input parameter

References ghidra::AddrSpace::flags, ghidra::ProtoParameter::getAddress(), ghidra::ProtoParameter::getSize(), ghidra::ProtoParameter::isTypeLocked(), and ghidra::Address::justifiedContain().

Referenced by ghidra::ActionDirectWrite::apply(), and ghidra::ActionInputPrototype::apply().

◆ possibleOutputParam()

bool ghidra::FuncProto::possibleOutputParam ( const Address addr,
int4  size 
) const

Decide whether a given storage location could be a return value.

If the output is locked, check if the location matches the current return value. Otherwise, check if the location could be a return value based on the prototype model.

Parameters
addris the starting address of the given storage location
sizeis the number of bytes in the storage
Returns
false if the location is definitely not the return value

References ghidra::ProtoParameter::getAddress(), ghidra::Datatype::getMetatype(), ghidra::ProtoParameter::getSize(), ghidra::ProtoParameter::getType(), ghidra::Address::justifiedContain(), and ghidra::TYPE_VOID.

◆ printRaw()

void ghidra::FuncProto::printRaw ( const string &  funcname,
ostream &  s 
) const

Print this prototype as a single line of text.

Parameters
funcnameis an identifier of the function using this prototype
sis the output stream

◆ resolveExtraPop()

void ghidra::FuncProto::resolveExtraPop ( void  )

Assuming this prototype is locked, calculate the extrapop.

If extrapop is unknown and this prototype is locked, try to directly calculate what the extrapop should be. This is really only designed to work with 32-bit x86 binaries.

References ghidra::ProtoParameter::getAddress(), ghidra::Address::getOffset(), ghidra::ProtoParameter::getSize(), and ghidra::IPTR_SPACEBASE.

◆ resolveModel()

void ghidra::FuncProto::resolveModel ( ParamActive active)

If this has a merged model, pick the most likely model (from the merged set)

The given parameter trials are used to pick from among the merged ProtoModels and this prototype is changed (specialized) to the pick

Parameters
activeis the set of parameter trials to evaluate with

References ghidra::ProtoModelMerged::selectModel().

Referenced by ghidra::ActionActiveParam::apply(), and ghidra::ActionInputPrototype::apply().

◆ setConstructor()

void ghidra::FuncProto::setConstructor ( bool  val)
inline

Toggle whether this prototype is a constructor method.

Parameters
valis true if this is a constructor, false otherwise

Referenced by ghidra::TypeCode::decodePrototype().

◆ setDestructor()

void ghidra::FuncProto::setDestructor ( bool  val)
inline

Toggle whether this prototype is a destructor method.

Parameters
valis true if this is a destructor

Referenced by ghidra::TypeCode::decodePrototype().

◆ setInjectId()

void ghidra::FuncProto::setInjectId ( int4  id)

Associate a given injection with this prototype.

Set the id directly.

Parameters
idis the new id

References ghidra::AddrSpace::flags.

Referenced by ghidra::IfcFixupApply::execute().

◆ setInline()

void ghidra::FuncProto::setInline ( bool  val)
inline

Toggle the in-line setting for functions with this prototype.

In-lining can be based on a call-fixup, or the full body of the function can be in-lined.

Parameters
valis true if in-lining should be performed.

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

◆ setInputErrors()

void ghidra::FuncProto::setInputErrors ( bool  val)
inline

Toggle the input error setting for this prototype.

Parameters
valis true if input parameters should be marked as in error

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

◆ setInputLock()

void ghidra::FuncProto::setInputLock ( bool  val)

Toggle the data-type lock on input parameters.

The lock on the data-type of input parameters is set as specified. A true value indicates that future analysis will not change the number of input parameters or their data-type. Zero parameters or void can be locked.

Parameters
valis true to indicate a lock, false for unlocked

References ghidra::AddrSpace::flags, and ghidra::ProtoParameter::setTypeLock().

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

◆ setInternal()

void ghidra::FuncProto::setInternal ( ProtoModel m,
Datatype vt 
)

Set internal backing storage for this.

A prototype model is set, and any parameters added to this during analysis will be backed internally.

Parameters
mis the prototype model to set
vtis the default void data-type to use if the return-value remains unassigned

Referenced by ghidra::ActionDefaultParams::apply(), ghidra::Override::decode(), ghidra::TypeCode::decodePrototype(), and ghidra::IfcProtooverride::execute().

◆ setModel()

void ghidra::FuncProto::setModel ( ProtoModel m)

Set the prototype model for this.

Establish a specific prototype model for this function prototype. Some basic properties are inherited from the model, otherwise parameters are unchanged.

Parameters
mis the new prototype model to set

References ghidra::ProtoModel::extrapop_unknown, ghidra::AddrSpace::flags, ghidra::ProtoModel::getExtraPop(), ghidra::ProtoModel::hasThisPointer(), and ghidra::ProtoModel::isConstructor().

Referenced by ghidra::ActionPrototypeTypes::apply(), and ghidra::ActionDefaultParams::apply().

◆ setModelLock()

void ghidra::FuncProto::setModelLock ( bool  val)
inline

Toggle the lock on the prototype model for this.

The prototype model can be locked while still leaving parameters unlocked. Parameter recovery will follow the rules of the locked model.

Parameters
valis true to indicate a lock, false for unlocked

Referenced by ghidra::IfcProducePrototypes::iterationCallback().

◆ setNoReturn()

void ghidra::FuncProto::setNoReturn ( bool  val)
inline

Toggle the no-return setting for functions with this prototype.

Parameters
valis true to treat the function as never returning

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

◆ setOutputErrors()

void ghidra::FuncProto::setOutputErrors ( bool  val)
inline

Toggle the output error setting for this prototype.

Parameters
valis true if return value should be marked as in error

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

◆ setOutputLock()

void ghidra::FuncProto::setOutputLock ( bool  val)

Toggle the data-type lock on the return value.

The lock of the data-type of the return value is set as specified. A true value indicates that future analysis will not change the presence of or the data-type of the return value. A void return value can be locked.

Parameters
valis true to indicate a lock, false for unlocked

References ghidra::AddrSpace::flags.

◆ setPieces()

void ghidra::FuncProto::setPieces ( const PrototypePieces pieces)

Set this prototype based on raw pieces.

The full function prototype is (re)set from a model, names, and data-types The new input and output parameters are both assumed to be locked.

Parameters
piecesis the raw collection of names and data-types

References ghidra::PrototypePieces::dotdotdot, ghidra::PrototypePieces::innames, ghidra::PrototypePieces::intypes, ghidra::PrototypePieces::model, and ghidra::PrototypePieces::outtype.

Referenced by ghidra::IfcProtooverride::execute(), and ghidra::Architecture::setPrototype().

◆ setReturnBytesConsumed()

bool ghidra::FuncProto::setReturnBytesConsumed ( int4  val)

Set the number of bytes consumed by callers of this.

Provide a hint as to how many bytes of the return value are important. The smallest hint is used to inform the dead-code removal algorithm.

Parameters
valis the hint (number of bytes or 0 for all bytes)
Returns
true if the smallest hint has changed

Referenced by ghidra::RulePiecePathology::tracePathologyForward().

◆ setScope()

void ghidra::FuncProto::setScope ( Scope s,
const Address startpoint 
)

Set a backing symbol Scope for this.

Input parameters are set based on an existing function Scope and if there is no prototype model the default model is set. Parameters that are added to this during analysis will automatically be reflected in the symbol table. This should only be called during initialization of this prototype.

Parameters
sis the Scope to set
startpointis a usepoint to associate with the parameters

References ghidra::Architecture::defaultfp, and ghidra::Scope::getArch().

Referenced by ghidra::Funcdata::decode(), and ghidra::Funcdata::Funcdata().

◆ trashBegin()

vector< VarnodeData >::const_iterator ghidra::FuncProto::trashBegin ( void  ) const

Get iterator to front of likelytrash list.

Returns
the iterator to the start of the list

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

◆ trashEnd()

vector< VarnodeData >::const_iterator ghidra::FuncProto::trashEnd ( void  ) const

Get iterator to end of likelytrash list.

Returns
the iterator to the end of the list

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

◆ unjustifiedInputParam()

bool ghidra::FuncProto::unjustifiedInputParam ( const Address addr,
int4  size,
VarnodeData res 
) const

Check if the given storage location looks like an unjustified input 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. If the input is locked, checking is againt the set parameters, otherwise the check is against the prototype model.

Parameters
addris the starting address of the given storage
sizeis the number of bytes in the given storage
resis the full parameter storage to pass back
Returns
true if the given storage is unjustified within its parameter container

References ghidra::AddrSpace::flags, ghidra::ProtoParameter::getAddress(), ghidra::Address::getOffset(), ghidra::ProtoParameter::getSize(), ghidra::Address::getSpace(), ghidra::ProtoParameter::isTypeLocked(), ghidra::Address::justifiedContain(), ghidra::VarnodeData::offset, ghidra::VarnodeData::size, and ghidra::VarnodeData::space.

◆ updateAllTypes()

void ghidra::FuncProto::updateAllTypes ( const vector< string > &  namelist,
const vector< Datatype *> &  typelist,
bool  dtdtdt 
)

Set this entire function prototype based on a list of names and data-types.

Prototype information is provided as separate lists of names and data-types, where the first entry corresponds to the output parameter (return value) and the remaining entries correspond to input parameters. Storage locations and hidden return parameters are calculated, creating a complete function protototype. Existing locks are overridden.

Parameters
namelistis the list of parameter names
typelistis the list of data-types
dtdtdtis true if the new prototype accepts variable argument lists

References ghidra::AddrSpace::flags, and ghidra::ParameterPieces::hiddenretparm.

◆ updateInputNoTypes()

void ghidra::FuncProto::updateInputNoTypes ( Funcdata data,
const vector< Varnode *> &  triallist,
ParamActive activeinput 
)

Update input parameters based on Varnode trials, but do not store the data-type.

This is accomplished in the same way as if there were data-types but instead of pulling a data-type from the Varnode, only the size is used. Undefined data-types are pulled from the given TypeFactory

Parameters
datais the function containing the trial Varnodes
triallistis the list of Varnodes
activeinputis the trial container

References ghidra::ParameterPieces::addr, ghidra::Funcdata::findDisjointCover(), ghidra::ParameterPieces::flags, ghidra::Funcdata::getArch(), ghidra::TypeFactory::getBase(), ghidra::ParamActive::getNumTrials(), ghidra::Varnode::getSize(), ghidra::ParamActive::getTrial(), ghidra::Varnode::isMark(), ghidra::Varnode::isPersist(), ghidra::Varnode::setMark(), ghidra::ParameterPieces::type, ghidra::TYPE_UNKNOWN, and ghidra::Architecture::types.

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

◆ updateInputTypes()

void ghidra::FuncProto::updateInputTypes ( Funcdata data,
const vector< Varnode *> &  triallist,
ParamActive activeinput 
)

Update input parameters based on Varnode trials.

If the input parameters are locked, don't do anything. Otherwise, given a list of Varnodes and their associated trial information, create an input parameter for each trial in order, grabbing data-type information from the Varnode. Any old input parameters are cleared.

Parameters
datais the function containing the trial Varnodes
triallistis the list of Varnodes
activeinputis the trial container

References ghidra::ParameterPieces::addr, ghidra::Funcdata::findDisjointCover(), ghidra::ParameterPieces::flags, ghidra::Funcdata::getArch(), ghidra::TypeFactory::getBase(), ghidra::Varnode::getHigh(), ghidra::ParamActive::getNumTrials(), ghidra::Varnode::getSize(), ghidra::ParamActive::getTrial(), ghidra::HighVariable::getType(), ghidra::Varnode::isMark(), ghidra::Varnode::isPersist(), ghidra::Varnode::setMark(), ghidra::ParameterPieces::type, ghidra::TYPE_UNKNOWN, and ghidra::Architecture::types.

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

◆ updateOutputNoTypes()

void ghidra::FuncProto::updateOutputNoTypes ( const vector< Varnode *> &  triallist,
TypeFactory factory 
)

Update the return value based on Varnode trials, but don't store the data-type.

If the output parameter is locked, don't do anything. Otherwise, given a list of (at most 1) Varnode, create a return value, grabbing size information from the Varnode. An undefined data-type is created from the given TypeFactory. Any old return value is removed.

Parameters
triallistis the list of Varnodes
factoryis the given TypeFactory

References ghidra::ParameterPieces::addr, ghidra::ParameterPieces::flags, ghidra::TypeFactory::getBase(), ghidra::ParameterPieces::type, and ghidra::TYPE_UNKNOWN.

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

◆ updateOutputTypes()

void ghidra::FuncProto::updateOutputTypes ( const vector< Varnode *> &  triallist)

Update the return value based on Varnode trials.

If the output parameter is locked, don't do anything. Otherwise, given a list of (at most 1) Varnode, create a return value, grabbing data-type information from the Varnode. Any old return value is removed.

Parameters
triallistis the list of Varnodes

References ghidra::ParameterPieces::addr, ghidra::ParameterPieces::flags, ghidra::ProtoParameter::getAddress(), ghidra::ProtoParameter::getSize(), ghidra::AddrSpace::getType(), ghidra::ProtoParameter::isSizeTypeLocked(), ghidra::ProtoParameter::isTypeLocked(), ghidra::ProtoParameter::overrideSizeLockType(), and ghidra::ParameterPieces::type.

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

◆ updateThisPointer()

void ghidra::FuncProto::updateThisPointer ( void  )
private

Make sure any "this" parameter is properly marked.

This is called after a new prototype is established (via decode or updateAllTypes) It makes sure that if the ProtoModel calls for a "this" parameter, then the appropriate parameter is explicitly marked as the "this".

References ghidra::ProtoParameter::isHiddenReturn(), and ghidra::ProtoParameter::setThisPointer().


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