Package ghidra.program.model.data
Class Structure.BitOffsetComparator
- java.lang.Object
-
- ghidra.program.model.data.Structure.BitOffsetComparator
-
- All Implemented Interfaces:
java.util.Comparator<java.lang.Object>
- Enclosing interface:
- Structure
public static class Structure.BitOffsetComparator extends java.lang.Object implements java.util.Comparator<java.lang.Object>
BitOffsetComparator
provides ability to compare an normalized bit offset (seegetNormalizedBitfieldOffset(int, int, int, int, boolean)
with aDataTypeComponent
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)
-
-
Constructor Summary
Constructors Constructor Description BitOffsetComparator(boolean bigEndian)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(java.lang.Object o1, java.lang.Object o2)
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.
-
-
-
Method Detail
-
compare
public int compare(java.lang.Object o1, java.lang.Object o2)
- Specified by:
compare
in interfacejava.util.Comparator<java.lang.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 endianess 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 unitstorageSize
- storage unit size (i.e., component length)effectiveBitSize
- size of bitfield in bitsbitOffset
- left shift amount for bitfield based upon a big-endian view of the storage unitbigEndian
- true if big-endian packing applies- Returns:
- normalized bit-offset
-
-