Package ghidra.util
Interface DataConverter
-
- All Superinterfaces:
java.io.Serializable
- All Known Subinterfaces:
GhidraDataConverter
- All Known Implementing Classes:
BigEndianDataConverter
,GhidraBigEndianDataConverter
,GhidraLittleEndianDataConverter
,LittleEndianDataConverter
public interface DataConverter extends java.io.Serializable
Defines methods to convert byte arrays to a specific primitive Java types, and to populate byte arrays from primitive Java types.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract 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.static DataConverter
getInstance(boolean isBigEndian)
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.static long
swapBytes(long val, int size)
Swap the least-significant bytes (based upon size)
-
-
-
Method Detail
-
getInstance
static DataConverter getInstance(boolean isBigEndian)
-
getShort
short getShort(byte[] b)
Get the short value from the given byte array.- Parameters:
b
- array containing bytes- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than 2.
-
getShort
short getShort(byte[] b, int offset)
Get the short value from the given byte array.- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the short- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than offset+2.
-
getInt
int getInt(byte[] b)
Get the int value from the given byte array.- Parameters:
b
- array containing bytes- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than 4.
-
getInt
int getInt(byte[] b, int offset)
Get the int value from the given byte array.- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the int- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than offset+4.
-
getLong
long getLong(byte[] b)
Get the long value from the given byte array.- Parameters:
b
- array containing bytes- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than 8.
-
getLong
long getLong(byte[] b, int offset)
Get the long value from the given byte array.- Parameters:
b
- array containing bytesoffset
- offset into byte array for getting the long- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than offset+8.
-
getValue
long getValue(byte[] b, int size)
Get the value from the given byte array using the specified size.- Parameters:
b
- array containing bytessize
- number of bytes to use from array at offset 0- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than size.
-
getValue
long getValue(byte[] b, int offset, int size)
Get the value from the given byte array using the specified size.- Parameters:
b
- array containing bytessize
- number of bytes to use from arrayoffset
- offset into byte array for getting the long- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than offset+size or size is greater than 8 (sizeof long).
-
getBigInteger
java.math.BigInteger getBigInteger(byte[] b, int size, boolean signed)
Get the value from the given byte array using the specified size.- Parameters:
b
- array containing bytessize
- number of bytes to use from array at offset 0- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than size.
-
getBigInteger
java.math.BigInteger getBigInteger(byte[] b, int offset, int size, boolean signed)
Get the value from the given byte array using the specified size.- Parameters:
b
- array containing bytessize
- number of bytes to use from arrayoffset
- offset into byte array for getting the long- Throws:
java.lang.IndexOutOfBoundsException
- if byte array size is less than offset+size.
-
getBytes
void getBytes(short value, byte[] b)
Converts the given value to bytes.- Parameters:
value
- value to convert to bytesb
- byte array to store bytes- Throws:
java.lang.IndexOutOfBoundsException
- if b.length is not at least 2.
-
getBytes
void getBytes(short value, byte[] b, int offset)
Converts the given value to bytes.- Parameters:
value
- value to convert to bytesb
- byte array to store bytesoffset
- offset into byte array to put the bytes- Throws:
java.lang.IndexOutOfBoundsException
- if (offset+2)>b.length
-
getBytes
void getBytes(int value, byte[] b)
Converts the given value to bytes.- Parameters:
value
- value to convert to bytesb
- byte array to store bytes- Throws:
java.lang.IndexOutOfBoundsException
- if b.length is not at least 4.
-
getBytes
void getBytes(int value, byte[] b, int offset)
Converts the given value to bytes.- Parameters:
value
- value to convert to bytesb
- byte array to store bytesoffset
- offset into byte array to put the bytes- Throws:
java.lang.IndexOutOfBoundsException
- if (offset+4)>b.length
-
getBytes
void getBytes(long value, byte[] b)
Converts the given value to bytes.- Parameters:
value
- value to convert to bytesb
- byte array to store bytes- Throws:
java.lang.IndexOutOfBoundsException
- if b.length is not at least 8.
-
getBytes
void getBytes(long value, byte[] b, int offset)
Converts the given value to bytes.- Parameters:
value
- value to convert to bytesb
- byte array to store bytesoffset
- offset into byte array to put the bytes- Throws:
java.lang.IndexOutOfBoundsException
- if (offset+8)>b.length
-
getBytes
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.- 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- Throws:
java.lang.IndexOutOfBoundsException
- if (offset+size)>b.length.
-
getBytes
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.- 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- Throws:
java.lang.IndexOutOfBoundsException
- if (offset+size)>b.length.
-
getBytes
byte[] getBytes(short value)
Converts the short value to an array of bytes.- Parameters:
value
- short value to be converted- Returns:
- array of bytes
-
getBytes
byte[] getBytes(int value)
Converts the int value to an array of bytes.- Parameters:
value
- int value to be converted- Returns:
- array of bytes
-
getBytes
byte[] getBytes(long value)
Converts the long value to an array of bytes.- Parameters:
value
- long value to be converted- Returns:
- array of bytes
-
getBytes
byte[] getBytes(java.math.BigInteger value, int size)
Converts the value to an array of bytes.- Parameters:
value
- value to be convertedsize
- value size in bytes- Returns:
- array of bytes
-
putShort
void putShort(byte[] b, short value)
Writes a short value into a byte array.- Parameters:
b
- array to contain the bytes;value
- the short value
-
putShort
void putShort(byte[] b, int offset, short value)
Writes a short value into the byte array at the given offset- Parameters:
b
- array to contain the bytes;offset
- the offset into the byte array to store the value.value
- the short value
-
putInt
void putInt(byte[] b, int value)
Writes a int value into a byte array.- Parameters:
b
- array to contain the bytes;value
- the int value
-
putInt
void putInt(byte[] b, int offset, int value)
Writes a int value into the byte array at the given offset- Parameters:
b
- array to contain the bytes;offset
- the offset into the byte array to store the value.value
- the int value
-
putLong
void putLong(byte[] b, long value)
Writes a long value into a byte array.- Parameters:
b
- array to contain the bytes;value
- the long value
-
putLong
void putLong(byte[] b, int offset, long value)
Writes a long value into the byte array at the given offset- Parameters:
b
- array to contain the bytes;offset
- the offset into the byte array to store the value.value
- the long value
-
putBigInteger
void putBigInteger(byte[] b, int size, java.math.BigInteger value)
Writes a value of specified size into the byte array at the given offset- Parameters:
b
- array to contain the bytes at offset 0;size
- number of bytes to be writtenvalue
-
-
putBigInteger
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- Parameters:
b
- array to contain the bytes;offset
- the offset into the byte array to store the value.size
- number of bytes to be writtenvalue
-
-
swapBytes
static long swapBytes(long val, int size)
Swap the least-significant bytes (based upon size)- Parameters:
val
- value whoose bytes are to be swappedsize
- number of least significant bytes to be swapped- Returns:
- value with bytes swapped (any high-order bytes beyond size will be 0)
-
-