Class MemoryByteProvider
- All Implemented Interfaces:
ByteProvider
,Closeable
,AutoCloseable
- Direct Known Subclasses:
MemoryMutableByteProvider
ByteProvider
implementation based on Memory
.
The bytes returned by this provider are indexed relative to the baseAddress
supplied to the constructor, and are limited to memory blocks
of the
same address space.
Warnings:
Using this ByteProvider with memory block/address spaces that are not simple "ram" initialized memory blocks is fraught with peril.
Addresses and address spaces can use all 64 bits of a long
as an offset, which
causes a problem when trying to express the correct length()
of this ByteProvider as
a long. (this is why address ranges deal with inclusive end values instead of exclusive).
- The return value of
length()
is constrained to a max of Long.MAX_VALUE isValidIndex(long)
treats its argument as an unsigned int64, and works for the entire address space range.
Not all byte provider index locations between 0 and length()
will be valid
(because gaps between memory blocks), and may generate exceptions when those locations are read.
- To avoid this situation, the caller will need to use information from the program's Memory manager to align reads to valid locations.
-
Field Summary
Modifier and TypeFieldDescriptionprotected Address
protected boolean
protected long
protected Memory
Fields inherited from interface ghidra.app.util.bin.ByteProvider
EMPTY_BYTEPROVIDER
-
Constructor Summary
ConstructorDescriptionMemoryByteProvider
(Memory memory, Address baseAddress) Constructs a newMemoryByteProvider
relative to the specified base address, containing the address range to the highest address in the same address space currently found in the memory map.MemoryByteProvider
(Memory memory, Address baseAddress, boolean firstBlockOnly) Constructs a newMemoryByteProvider
relative to the specified base address, containing the address range to the end of the first memory block, or the highest address in the same address space, currently found in the memory map.MemoryByteProvider
(Memory memory, Address baseAddress, Address maxAddress) Constructs a newMemoryByteProvider
relative to the specified base address, with the specified length.MemoryByteProvider
(Memory memory, AddressSpace space) Constructs a newMemoryByteProvider
for a specificAddressSpace
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Releases any resources theByteProvider
may have occupiedstatic MemoryByteProvider
createDefaultAddressSpaceByteProvider
(Program program, boolean firstBlockOnly) Create aByteProvider
that starts at the beginning (e.g.static MemoryByteProvider
createMemoryBlockByteProvider
(Memory memory, MemoryBlock block) Create aByteProvider
that is limited to the specifiedMemoryBlock
.static MemoryByteProvider
createProgramHeaderByteProvider
(Program program, boolean firstBlockOnly) Create aByteProvider
that starts at the beginning of the specifiedprogram's
memory, containing either just the first memory block, or all memory blocks (of the same address space).Returns the absolute path (similar to, but not a, URI) to theByteProvider
.Returns the address range of the bytes of this provider.Returns the address of the last byte of this provider.getFile()
Returns the underlyingFile
for thisByteProvider
, or null if thisByteProvider
is not associated with aFile
.getName()
Returns the name of theByteProvider
.Returns the address of the first byte of this provider.boolean
isEmpty()
Returns true if this ByteProvider does not contain any bytes.boolean
isValidIndex
(long index) Returns true if the specified index is valid.long
length()
Returns the length of theByteProvider
byte
readByte
(long index) Reads a byte at the specified indexbyte[]
readBytes
(long index, long length) Reads a byte array at the specified indexMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.app.util.bin.ByteProvider
getFSRL, getInputStream
-
Field Details
-
memory
-
baseAddress
-
maxOffset
protected long maxOffset -
isEmtpy
protected boolean isEmtpy
-
-
Constructor Details
-
MemoryByteProvider
Constructs a newMemoryByteProvider
for a specificAddressSpace
. Bytes will be provided relative to the minimum address (typically 0) in the space, and ranges to the highest address in the same address space currently found in the memory map.- Parameters:
memory
- theMemory
space
- theAddressSpace
-
MemoryByteProvider
Constructs a newMemoryByteProvider
relative to the specified base address, containing the address range to the highest address in the same address space currently found in the memory map.- Parameters:
memory
- theMemory
baseAddress
- the base address
-
MemoryByteProvider
Constructs a newMemoryByteProvider
relative to the specified base address, containing the address range to the end of the first memory block, or the highest address in the same address space, currently found in the memory map.- Parameters:
memory
- theMemory
baseAddress
- the base addressfirstBlockOnly
- boolean flag, if true, only the first memory block will be accessible, if false, all memory blocks of the address space will be accessible
-
MemoryByteProvider
Constructs a newMemoryByteProvider
relative to the specified base address, with the specified length.- Parameters:
memory
- theMemory
baseAddress
- the base addressmaxAddress
- the highest address accessible by this provider (inclusive), or null if there is no memory
-
-
Method Details
-
createMemoryBlockByteProvider
Create aByteProvider
that is limited to the specifiedMemoryBlock
.- Parameters:
memory
-Memory
of the programblock
-MemoryBlock
to read from- Returns:
- new
ByteProvider
that contains the bytes of the specified MemoryBlock
-
createProgramHeaderByteProvider
public static MemoryByteProvider createProgramHeaderByteProvider(Program program, boolean firstBlockOnly) Create aByteProvider
that starts at the beginning of the specifiedprogram's
memory, containing either just the first memory block, or all memory blocks (of the same address space).- Parameters:
program
-Program
to readfirstBlockOnly
- boolean flag, if true, only the first memory block will be accessible via the returned provider, if false, all memory blocks of the address space will be accessible- Returns:
- new
MemoryByteProvider
, starting at program's minAddress
-
createDefaultAddressSpaceByteProvider
public static MemoryByteProvider createDefaultAddressSpaceByteProvider(Program program, boolean firstBlockOnly) Create aByteProvider
that starts at the beginning (e.g. 0) of the specifiedprogram's
default address space memory, containing either the first memory block, or all memory blocks (of the same address space).- Parameters:
program
-Program
to readfirstBlockOnly
- boolean flag, if true, only the first memory block will be accessible via the returned provider, if false, all memory blocks of the address space will be accessible- Returns:
- new
MemoryByteProvider
, starting at program's minAddress
-
getStartAddress
Returns the address of the first byte of this provider.- Returns:
- address of the first byte returned by this provider (at index 0)
-
getEndAddress
Returns the address of the last byte of this provider.- Returns:
- address of the last byte returned by this provider
-
getAddressSet
Returns the address range of the bytes of this provider.- Returns:
- address range of first byte to last byte of this provider
-
isEmpty
public boolean isEmpty()Description copied from interface:ByteProvider
Returns true if this ByteProvider does not contain any bytes.- Specified by:
isEmpty
in interfaceByteProvider
- Returns:
- boolean true if this provider is empty, false if contains bytes
-
getFile
Description copied from interface:ByteProvider
Returns the underlyingFile
for thisByteProvider
, or null if thisByteProvider
is not associated with aFile
.- Specified by:
getFile
in interfaceByteProvider
- Returns:
- the underlying file for this byte provider
-
getName
Description copied from interface:ByteProvider
Returns the name of theByteProvider
. For example, the underlying file name.- Specified by:
getName
in interfaceByteProvider
- Returns:
- the name of the
ByteProvider
or null if there is no name
-
getAbsolutePath
Description copied from interface:ByteProvider
Returns the absolute path (similar to, but not a, URI) to theByteProvider
. For example, the complete path to the file.- Specified by:
getAbsolutePath
in interfaceByteProvider
- Returns:
- the absolute path to the
ByteProvider
or null if not associated with aFile
.
-
length
Description copied from interface:ByteProvider
Returns the length of theByteProvider
- Specified by:
length
in interfaceByteProvider
- Returns:
- the length of the
ByteProvider
- Throws:
IOException
- if an I/O error occurs
-
isValidIndex
public boolean isValidIndex(long index) Description copied from interface:ByteProvider
Returns true if the specified index is valid.- Specified by:
isValidIndex
in interfaceByteProvider
- Parameters:
index
- the index in the byte provider to check- Returns:
- true if the specified index is valid
-
readByte
Description copied from interface:ByteProvider
Reads a byte at the specified index- Specified by:
readByte
in interfaceByteProvider
- Parameters:
index
- the index of the byte to read- Returns:
- the byte read from the specified index
- Throws:
IOException
- if an I/O error occurs
-
readBytes
Description copied from interface:ByteProvider
Reads a byte array at the specified index- Specified by:
readBytes
in interfaceByteProvider
- Parameters:
index
- the index of the byte to readlength
- the number of bytes to read- Returns:
- the byte array read from the specified index
- Throws:
IOException
- if an I/O error occurs
-
close
public void close()Description copied from interface:ByteProvider
Releases any resources theByteProvider
may have occupied- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceByteProvider
- Specified by:
close
in interfaceCloseable
-