Package ghidra.util
Class LittleEndianDataConverter
java.lang.Object
ghidra.util.LittleEndianDataConverter
- All Implemented Interfaces:
DataConverter,Serializable
- Direct Known Subclasses:
GhidraLittleEndianDataConverter
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:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDon't use this constructor to create new instances of this class. -
Method Summary
Modifier and TypeMethodDescriptiongetBigInteger(byte[] b, int offset, int size, boolean signed) Get the value from the given byte array using the specified size.intgetInt(byte[] b, int offset) Get the int value from the given byte array.longgetLong(byte[] b, int offset) Get the long value from the given byte array.shortgetShort(byte[] b, int offset) Get the short value from the given byte array.longgetValue(byte[] b, int offset, int size) Get the unsigned value from the given byte array using the specified integer size, returned as a long.voidputBigInteger(byte[] b, int offset, int size, BigInteger value) Writes a value of specified size into the byte array at the given offsetvoidputInt(byte[] b, int offset, int value) Writes a int value into the byte array at the given offset.voidputShort(byte[] b, int offset, short value) Writes a short value into the byte array at the given offsetvoidputValue(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, waitMethods 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 Details
-
INSTANCE
-
-
Constructor Details
-
LittleEndianDataConverter
public LittleEndianDataConverter()Don't use this constructor to create new instances of this class. Use the staticINSTANCEinstead orDataConverter.getInstance(boolean)
-
-
Method Details
-
getShort
public short getShort(byte[] b, int offset) Description copied from interface:DataConverterGet the short value from the given byte array.- Specified by:
getShortin 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:DataConverterGet the int value from the given byte array.- Specified by:
getIntin 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:DataConverterGet the long value from the given byte array.- Specified by:
getLongin 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:DataConverterGet 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:
getValuein 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
Description copied from interface:DataConverterGet the value from the given byte array using the specified size.- Specified by:
getBigIntegerin 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:
BigIntegerwith value
-
putShort
public void putShort(byte[] b, int offset, short value) Description copied from interface:DataConverterWrites a short value into the byte array at the given offset- Specified by:
putShortin 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:DataConverterWrites a int value into the byte array at the given offset.- Specified by:
putIntin 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:DataConverterConverts the given value to bytes using the number of least significant bytes specified by size.- Specified by:
putValuein 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
Description copied from interface:DataConverterWrites a value of specified size into the byte array at the given offset- Specified by:
putBigIntegerin 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
-