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

A contiguous range of memory that can be used to pass parameters. More...

#include <fspec.hh>

Public Types

enum  {
  force_left_justify = 1, reverse_stack = 2, smallsize_zext = 4, smallsize_sext = 8,
  smallsize_inttype = 32, smallsize_floatext = 64, extracheck_high = 128, extracheck_low = 256,
  is_grouped = 512, overlapping = 0x100
}
 
enum  { no_containment, contains_unjustified, contains_justified, contained_by }
 

Public Member Functions

 ParamEntry (int4 grp)
 Constructor for use with decode.
 
int4 getGroup (void) const
 Get the group id this belongs to.
 
const vector< int4 > & getAllGroups (void) const
 Get all group numbers this overlaps.
 
bool groupOverlap (const ParamEntry &op2) const
 Check if this and op2 occupy any of the same groups. More...
 
int4 getSize (void) const
 Get the size of the memory range in bytes.
 
int4 getMinSize (void) const
 Get the minimum size of a logical value contained in this.
 
int4 getAlign (void) const
 Get the alignment of this entry.
 
JoinRecordgetJoinRecord (void) const
 Get record describing joined pieces (or null if only 1 piece)
 
type_metatype getType (void) const
 Get the data-type class associated with this.
 
bool isExclusion (void) const
 Return true if this holds a single parameter exclusively.
 
bool isReverseStack (void) const
 Return true if parameters are allocated in reverse order.
 
bool isGrouped (void) const
 Return true if this is grouped with other entries.
 
bool isOverlap (void) const
 Return true if this overlaps another entry.
 
bool subsumesDefinition (const ParamEntry &op2) const
 Does this subsume the definition of the given ParamEntry. More...
 
bool containedBy (const Address &addr, int4 sz) const
 Is this entry contained by the given range. More...
 
bool intersects (const Address &addr, int4 sz) const
 Does this intersect the given range in some way. More...
 
int4 justifiedContain (const Address &addr, int4 sz) const
 Calculate endian aware containment. More...
 
bool getContainer (const Address &addr, int4 sz, VarnodeData &res) const
 Calculate the containing memory range. More...
 
bool contains (const ParamEntry &op2) const
 Does this contain the given entry (as a subpiece) More...
 
OpCode assumedExtension (const Address &addr, int4 sz, VarnodeData &res) const
 Calculate the type of extension to expect for the given logical value. More...
 
int4 getSlot (const Address &addr, int4 skip) const
 Calculate the slot occupied by a specific address. More...
 
AddrSpacegetSpace (void) const
 Get the address space containing this entry.
 
uintb getBase (void) const
 Get the starting offset of this entry.
 
Address getAddrBySlot (int4 &slot, int4 sz) const
 Calculate the storage address assigned when allocating a parameter of a given size. More...
 
void decode (Decoder &decoder, bool normalstack, bool grouped, list< ParamEntry > &curList)
 Decode a <pentry> element into this object. More...
 
bool isParamCheckHigh (void) const
 Return true if there is a high overlap.
 
bool isParamCheckLow (void) const
 Return true if there is a low overlap.
 

Static Public Member Functions

static void orderWithinGroup (const ParamEntry &entry1, const ParamEntry &entry2)
 Enforce ParamEntry group ordering rules. More...
 

Private Member Functions

void resolveJoin (list< ParamEntry > &curList)
 Make adjustments for a join ParamEntry. More...
 
void resolveOverlap (list< ParamEntry > &curList)
 Make adjustments for ParamEntry that overlaps others. More...
 
bool isLeftJustified (void) const
 Is the logical value left-justified within its container.
 

Static Private Member Functions

static const ParamEntryfindEntryByStorage (const list< ParamEntry > &entryList, const VarnodeData &vn)
 Find a ParamEntry matching the given storage Varnode. More...
 

Private Attributes

uint4 flags
 Boolean properties of the parameter.
 
type_metatype type
 Data-type class that this entry must match.
 
vector< int4 > groupSet
 Group(s) this entry belongs to.
 
AddrSpacespaceid
 Address space containing the range.
 
uintb addressbase
 Starting offset of the range.
 
int4 size
 Size of the range in bytes.
 
int4 minsize
 Minimum bytes allowed for the logical value.
 
int4 alignment
 How much alignment (0 means only 1 logical value is allowed)
 
int4 numslots
 (Maximum) number of slots that can store separate parameters
 
JoinRecordjoinrec
 Non-null if this is logical variable from joined pieces.
 

Detailed Description

A contiguous range of memory that can be used to pass parameters.

This range can be used to pass a single parameter (isExclusion() == true). This is intended to model a parameter passed in a register. The logical value does not have to fill the entire range. The size in bytes can range from a minimum, getMinSize(), to the whole range, getSize(). Justification and extension of the logical value within the range can be specified.

Alternately the range can be used as a resource for multiple parameters (isExclusion() == false). In this case, the parameters are allocated sequentially (usually) starting from the front of the range. The amount of space consumed by each parameter is dictated by an alignment setting in bytes.

A ParamEntry can be associated with a particular class of data-types. Usually:

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
force_left_justify 

Big endian values are left justified within their slot.

reverse_stack 

Slots (for non-exlusion entries) are allocated in reverse order.

smallsize_zext 

Assume values that are below the max size are zero extended into this container.

smallsize_sext 

Assume values that are below the max size are sign extended into this container.

smallsize_inttype 

Assume values that are below the max size are sign OR zero extended based on integer type.

smallsize_floatext 

Assume values smaller than max size are floating-point extended to full size.

extracheck_high 

Perform extra checks during parameter recovery on most sig portion of the double.

extracheck_low 

Perform extra checks during parameter recovery on least sig portion of the double.

is_grouped 

This entry is grouped with other entries.

overlapping 

Overlaps an earlier entry (and doesn't consume additional resource slots)

◆ anonymous enum

anonymous enum
Enumerator
no_containment 

Range neither contains nor is contained by a ParamEntry.

contains_unjustified 

ParamEntry contains range, but the range does not cover the least significant bytes.

contains_justified 

ParamEntry contains range, which covers the least significant bytes.

contained_by 

ParamEntry is contained by the range.

Member Function Documentation

◆ assumedExtension()

OpCode ghidra::ParamEntry::assumedExtension ( const Address addr,
int4  sz,
VarnodeData res 
) const

Calculate the type of extension to expect for the given logical value.

Return:

  • CPUI_COPY if no extensions are assumed for small values in this container
  • CPUI_INT_SEXT indicates a sign extension
  • CPUI_INT_ZEXT indicates a zero extension
  • CPUI_PIECE indicates an integer extension based on type of parameter

(A CPUI_FLOAT2FLOAT=float extension is handled by heritage and JoinRecord) If returning an extension operator, pass back the container being extended.

Parameters
addris the starting address of the logical value
szis the size of the logical value in bytes
reswill hold the passed back containing range
Returns
the type of extension

References addressbase, alignment, ghidra::CPUI_COPY, ghidra::CPUI_INT_SEXT, ghidra::CPUI_INT_ZEXT, ghidra::CPUI_PIECE, flags, ghidra::Address::getOffset(), joinrec, justifiedContain(), ghidra::VarnodeData::offset, ghidra::VarnodeData::size, size, smallsize_inttype, smallsize_sext, smallsize_zext, ghidra::VarnodeData::space, and spaceid.

◆ containedBy()

bool ghidra::ParamEntry::containedBy ( const Address addr,
int4  sz 
) const

Is this entry contained by the given range.

We assume a join ParamEntry cannot be contained by a single contiguous memory range.

Parameters
addris the starting address of the potential containing range
szis the number of bytes in the range
Returns
true if the entire ParamEntry fits inside the range

References addressbase, ghidra::Address::getOffset(), ghidra::Address::getSpace(), size, and spaceid.

Referenced by ghidra::ParamListStandard::characterizeAsParam(), contains(), and ghidra::ParamListStandard::getBiggestContainedParam().

◆ contains()

bool ghidra::ParamEntry::contains ( const ParamEntry op2) const

Does this contain the given entry (as a subpiece)

Test that this, as one or more memory ranges, contains the other ParamEntry's memory range. A join ParamEntry cannot be contained by another entry, but it can contain an entry in one of its pieces.

Parameters
op2is the given ParamEntry to test for containment
Returns
true if the given ParamEntry is contained

References addressbase, containedBy(), ghidra::JoinRecord::getPiece(), joinrec, ghidra::JoinRecord::numPieces(), size, and spaceid.

Referenced by resolveOverlap().

◆ decode()

void ghidra::ParamEntry::decode ( Decoder decoder,
bool  normalstack,
bool  grouped,
list< ParamEntry > &  curList 
)

◆ findEntryByStorage()

const ParamEntry * ghidra::ParamEntry::findEntryByStorage ( const list< ParamEntry > &  entryList,
const VarnodeData vn 
)
staticprivate

Find a ParamEntry matching the given storage Varnode.

Search through the list backward.

Parameters
entryListis the list of ParamEntry to search through
vnis the storage to search for
Returns
the matching ParamEntry or null

References addressbase, ghidra::VarnodeData::offset, ghidra::VarnodeData::size, size, ghidra::VarnodeData::space, and spaceid.

Referenced by resolveJoin().

◆ getAddrBySlot()

Address ghidra::ParamEntry::getAddrBySlot ( int4 &  slotnum,
int4  sz 
) const

Calculate the storage address assigned when allocating a parameter of a given size.

Assume slotnum slots have already been assigned and increment slotnum by the number of slots used. Return an invalid address if the size is too small or if there are not enough slots left.

Parameters
slotnumis a reference to used slots (which will be updated)
szis the size of the parameter to allocated
Returns
the address of the new parameter (or an invalid address)

References addressbase, alignment, ghidra::AddrSpaceManager::constructFloatExtensionAddress(), flags, ghidra::AddrSpace::getManager(), isLeftJustified(), isReverseStack(), minsize, numslots, size, smallsize_floatext, and spaceid.

Referenced by ghidra::ParamListStandard::assignAddress(), and ghidra::ParamListStandard::buildTrialMap().

◆ getContainer()

bool ghidra::ParamEntry::getContainer ( const Address addr,
int4  sz,
VarnodeData res 
) const

Calculate the containing memory range.

Pass back the VarnodeData (space,offset,size) of the parameter that would contain the given memory range. If this contains the range and is exclusive, just pass back this memory range. Otherwise the passed back range will depend on alignment.

Parameters
addris the starting address of the given range
szis the size of the given range in bytes
resis the reference to VarnodeData that will be passed back
Returns
true if the given range is contained at all

References addressbase, alignment, ghidra::Address::getOffset(), ghidra::JoinRecord::getPiece(), joinrec, ghidra::JoinRecord::numPieces(), ghidra::VarnodeData::offset, ghidra::Address::overlap(), ghidra::VarnodeData::size, size, ghidra::VarnodeData::space, and spaceid.

◆ getSlot()

int4 ghidra::ParamEntry::getSlot ( const Address addr,
int4  skip 
) const

Calculate the slot occupied by a specific address.

For non-exclusive entries, the memory range can be divided up into slots, which are chunks that take up a full alignment. I.e. for an entry with alignment 4, slot 0 is bytes 0-3 of the range, slot 1 is bytes 4-7, etc. Assuming the given address is contained in this entry, and we skip ahead a number of bytes, return the slot associated with that byte. NOTE: its important that the given address has already been checked for containment.

Parameters
addris the given address
skipis the number of bytes to skip ahead
Returns
the slot index

References addressbase, alignment, ghidra::Address::getOffset(), groupSet, isReverseStack(), and numslots.

Referenced by ghidra::ParamListStandard::buildTrialMap(), ghidra::ParamActive::freePlaceholderSlot(), ghidra::ParamListStandard::possibleParamWithSlot(), and ghidra::ParamTrial::slotGroup().

◆ groupOverlap()

bool ghidra::ParamEntry::groupOverlap ( const ParamEntry op2) const

Check if this and op2 occupy any of the same groups.

Parameters
op2is the other entry to compare
Returns
true if the group sets associated with each ParamEntry intersect at all

References groupSet.

◆ intersects()

bool ghidra::ParamEntry::intersects ( const Address addr,
int4  sz 
) const

Does this intersect the given range in some way.

If this a a join, each piece is tested for intersection. Otherwise, this, considered as a single memory, is tested for intersection.

Parameters
addris the starting address of the given memory range to test against
szis the number of bytes in the given memory range
Returns
true if there is any kind of intersection

References addressbase, ghidra::Address::getOffset(), ghidra::JoinRecord::getPiece(), ghidra::Address::getSpace(), joinrec, ghidra::JoinRecord::numPieces(), ghidra::VarnodeData::offset, size, and spaceid.

Referenced by resolveOverlap().

◆ justifiedContain()

int4 ghidra::ParamEntry::justifiedContain ( const Address addr,
int4  sz 
) const

Calculate endian aware containment.

Check if the given memory range is contained in this. If it is contained, return the endian aware offset of the containment. I.e. if the least significant byte of the given range falls on the least significant byte of the this, return 0. If it intersects the second least significant, return 1, etc.

Parameters
addris the starting address of the given memory range
szis the size of the given memory range in bytes
Returns
the endian aware alignment or -1 if the given range isn't contained

References addressbase, alignment, flags, force_left_justify, ghidra::VarnodeData::getAddr(), ghidra::Address::getOffset(), ghidra::JoinRecord::getPiece(), ghidra::Address::getSpace(), isLeftJustified(), joinrec, ghidra::Address::justifiedContain(), ghidra::JoinRecord::numPieces(), size, and spaceid.

Referenced by assumedExtension(), ghidra::ParamListStandard::characterizeAsParam(), ghidra::ParamListRegisterOut::fillinMap(), and ghidra::ParamListStandard::findEntry().

◆ orderWithinGroup()

void ghidra::ParamEntry::orderWithinGroup ( const ParamEntry entry1,
const ParamEntry entry2 
)
static

Enforce ParamEntry group ordering rules.

Entries within a group must be distinguishable by size or by type. Throw an exception if the entries aren't distinguishable

Parameters
entry1is the first ParamEntry to compare
entry2is the second ParamEntry to compare

References minsize, size, type, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::ParamListStandardOut::decode(), and ghidra::ParamListStandard::parseGroup().

◆ resolveJoin()

void ghidra::ParamEntry::resolveJoin ( list< ParamEntry > &  curList)
private

Make adjustments for a join ParamEntry.

If the ParamEntry is initialized with a join address, cache the join record and adjust the group and groupsize based on the ParamEntrys being overlapped

Parameters
curListis the current list of ParamEntry

References addressbase, extracheck_high, extracheck_low, findEntryByStorage(), ghidra::AddrSpaceManager::findJoin(), flags, ghidra::AddrSpace::getManager(), ghidra::JoinRecord::getPiece(), ghidra::AddrSpace::getType(), groupSet, ghidra::IPTR_JOIN, joinrec, ghidra::JoinRecord::numPieces(), overlapping, and spaceid.

Referenced by decode().

◆ resolveOverlap()

void ghidra::ParamEntry::resolveOverlap ( list< ParamEntry > &  curList)
private

Make adjustments for ParamEntry that overlaps others.

Search for overlaps of this with any previous entry. If an overlap is discovered, verify the form is correct for the different ParamEntry to share group slots and reassign this group.

Parameters
curListis the list of previous entries

References addressbase, contains(), extracheck_high, extracheck_low, flags, groupSet, intersects(), ghidra::AddrSpace::isBigEndian(), isOverlap(), joinrec, overlapping, size, and spaceid.

Referenced by decode().

◆ subsumesDefinition()

bool ghidra::ParamEntry::subsumesDefinition ( const ParamEntry op2) const

Does this subsume the definition of the given ParamEntry.

This entry must properly contain the other memory range, and the entry properties must be compatible. A join ParamEntry can subsume another join ParamEntry, but we expect the addressbase to be identical.

Parameters
op2is the given entry to compare with this
Returns
true if the given entry is subsumed

References addressbase, alignment, size, spaceid, type, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::ParamListMerged::foldIn().


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