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()
Don't use this constructor to create new instances of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigInteger
getBigInteger(byte[] b, int offset, int size, boolean signed)
Get the value from the given byte array using the specified size.int
getInt(byte[] b, int offset)
Get the int 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, int offset)
Get the short value from the given byte array.long
getValue(byte[] b, int offset, int size)
Get the unsigned value from the given byte array using the specified integer size, returned as a long.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
putInt(byte[] b, int offset, int value)
Writes a int value into the byte array at the given offset.void
putShort(byte[] b, int offset, short value)
Writes a short value into the byte array at the given offsetvoid
putValue(long value, int size, byte[] b, int offset)
Converts the given value to bytes using the number of least significant bytes specified by size.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ghidra.util.DataConverter
getBigInteger, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getInt, getLong, getShort, getSignedValue, getSignedValue, getValue, isBigEndian, putBigInteger, putInt, putLong, putLong, putShort
-
-
-
-
Field Detail
-
INSTANCE
public static final LittleEndianDataConverter INSTANCE
-
-
Constructor Detail
-
LittleEndianDataConverter
public LittleEndianDataConverter()
Don't use this constructor to create new instances of this class. Use the staticINSTANCE
instead orDataConverter.getInstance(boolean)
-
-
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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the longsize
- 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 interfaceDataConverter
- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the longsize
- number of bytes to use from arraysigned
- 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 interfaceDataConverter
- Parameters:
b
- array to contain the bytesoffset
- the offset into the byte array to store the valuevalue
- 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.- Specified by:
putInt
in interfaceDataConverter
- Parameters:
b
- array to contain the bytesoffset
- the offset into the byte array to store the valuevalue
- 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 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 bytesoffset
- the offset into the byte array to store the valuesize
- number of bytes to be writtenvalue
- BigInteger value to convert
-
-