Package ghidra.util

Class LittleEndianDataConverter

  • All Implemented Interfaces:
    DataConverter, java.io.Serializable
    Direct Known Subclasses:
    GhidraLittleEndianDataConverter

    public class LittleEndianDataConverter
    extends java.lang.Object
    implements DataConverter
    Helper class to convert a byte array to a Java primitive in Little endian order, and to convert a primitive to a byte array.
    See Also:
    Serialized Form
    • Method Detail

      • getShort

        public short getShort​(byte[] b,
                              int offset)
        Description copied from interface: DataConverter
        Get the short value from the given byte array.
        Specified by:
        getShort in interface DataConverter
        Parameters:
        b - array containing bytes
        offset - offset into byte array for getting the short
        Returns:
        signed short value
      • getInt

        public int getInt​(byte[] b,
                          int offset)
        Description copied from interface: DataConverter
        Get the int value from the given byte array.
        Specified by:
        getInt in interface DataConverter
        Parameters:
        b - array containing bytes
        offset - offset into byte array for getting the int
        Returns:
        signed int value
      • getLong

        public long getLong​(byte[] b,
                            int offset)
        Description copied from interface: DataConverter
        Get the long value from the given byte array.
        Specified by:
        getLong in interface DataConverter
        Parameters:
        b - array containing bytes
        offset - offset into byte array for getting the long
        Returns:
        signed long value
      • getValue

        public long getValue​(byte[] b,
                             int offset,
                             int size)
        Description copied from interface: DataConverter
        Get the unsigned value from the given byte array using the specified integer size, returned as a long.

        Values with a size less than sizeof(long) will not have their sign bit extended and therefore will appear as an 'unsigned' value.

        Casting the 'unsigned' long value to the correctly sized smaller java primitive will cause the value to appear as a signed value.

        Values of size 8 (ie. longs) will be signed.

        Specified by:
        getValue in interface DataConverter
        Parameters:
        b - array containing bytes
        offset - offset into byte array for getting the long
        size - number of bytes (1 - 8) to use from array
        Returns:
        unsigned value
      • getBigInteger

        public java.math.BigInteger getBigInteger​(byte[] b,
                                                  int offset,
                                                  int size,
                                                  boolean signed)
        Description copied from interface: DataConverter
        Get the value from the given byte array using the specified size.
        Specified by:
        getBigInteger in interface DataConverter
        Parameters:
        b - array containing bytes
        offset - offset into byte array for getting the long
        size - number of bytes to use from array
        signed - boolean flag indicating the value is signed
        Returns:
        BigInteger with value
      • putShort

        public void putShort​(byte[] b,
                             int offset,
                             short value)
        Description copied from interface: DataConverter
        Writes a short value into the byte array at the given offset
        Specified by:
        putShort in interface DataConverter
        Parameters:
        b - array to contain the bytes
        offset - the offset into the byte array to store the value
        value - the short value
      • putInt

        public void putInt​(byte[] b,
                           int offset,
                           int value)
        Description copied from interface: DataConverter
        Writes a int value into the byte array at the given offset.

        See DataConverter.getBytes(int, byte[], int)

        Specified by:
        putInt in interface DataConverter
        Parameters:
        b - array to contain the bytes
        offset - the offset into the byte array to store the value
        value - the int value
      • putValue

        public void putValue​(long value,
                             int size,
                             byte[] b,
                             int offset)
        Description copied from interface: DataConverter
        Converts the given value to bytes using the number of least significant bytes specified by size.

        Specified by:
        putValue in interface DataConverter
        Parameters:
        value - value to convert to bytes
        size - number of least significant bytes of value to be written to the byte array
        b - byte array to store bytes
        offset - offset into byte array to put the bytes
      • putBigInteger

        public void putBigInteger​(byte[] b,
                                  int offset,
                                  int size,
                                  java.math.BigInteger value)
        Description copied from interface: DataConverter
        Writes a value of specified size into the byte array at the given offset

        See DataConverter.getBytes(BigInteger, int, byte[], int)

        Specified by:
        putBigInteger in interface DataConverter
        Parameters:
        b - array to contain the bytes
        offset - the offset into the byte array to store the value
        size - number of bytes to be written
        value - BigInteger value to convert