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

An endian aware range of bits contained in a contiguous set of bytes. More...

#include <address.hh>

Public Member Functions

 BitRange (void)
 Construct undefined range.
 
 BitRange (int4 bOff, int4 bSize, bool bigEndian)
 Construct byte range.
 
 BitRange (const BitRange &op2, int4 off, int4 sz)
 Constructor, copy range into new container.
 
 BitRange (int4 bOff, int4 bSize, int4 least, int4 num, bool bigEndian)
 Constructor.
 
bool empty (void) const
 Return true if this is an empty bit range (zero bits)
 
int4 compare (const BitRange &op2) const
 Compare this with another as containers.
 
int4 translateLSB (const BitRange &op2) const
 Translate the leastSigBit of the given range into this reference frame.
 
int4 overlapTest (const BitRange &op2) const
 Characterize the type of overlap between this and another range.
 
void intersection (const BitRange &op2)
 Replace this with the intersection of this with another BitRange.
 
void intersectMask (uintb mask)
 Restrict this with a mask that lines up with the container.
 
void shift (int4 leftShiftAmount)
 Replace this with the shifted range.
 
void truncateMostSigBytes (int4 num)
 Truncate the most significant bytes in the byte container.
 
void truncateLeastSigBytes (int4 num)
 Truncate the least significant bytes in the byte container.
 
void extendBytes (int4 num)
 Add most significant bytes to the container.
 
uintb getMask (void) const
 Get mask representing this range.
 
bool isByteRange (void) const
 Return true if this bit range is also a byte range.
 
bool isMostSignificant (void) const
 Return true if the bit range occupies the most significant bits of the container.
 
void minimizeContainer (void)
 Shrink the container to fit the bit range.
 
void expandToMost (void)
 Expand the bitrange until it includes the most significant bits of the container.
 

Public Attributes

int4 byteOffset
 Byte offset of the region containing the range.
 
int4 byteSize
 Size of the region in bytes.
 
int4 leastSigBit
 Least significant bit of the bit-range within its region.
 
int4 numBits
 Number of bits in the range.
 
bool isBigEndian
 Is the underlying encoding big endian.
 

Detailed Description

An endian aware range of bits contained in a contiguous set of bytes.

Member Function Documentation

◆ compare()

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

Compare this with another as containers.

Both the byte container and the bit range are compared and must be equal to return 0.

Parameters
op2is the other bit range to compare with
Returns
-1, 0, or 1 to establish ordering the two ranges

References byteOffset, byteSize, leastSigBit, and numBits.

Referenced by ghidra::TypeBitField::compare(), and ghidra::TypeBitField::compareDependency().

◆ extendBytes()

void ghidra::BitRange::extendBytes ( int4  num)

Add most significant bytes to the container.

Only the container is affected, the bit range itself does not change.

Parameters
numis the number of bytes to add

References byteOffset, byteSize, and isBigEndian.

Referenced by ghidra::BitFieldTransform::findOverwrite(), and ghidra::BitFieldInsertTransform::handleSubpieceBack().

◆ getMask()

uintb ghidra::BitRange::getMask ( void  ) const

◆ intersection()

void ghidra::BitRange::intersection ( const BitRange op2)

Replace this with the intersection of this with another BitRange.

The byte container for this does not change only leastSigBit and numBits. If the intersection is empty, numBits is set to 0.

Parameters
op2is the bit range to intersect with this.

References leastSigBit, numBits, and translateLSB().

◆ intersectMask()

void ghidra::BitRange::intersectMask ( uintb  mask)

Restrict this with a mask that lines up with the container.

The range of bits is intersected with the 1-bits of the mask. The resulting range is the minimal cover of the bits in the intersection.

Parameters
maskis the mask to intersect with

References getMask(), leastSigBit, and numBits.

Referenced by ghidra::BitFieldTransform::findOverwrite(), ghidra::BitFieldInsertTransform::handleAndBack(), and ghidra::BitFieldInsertTransform::processBackward().

◆ isByteRange()

bool ghidra::BitRange::isByteRange ( void  ) const

Return true if this bit range is also a byte range.

Returns
true if the beginning and end of the range fall on byte boundaries

References leastSigBit, and numBits.

Referenced by ghidra::TypeStruct::decodeBitField().

◆ isMostSignificant()

bool ghidra::BitRange::isMostSignificant ( void  ) const

Return true if the bit range occupies the most significant bits of the container.

Returns
true if the most significant bit of the field and the container are the same

References byteSize, leastSigBit, and numBits.

Referenced by ghidra::BitFieldNodeState::BitFieldNodeState(), ghidra::BitFieldPullTransform::handleAndForward(), ghidra::BitFieldPullTransform::handleLeftForward(), ghidra::BitFieldPullTransform::handleLessForward(), and ghidra::BitFieldPullTransform::handleMultForward().

◆ overlapTest()

int4 ghidra::BitRange::overlapTest ( const BitRange op2) const

Characterize the type of overlap between this and another range.

Return:

  • -1 if this should come before (no intersection)
  • 0 if this and op2 are the same bitrange
  • 1 if this should come after (no intersection)
  • 2 if this is contained in op2
  • 3 if op2 is contained in this
  • 4 if partial overlap
Parameters
op2is the other range to compare
Returns
the intersection code

this contained in op2

op2 contained in this

References isBigEndian, leastSigBit, numBits, and translateLSB().

Referenced by ghidra::TypeStruct::collectBitFields(), ghidra::BitFieldTransform::establishFields(), ghidra::TypeStruct::findMatchingBitField(), and ghidra::TypeStruct::hasBitFieldsInRange().

◆ shift()

void ghidra::BitRange::shift ( int4  leftShiftAmount)

◆ translateLSB()

int4 ghidra::BitRange::translateLSB ( const BitRange op2) const

Translate the leastSigBit of the given range into this reference frame.

The returned result is directly comparable with leastSigBit for determining order/overlap.

Parameters
op2is the other BitRange to translate into this frame
Returns
the translated value of op2.leastSigBit

References byteOffset, byteSize, isBigEndian, and leastSigBit.

Referenced by BitRange(), ghidra::BitFieldTransform::establishFields(), intersection(), and overlapTest().

◆ truncateLeastSigBytes()

void ghidra::BitRange::truncateLeastSigBytes ( int4  num)

Truncate the least significant bytes in the byte container.

Parameters
numis the number of bytes to truncate

References byteOffset, byteSize, isBigEndian, leastSigBit, and numBits.

Referenced by ghidra::BitFieldPullTransform::handleSubpieceForward().

◆ truncateMostSigBytes()

void ghidra::BitRange::truncateMostSigBytes ( int4  num)

Truncate the most significant bytes in the byte container.

The number of bits may be affected.

Parameters
numis the number of bytes to truncate

References byteOffset, byteSize, isBigEndian, leastSigBit, and numBits.

Referenced by ghidra::BitFieldPullTransform::handleSubpieceForward(), and ghidra::BitFieldInsertTransform::handleZextBack().


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