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

Partial data-type information mapped to a specific range of bytes. More...

#include <varmap.hh>

Public Types

enum  RangeType { fixed = 0, open = 1, endpoint = 2 }
 The basic categorization of the range. More...
 

Public Member Functions

 RangeHint (void)
 Uninitialized constructor.
 
 RangeHint (uintb st, int4 sz, intb sst, Datatype *ct, uint4 fl, RangeType rt, int4 hi)
 Initialized constructor.
 
bool reconcile (const RangeHint *b) const
 Can the given intersecting RangeHint coexist with this at their given offsets. More...
 
bool contain (const RangeHint *b) const
 Return true if this or the given range contains the other. More...
 
bool preferred (const RangeHint *b, bool reconcile) const
 Return true if the this range's data-type is preferred over the other given range. More...
 
bool attemptJoin (RangeHint *b)
 Try to concatenate another RangeHint onto this. More...
 
void absorb (RangeHint *b)
 Absorb the other RangeHint into this. More...
 
bool merge (RangeHint *b, AddrSpace *space, TypeFactory *typeFactory)
 Try to form the union of this with another RangeHint. More...
 
int4 compare (const RangeHint &op2) const
 Order this with another RangeHint. More...
 

Static Public Member Functions

static bool compareRanges (const RangeHint *a, const RangeHint *b)
 Compare two RangeHint pointers.
 

Private Attributes

uintb start
 Starting offset of this range of bytes.
 
int4 size
 Number of bytes in a single element of this range.
 
intb sstart
 A signed version of the starting offset.
 
Datatypetype
 Putative data-type for a single element of this range.
 
uint4 flags
 Additional boolean properties of this range.
 
RangeType rangeType
 The type of range.
 
int4 highind
 Minimum upper bound on the array index (if this is open)
 

Friends

class MapState
 
class ScopeLocal
 

Detailed Description

Partial data-type information mapped to a specific range of bytes.

This object gives a hint about the data-type for a sequence of bytes starting at a specific address offset (typically on the stack). It describes where the data-type starts, what data-type it might be, and how far it extends from the start point (possibly as an array).

Member Enumeration Documentation

◆ RangeType

The basic categorization of the range.

Enumerator
fixed 

A data-type with a fixed size.

open 

An array with a (possibly unknown) number of elements.

endpoint 

An (artificial) boundary to the range of bytes getting analyzed.

Member Function Documentation

◆ absorb()

void ghidra::RangeHint::absorb ( RangeHint b)

Absorb the other RangeHint into this.

Absorb details of the other RangeHint into this, except for the data-type. Inherit an open range type and any indexing information. The data-type for this is assumed to be compatible and preferred over the other data-type and is not changed.

Parameters
bis the other RangeHint to absorb

References ghidra::Datatype::getSize(), highind, open, rangeType, sstart, and type.

Referenced by attemptJoin(), and merge().

◆ attemptJoin()

bool ghidra::RangeHint::attemptJoin ( RangeHint b)

Try to concatenate another RangeHint onto this.

If this RangeHint is an array and the following RangeHint line up, adjust this so that it absorbs the other given RangeHint and return true. The second RangeHint:

  • must have the same element size
  • must have close to the same data-type
  • must line up with the step of the first array
  • must not be a locked data-type
  • must not extend the size of the first array beyond what is known of its limits
Parameters
bis the other RangeHint to absorb
Returns
true if the other RangeHint was successfully absorbed

References absorb(), endpoint, flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), highind, open, rangeType, sstart, type, ghidra::TYPE_INT, ghidra::TYPE_PTR, ghidra::TYPE_UINT, ghidra::TYPE_UNKNOWN, and ghidra::Varnode::typelock.

Referenced by ghidra::ScopeLocal::restructure().

◆ compare()

int4 ghidra::RangeHint::compare ( const RangeHint op2) const

Order this with another RangeHint.

Compare (signed) offset, size, RangeType, type lock, and high index, in that order. Datatype is not compared.

Parameters
op2is the other RangeHint to compare with this
Returns
-1, 0, or 1 depending on if this comes before, is equal to, or comes after

References flags, highind, rangeType, size, sstart, and ghidra::Varnode::typelock.

Referenced by compareRanges(), and ghidra::MapState::reconcileDatatypes().

◆ contain()

bool ghidra::RangeHint::contain ( const RangeHint b) const

Return true if this or the given range contains the other.

We assume this range starts at least as early as the given range and that the two ranges intersect.

Parameters
bis the given range to check for containment with this
Returns
true if one contains the other

References size, and sstart.

Referenced by merge().

◆ merge()

bool ghidra::RangeHint::merge ( RangeHint b,
AddrSpace space,
TypeFactory typeFactory 
)

Try to form the union of this with another RangeHint.

Given that this and the other RangeHint intersect, redefine this so that it becomes the union of the two original ranges. The union must succeed in some form. An attempt is made to preserve the data-type information of both the original ranges, but changes will be made if necessary. An exception is thrown if the data-types are locked and cannot be reconciled.

Parameters
bis the other RangeHint to merge with this
spaceis the address space holding the ranges
typeFactoryis a factory for producing data-types
Returns
true if there was an overlap that could be reconciled

References absorb(), contain(), fixed, flags, ghidra::TypeFactory::getBase(), ghidra::Datatype::getName(), highind, open, preferred(), rangeType, reconcile(), size, sstart, start, type, ghidra::TYPE_UNKNOWN, and ghidra::Varnode::typelock.

Referenced by ghidra::ScopeLocal::restructure().

◆ preferred()

bool ghidra::RangeHint::preferred ( const RangeHint b,
bool  reconcile 
) const

Return true if the this range's data-type is preferred over the other given range.

A locked data-type is preferred over unlocked. A fixed size over open size. Otherwise data-type ordering is used.

Parameters
bis the other given range
reconcileis true is the two ranges have reconciled data-types
Returns
true if this ranges's data-type is preferred

References flags, open, rangeType, start, type, ghidra::Varnode::typelock, and ghidra::Datatype::typeOrder().

Referenced by merge().

◆ reconcile()

bool ghidra::RangeHint::reconcile ( const RangeHint b) const

Can the given intersecting RangeHint coexist with this at their given offsets.

Determine if the data-type information in the two ranges line up properly, in which case the union of the two ranges can exist without destroying data-type information.

Parameters
bis the range to reconcile with this
Returns
true if the data-type information can be reconciled

References flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::getSubType(), sstart, type, ghidra::TYPE_ARRAY, ghidra::TYPE_INT, ghidra::TYPE_STRUCT, ghidra::TYPE_UINT, ghidra::TYPE_UNION, ghidra::TYPE_UNKNOWN, and ghidra::Varnode::typelock.

Referenced by merge().


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