Package ghidra.app.util.bin
Class LEB128Info
java.lang.Object
ghidra.app.util.bin.LEB128Info
Class to hold result of reading a
LEB128
value, along with size and position metadata.-
Method Summary
Modifier and TypeMethodDescriptionint
asInt32()
Returns the value as an signed int32.long
asLong()
Returns the value as a 64bit primitive long.int
asUInt32()
Returns the value as an unsigned int32.int
Returns the number of bytes that were used to store the LEB128 value in the stream it was read from.long
Returns the offset of the LEB128 value in the stream it was read from.static LEB128Info
readValue
(BinaryReader reader, boolean isSigned) Reads a LEB128 value from the BinaryReader and returns aLEB128Info
instance that contains the value along with size and position metadata.static LEB128Info
signed
(BinaryReader reader) Reads an signed LEB128 value from the BinaryReader and returns aLEB128Info
instance that contains the value along with size and position metadata.toString()
static LEB128Info
unsigned
(BinaryReader reader) Reads an unsigned LEB128 value from the BinaryReader and returns aLEB128Info
instance that contains the value along with size and position metadata.
-
Method Details
-
unsigned
Reads an unsigned LEB128 value from the BinaryReader and returns aLEB128Info
instance that contains the value along with size and position metadata.- Parameters:
reader
-BinaryReader
to read bytes from- Returns:
- a
LEB128Info
instance with the read LEB128 value with metadata - Throws:
IOException
- if an I/O error occurs or value is outside the range of a java 64 bit int
-
signed
Reads an signed LEB128 value from the BinaryReader and returns aLEB128Info
instance that contains the value along with size and position metadata.- Parameters:
reader
-BinaryReader
to read bytes from- Returns:
- a
LEB128Info
instance with the read LEB128 value with metadata - Throws:
IOException
- if an I/O error occurs or value is outside the range of a java 64 bit int
-
asUInt32
Returns 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:
IOException
- if value is outside range
-
asInt32
Returns 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_VALUE
toInteger.MAX_VALUE
- Throws:
IOException
- if value is outside range
-
asLong
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. ifsigned(BinaryReader)
vs.unsigned(BinaryReader)
was used).- Returns:
- long value.
-
getOffset
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
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
-
toString
-
readValue
Reads a LEB128 value from the BinaryReader and returns aLEB128Info
instance that contains the value along with size and position metadata.- Parameters:
reader
-BinaryReader
to read bytes fromisSigned
- true if the value is signed- Returns:
- a
LEB128Info
instance with the read LEB128 value with metadata - Throws:
IOException
- if an I/O error occurs or value is outside the range of a java 64 bit int
-