Package ghidra.util
Class LittleEndianDataConverter
- java.lang.Object
-
- ghidra.util.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
-
-
Field Summary
Fields Modifier and Type Field Description static LittleEndianDataConverter
INSTANCE
-
Constructor Summary
Constructors Constructor Description LittleEndianDataConverter()
Constructor for BigEndianDataConverter.
-
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 offsetvoid
putBigInteger(byte[] b, int size, java.math.BigInteger value)
Writes a value of specified size into the byte array at the given offsetvoid
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 offsetvoid
putLong(byte[] b, int offset, long value)
Writes a long value into the byte array at the given offsetvoid
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 offsetvoid
putShort(byte[] b, short value)
Writes a short value into a byte array.
-
-
-
Field Detail
-
INSTANCE
public static LittleEndianDataConverter INSTANCE
-
-
Method Detail
-
getShort
public final short getShort(byte[] b)
Description copied from interface:DataConverter
Get the short value from the given byte array.- Specified by:
getShort
in interfaceDataConverter
- Parameters:
b
- array containing bytes- See Also:
DataConverter.getShort(byte[])
-
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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the short- See Also:
DataConverter.getShort(byte[], int)
-
getInt
public final int getInt(byte[] b)
Description copied from interface:DataConverter
Get the int value from the given byte array.- Specified by:
getInt
in interfaceDataConverter
- Parameters:
b
- array containing bytes- See Also:
DataConverter.getInt(byte[])
-
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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the int- See Also:
DataConverter.getInt(byte[], int)
-
getLong
public final long getLong(byte[] b)
Description copied from interface:DataConverter
Get the long value from the given byte array.- Specified by:
getLong
in interfaceDataConverter
- Parameters:
b
- array containing bytes- See Also:
DataConverter.getLong(byte[])
-
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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytessize
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the longsize
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytessize
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the longsize
- number of bytes to use from array
-
getBytes
public final void getBytes(short value, byte[] b)
Description copied from interface:DataConverter
Converts the given value to bytes.- Specified by:
getBytes
in interfaceDataConverter
- Parameters:
value
- value to convert to bytesb
- byte array to store bytes- See Also:
DataConverter.getBytes(short, byte[])
-
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 interfaceDataConverter
- Parameters:
value
- value to convert to bytesb
- byte array to store bytesoffset
- offset into byte array to put the bytes- See Also:
DataConverter.getBytes(short, byte[], int)
-
getBytes
public final void getBytes(int value, byte[] b)
Description copied from interface:DataConverter
Converts the given value to bytes.- Specified by:
getBytes
in interfaceDataConverter
- Parameters:
value
- value to convert to bytesb
- byte array to store bytes- See Also:
DataConverter.getBytes(int, byte[])
-
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 interfaceDataConverter
- Parameters:
value
- value to convert to bytesb
- byte array to store bytesoffset
- offset into byte array to put the bytes- See Also:
DataConverter.getBytes(int, byte[], int)
-
getBytes
public final void getBytes(long value, byte[] b)
Description copied from interface:DataConverter
Converts the given value to bytes.- Specified by:
getBytes
in interfaceDataConverter
- Parameters:
value
- value to convert to bytesb
- byte array to store bytes- See Also:
DataConverter.getBytes(long, byte[])
-
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 interfaceDataConverter
- Parameters:
value
- value to convert to bytesb
- byte array to store bytesoffset
- 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 interfaceDataConverter
- Parameters:
value
- value to convert to bytessize
- number of least significant bytes of value to be written to the byte arrayb
- byte array to store bytesoffset
- 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 interfaceDataConverter
- 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)
-
putInt
public final void putInt(byte[] b, int value)
Description copied from interface:DataConverter
Writes a int value into a byte array.- Specified by:
putInt
in interfaceDataConverter
- Parameters:
b
- array to contain the bytes;value
- the int value- See Also:
DataConverter.putInt(byte[], 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 interfaceDataConverter
- 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)
-
putLong
public final void putLong(byte[] b, long value)
Description copied from interface:DataConverter
Writes a long value into a byte array.- Specified by:
putLong
in interfaceDataConverter
- Parameters:
b
- array to contain the bytes;value
- the long value- See Also:
DataConverter.putLong(byte[], 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 interfaceDataConverter
- 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)
-
putShort
public final void putShort(byte[] b, short value)
Description copied from interface:DataConverter
Writes a short value into a byte array.- Specified by:
putShort
in interfaceDataConverter
- Parameters:
b
- array to contain the bytes;value
- the short value- See Also:
DataConverter.putShort(byte[], 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 interfaceDataConverter
- Parameters:
value
- int value to be converted- Returns:
- array of bytes
- See Also:
DataConverter.getBytes(int)
-
getBytes
public byte[] getBytes(long value)
Description copied from interface:DataConverter
Converts the long value to an array of bytes.- Specified by:
getBytes
in interfaceDataConverter
- Parameters:
value
- long value to be converted- Returns:
- array of bytes
- See Also:
DataConverter.getBytes(long)
-
getBytes
public byte[] getBytes(short value)
Description copied from interface:DataConverter
Converts the short value to an array of bytes.- Specified by:
getBytes
in interfaceDataConverter
- Parameters:
value
- short value to be converted- Returns:
- array of bytes
- See Also:
DataConverter.getBytes(short)
-
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 interfaceDataConverter
- Parameters:
value
- value to be convertedsize
- 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 interfaceDataConverter
- Parameters:
value
- value to convert to bytessize
- number of least significant bytes of value to be written to the byte arrayb
- byte array to store bytesoffset
- 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 interfaceDataConverter
- 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 interfaceDataConverter
- Parameters:
b
- array to contain the bytes at offset 0;size
- number of bytes to be written
-
-