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 Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.math.BigInteger getBigInteger​(byte[] b, int size, boolean signed)
      Get the value from the given byte array using the specified size.
      java.math.BigInteger getBigInteger​(byte[] b, int offset, int size, boolean signed)
      Get the value from the given byte array using the specified size.
      byte[] getBytes​(int value)
      Converts the int value to an array of bytes.
      void getBytes​(int value, byte[] b)
      Converts the given value to bytes.
      void getBytes​(int value, byte[] b, int offset)
      Converts the given value to bytes.
      byte[] getBytes​(long value)
      Converts the long value to an array of bytes.
      void getBytes​(long value, byte[] b)
      Converts the given value to bytes.
      void getBytes​(long value, byte[] b, int offset)
      Converts the given value to bytes.
      void getBytes​(long value, int size, byte[] b, int offset)
      Converts the given value to bytes using the number of least significant bytes specified by size.
      byte[] getBytes​(short value)
      Converts the short value to an array of bytes.
      void getBytes​(short value, byte[] b)
      Converts the given value to bytes.
      void getBytes​(short value, byte[] b, int offset)
      Converts the given value to bytes.
      byte[] getBytes​(java.math.BigInteger value, int size)
      Converts the value to an array of bytes.
      void getBytes​(java.math.BigInteger value, int size, byte[] b, int offset)
      Converts the given value to bytes using the number of least significant bytes specified by size.
      int getInt​(byte[] b)
      Get the int value from the given byte array.
      int getInt​(byte[] b, int offset)
      Get the int value from the given byte array.
      long getLong​(byte[] b)
      Get the long value from the given byte array.
      long getLong​(byte[] b, int offset)
      Get the long value from the given byte array.
      short getShort​(byte[] b)
      Get the short value from the given byte array.
      short getShort​(byte[] b, int offset)
      Get the short value from the given byte array.
      long getValue​(byte[] b, int size)
      Get the value from the given byte array using the specified size.
      long getValue​(byte[] b, int offset, int size)
      Get the value from the given byte array using the specified size.
      void putBigInteger​(byte[] b, int offset, int size, java.math.BigInteger value)
      Writes a value of specified size into the byte array at the given offset
      void putBigInteger​(byte[] b, int size, java.math.BigInteger value)
      Writes a value of specified size into the byte array at the given offset
      void putInt​(byte[] b, int value)
      Writes a int value into a byte array.
      void putInt​(byte[] b, int offset, int value)
      Writes a int value into the byte array at the given offset
      void putLong​(byte[] b, int offset, long value)
      Writes a long value into the byte array at the given offset
      void putLong​(byte[] b, long value)
      Writes a long value into a byte array.
      void putShort​(byte[] b, int offset, short value)
      Writes a short value into the byte array at the given offset
      void putShort​(byte[] b, short value)
      Writes a short value into a byte array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LittleEndianDataConverter

        public LittleEndianDataConverter()
        Constructor for BigEndianDataConverter.
    • 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
        See Also:
        DataConverter.getShort(byte[], int)
      • 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
        See Also:
        DataConverter.getInt(byte[], int)
      • 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
        See Also:
        DataConverter.getLong(byte[], int)
      • getValue

        public long getValue​(byte[] b,
                             int size)
        Description copied from interface: DataConverter
        Get the value from the given byte array using the specified size.
        Specified by:
        getValue in interface DataConverter
        Parameters:
        b - array containing bytes
        size - number of bytes to use from array at offset 0
        See Also:
        DataConverter.getValue(byte[], int)
      • getValue

        public long getValue​(byte[] b,
                             int offset,
                             int size)
        Description copied from interface: DataConverter
        Get the value from the given byte array using the specified size.
        Specified by:
        getValue 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
        See Also:
        DataConverter.getValue(byte[], int, int)
      • getBigInteger

        public final java.math.BigInteger getBigInteger​(byte[] b,
                                                        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
        size - number of bytes to use from array at offset 0
      • getBigInteger

        public final 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
      • getBytes

        public void getBytes​(short value,
                             byte[] b,
                             int offset)
        Description copied from interface: DataConverter
        Converts the given value to bytes.
        Specified by:
        getBytes in interface DataConverter
        Parameters:
        value - value to convert to bytes
        b - byte array to store bytes
        offset - offset into byte array to put the bytes
        See Also:
        DataConverter.getBytes(short, byte[], int)
      • getBytes

        public void getBytes​(int value,
                             byte[] b,
                             int offset)
        Description copied from interface: DataConverter
        Converts the given value to bytes.
        Specified by:
        getBytes in interface DataConverter
        Parameters:
        value - value to convert to bytes
        b - byte array to store bytes
        offset - offset into byte array to put the bytes
        See Also:
        DataConverter.getBytes(int, byte[], int)
      • getBytes

        public void getBytes​(long value,
                             byte[] b,
                             int offset)
        Description copied from interface: DataConverter
        Converts the given value to bytes.
        Specified by:
        getBytes in interface DataConverter
        Parameters:
        value - value to convert to bytes
        b - byte array to store bytes
        offset - offset into byte array to put the bytes
        See Also:
        DataConverter.getBytes(long, byte[], int)
      • getBytes

        public void getBytes​(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:
        getBytes 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
        See Also:
        DataConverter.getBytes(long, int, byte[], int)
      • putInt

        public final 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
        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
        See Also:
        DataConverter.putInt(byte[], int, int)
      • putLong

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

        public final 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
        See Also:
        DataConverter.putShort(byte[], int, short)
      • getBytes

        public byte[] getBytes​(int value)
        Description copied from interface: DataConverter
        Converts the int value to an array of bytes.
        Specified by:
        getBytes in interface DataConverter
        Parameters:
        value - int value to be converted
        Returns:
        array of bytes
        See Also:
        DataConverter.getBytes(int)
      • getBytes

        public byte[] getBytes​(java.math.BigInteger value,
                               int size)
        Description copied from interface: DataConverter
        Converts the value to an array of bytes.
        Specified by:
        getBytes in interface DataConverter
        Parameters:
        value - value to be converted
        size - value size in bytes
        Returns:
        array of bytes
      • getBytes

        public void getBytes​(java.math.BigInteger 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:
        getBytes 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
        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
      • putBigInteger

        public void putBigInteger​(byte[] b,
                                  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
        Specified by:
        putBigInteger in interface DataConverter
        Parameters:
        b - array to contain the bytes at offset 0;
        size - number of bytes to be written