Class AddressableByteSequence
java.lang.Object
ghidra.features.base.memsearch.bytesequence.AddressableByteSequence
- All Implemented Interfaces:
ByteSequence
This class provides a
ByteSequence
view into an AddressableByteSource
. By
specifying an address and length, this class provides a view into the byte source
as a indexable sequence of bytes. It is mutable and can be reused by setting a new
address range for this sequence. This was to avoid constantly allocating large byte arrays.-
Constructor Summary
ConstructorDescriptionAddressableByteSequence
(AddressableByteSource byteSource, int capacity) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Sets this view to an empty byte sequencegetAddress
(int index) Returns the address of the byte represented by the given index into this buffer.byte
getByte
(int index) Returns the byte at the given index.byte[]
getBytes
(int index, int size) Returns a byte array containing the bytes from the given range.int
Returns the length of available bytes.boolean
hasAvailableBytes
(int index, int length) A convenience method for checking if this sequence can provide a range of bytes from some offset.void
setRange
(AddressRange range) Sets the range of bytes that this object will buffer.
-
Constructor Details
-
AddressableByteSequence
Constructor- Parameters:
byteSource
- the source of the underlying bytes that is a buffer intocapacity
- the maximum size range that this object will buffer
-
-
Method Details
-
clear
public void clear()Sets this view to an empty byte sequence -
setRange
Sets the range of bytes that this object will buffer. This immediately will read the bytes from the byte source into it's internal byte array buffer.- Parameters:
range
- the range of bytes to buffer
-
getAddress
Returns the address of the byte represented by the given index into this buffer.- Parameters:
index
- the index into the buffer to get its associated address- Returns:
- the Address for the given index
-
getLength
public int getLength()Description copied from interface:ByteSequence
Returns the length of available bytes.- Specified by:
getLength
in interfaceByteSequence
- Returns:
- the length of the sequence of bytes
-
getByte
public byte getByte(int index) Description copied from interface:ByteSequence
Returns the byte at the given index. The index must between 0 and the extended length.- Specified by:
getByte
in interfaceByteSequence
- Parameters:
index
- the index in the byte sequence to retrieve a byte value- Returns:
- the byte at the given index
-
getBytes
public byte[] getBytes(int index, int size) Description copied from interface:ByteSequence
Returns a byte array containing the bytes from the given range.- Specified by:
getBytes
in interfaceByteSequence
- Parameters:
index
- the start index of the range to get bytessize
- the number of bytes to get- Returns:
- a byte array containing the bytes from the given range
-
hasAvailableBytes
public boolean hasAvailableBytes(int index, int length) Description copied from interface:ByteSequence
A convenience method for checking if this sequence can provide a range of bytes from some offset.- Specified by:
hasAvailableBytes
in interfaceByteSequence
- Parameters:
index
- the index of the start of the range to check for available byteslength
- the length of the range to check for available bytes- Returns:
- true if bytes are available for the given range
-