Class Structure.BitOffsetComparator

java.lang.Object
ghidra.program.model.data.Structure.BitOffsetComparator
All Implemented Interfaces:
Comparator<Object>
Enclosing interface:
Structure

public static class Structure.BitOffsetComparator extends Object implements Comparator<Object>
BitOffsetComparator provides ability to compare an normalized bit offset (see getNormalizedBitfieldOffset(int, int, int, int, boolean)) with a DataTypeComponent object. The offset will be considered equal (0) if the component contains the offset. A normalized component bit numbering is used to establish the footprint of each component with an ordinal-based ordering (assumes specific LE/BE allocation rules). Bit offsets for this comparator number the first allocated bit of the structure as 0 and the last allocated bit of the structure as (8 * structLength) - 1. For big-endian bitfields the msb of the bitfield will be assigned the lower bit-number (assumes msb-allocated-first), while little-endian will perform similar numbering assuming byte-swap and bit-reversal of the storage unit (assumes lsb-allocated-first). Both cases result in a normalized view where normalized bit-0 is allocated first.
 
 Example:
    
 Big-Endian (normalized view):
    | . . . . . . . 7 | 8 9 . . . . . . |
    |<--------------------------------->| storage-size (2-bytes)
                        |<--------------| bit-offset (6, lsb position within storage unit)
                    |<--->|               bit-size (3)
                        
 Little-Endian (normalized view, w/ storage byte-swap and bit-reversal):
    | . . . . . . 6 7 | 8 . . . . . . . |
    |------------>|                       bit-offset (6, lsb position within storage unit)
                  |<--->|                 bit-size (3)
 
 
  • Field Details

  • Constructor Details

    • BitOffsetComparator

      public BitOffsetComparator(boolean bigEndian)
  • Method Details

    • compare

      public int compare(Object o1, Object o2)
      Specified by:
      compare in interface Comparator<Object>
    • getNormalizedBitfieldOffset

      public static int getNormalizedBitfieldOffset(int byteOffset, int storageSize, int effectiveBitSize, int bitOffset, boolean bigEndian)
      Compute the normalized bit offset of a bitfield relative to the start of a structure. NOTE: This implementation currently relies only on endianness to dictate bit allocation ordering. If future support is added for alternate bitfield packing, this implementation will require modification.
      Parameters:
      byteOffset - byte offset within structure of storage unit
      storageSize - storage unit size (i.e., component length)
      effectiveBitSize - size of bitfield in bits
      bitOffset - left shift amount for bitfield based upon a big-endian view of the storage unit
      bigEndian - true if big-endian packing applies
      Returns:
      normalized bit-offset