Class LEB128
- java.lang.Object
-
- ghidra.app.util.bin.format.dwarf4.LEB128
-
public class LEB128 extends java.lang.ObjectClass to hold result of reading a LEB128 value, along with size and position metadata.Note: If a LEB128 value that would result in a native value longer than 64bits is attempted to be read, an
IOExceptionwill be thrown, and the stream's position will be left at the last read byte.If this was a valid (but overly large) LEB128, the caller's stream will be left still pointing to LEB data.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Change Modifier and Type Method Description NEW intasInt32()Returns the value as an signed int32.NEW longasLong()Returns the value as a 64bit primitive long.NEW intasUInt32()Returns the value as an unsigned int32.static longdecode(byte[] bytes, boolean isSigned)Decodes a LEB128 number from a byte array and returns it as a long.static longdecode(byte[] bytes, int offset, boolean isSigned)Decodes a LEB128 number from a byte array and returns it as a long.NEW intgetLength()Returns the number of bytes that were used to store the LEB128 value in the stream it was read from.NEW longgetOffset()Returns the offset of the LEB128 value in the stream it was read from.NEW static intreadAsInt32(BinaryReader reader)Reads a LEB128 signed number from the BinaryReader and returns it as a java 32 bit int.NEW static longreadAsLong(BinaryReader reader, boolean isSigned)Reads a LEB128 number from the BinaryReader and returns it as a java 64 bit long int.NEW static intreadAsUInt32(BinaryReader reader)Reads a LEB128 unsigned number from the BinaryReader and returns it as a java 32 bit int.NEW static LEB128readSignedValue(BinaryReader reader)Reads an signed LEB128 value from the BinaryReader and returns aLEB128instance that contains the value along with size and position metadata.NEW static LEB128readUnsignedValue(BinaryReader reader)Reads an unsigned LEB128 value from the BinaryReader and returns aLEB128instance that contains the value along with size and position metadata.NEW static LEB128readValue(BinaryReader reader, boolean isSigned)Reads a LEB128 value from the BinaryReader and returns aLEB128instance that contains the value along with size and position metadata.NEW java.lang.StringtoString()REMOVED intdecode32s(BinaryReader reader) (Removed)REMOVED intdecode32u(BinaryReader reader) (Removed)REMOVED longdecode(BinaryReader reader, boolean isSigned) (Removed)
-
-
-
Method Detail
-
asUInt32 NEW
public int asUInt32() throws java.io.IOExceptionReturns the value as an unsigned int32. If the actual value is outside the positive range of a java int (ie. 0..Integer.MAX_VALUE), an exception is thrown.- Returns:
- int in the range of 0 to
Integer.MAX_VALUE - Throws:
java.io.IOException- if value is outside range
-
asInt32 NEW
public int asInt32() throws java.io.IOExceptionReturns the value as an signed int32. If the actual value is outside the range of a java int (ie.Integer.MIN_VALUE..Integer.MAX_VALUE), an exception is thrown.- Returns:
- int in the range of
Integer.MIN_VALUEtoInteger.MAX_VALUE - Throws:
java.io.IOException- if value is outside range
-
asLong NEW
public long asLong()
Returns the value as a 64bit primitive long. Interpreting the signed-ness of the value will depend on the way the value was read (ie. ifreadSignedValue(BinaryReader)vs.readUnsignedValue(BinaryReader)was used).- Returns:
- long value.
-
getOffset NEW
public long getOffset()
Returns the offset of the LEB128 value in the stream it was read from.- Returns:
- stream offset of the LEB128 value
-
getLength NEW
public int getLength()
Returns the number of bytes that were used to store the LEB128 value in the stream it was read from.- Returns:
- number of bytes used to store the read LEB128 value
-
readValue NEW
public static LEB128 readValue(BinaryReader reader, boolean isSigned) throws java.io.IOException
Reads a LEB128 value from the BinaryReader and returns aLEB128instance that contains the value along with size and position metadata.- Parameters:
reader-BinaryReaderto read bytes fromisSigned- true if the value is signed- Returns:
- a
LEB128instance with the read LEB128 value with metadata - Throws:
java.io.IOException- if an I/O error occurs or value is outside the range of a java 64 bit int
-
readUnsignedValue NEW
public static LEB128 readUnsignedValue(BinaryReader reader) throws java.io.IOException
Reads an unsigned LEB128 value from the BinaryReader and returns aLEB128instance that contains the value along with size and position metadata.- Parameters:
reader-BinaryReaderto read bytes from- Returns:
- a
LEB128instance with the read LEB128 value with metadata - Throws:
java.io.IOException- if an I/O error occurs or value is outside the range of a java 64 bit int
-
readSignedValue NEW
public static LEB128 readSignedValue(BinaryReader reader) throws java.io.IOException
Reads an signed LEB128 value from the BinaryReader and returns aLEB128instance that contains the value along with size and position metadata.- Parameters:
reader-BinaryReaderto read bytes from- Returns:
- a
LEB128instance with the read LEB128 value with metadata - Throws:
java.io.IOException- if an I/O error occurs or value is outside the range of a java 64 bit int
-
readAsInt32 NEW
public static int readAsInt32(BinaryReader reader) throws java.io.IOException
Reads a LEB128 signed number from the BinaryReader and returns it as a java 32 bit int.If the value of the number can not fit in the int type, an
IOExceptionwill be thrown.- Parameters:
reader-BinaryReaderto read bytes from- Returns:
- signed int32 value
- Throws:
java.io.IOException- if error reading bytes or value is outside the range of a signed int32
-
readAsUInt32 NEW
public static int readAsUInt32(BinaryReader reader) throws java.io.IOException
Reads a LEB128 unsigned number from the BinaryReader and returns it as a java 32 bit int.If the value of the number can not fit in the positive range of the int type, an
IOExceptionwill be thrown.- Parameters:
reader-BinaryReaderto read bytes from- Returns:
- unsigned int32 value 0..Integer.MAX_VALUE
- Throws:
java.io.IOException- if error reading bytes or value is outside the positive range of a java 32 bit int (ie. 0..Integer.MAX_VALUE)
-
readAsLong NEW
public static long readAsLong(BinaryReader reader, boolean isSigned) throws java.io.IOException
Reads a LEB128 number from the BinaryReader and returns it as a java 64 bit long int.Large unsigned integers that use all 64 bits are be returned in a java native 'long' type, which is signed. It is up to the caller to treat the value as unsigned.
Large integers that use more than 64 bits will cause an IOException to be thrown.
- Parameters:
reader-BinaryReaderto read bytes fromisSigned- true if the value is signed- Returns:
- long integer value. Caller must treat it as unsigned if isSigned parameter was set to false
- Throws:
java.io.IOException- if an I/O error occurs or value is outside the range of a java 64 bit int
-
decode
public static long decode(byte[] bytes, boolean isSigned) throws java.io.IOExceptionDecodes a LEB128 number from a byte array and returns it as a long.- Parameters:
bytes- the bytes representing the LEB128 numberisSigned- true if the value is signed- Returns:
- long integer value. Caller must treat it as unsigned if isSigned parameter was set to false
- Throws:
java.io.IOException- if error reading bytes or value is outside the range of a java 64 bit int
-
decode
public static long decode(byte[] bytes, int offset, boolean isSigned) throws java.io.IOExceptionDecodes a LEB128 number from a byte array and returns it as a long.- Parameters:
bytes- the bytes representing the LEB128 numberoffset- offset in byte array of where to start reading bytesisSigned- true if the value is signed- Returns:
- long integer value. Caller must treat it as unsigned if isSigned parameter was set to false
- Throws:
java.io.IOException- if error reading bytes or value is outside the range of a java 64 bit int
-
-