Package ghidra.program.model.mem
Class MemoryBlockStub
- java.lang.Object
-
- ghidra.program.model.mem.MemoryBlockStub
-
- All Implemented Interfaces:
MemoryBlock
,java.io.Serializable
,java.lang.Comparable<MemoryBlock>
public class MemoryBlockStub extends java.lang.Object implements MemoryBlock
MemoryBlockStub can be extended for use by tests. It throws an UnsupportedOperationException for all methods in the MemoryBlock interface. Any method that is needed for your test can then be overridden so it can provide its own test implementation and return value.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface ghidra.program.model.mem.MemoryBlock
EXECUTE, EXTERNAL_BLOCK_NAME, READ, VOLATILE, WRITE
-
-
Constructor Summary
Constructors Constructor Description MemoryBlockStub()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(MemoryBlock o)
boolean
contains(Address addr)
Return whether addr is contained in this block.byte
getByte(Address addr)
Returns the byte at the given address in this block.int
getBytes(Address addr, byte[] b)
Tries to get b.length bytes from this block at the given address.int
getBytes(Address addr, byte[] b, int off, int len)
Tries to get len bytes from this block at the given address and put them into the given byte array at the specified offet.java.lang.String
getComment()
Get the comment associated with this block.java.io.InputStream
getData()
Get memory data in the form of an InputStream.Address
getEnd()
Return the end address of this block.java.lang.String
getName()
Get the name of this blockint
getPermissions()
Returns block permissions as a bit mask.long
getSize()
Get the number of bytes in this block.java.util.List<MemoryBlockSourceInfo>
getSourceInfos()
Returns a list ofMemoryBlockSourceInfo
objects for this block.java.lang.String
getSourceName()
Get the name of the source of this memory block.Address
getStart()
Return the starting address for this block.MemoryBlockType
getType()
Get the type for this block: TYPE_DEFAULT, TYPE_OVERLAY, TYPE_BIT_MAPPED, or TYPE_BYTE_MAPPEDboolean
isExecute()
Returns the value of the execute property associated with this blockboolean
isInitialized()
Return whether this block has been initialized.boolean
isLoaded()
Returns true if this memory block is a real loaded block (i.e.boolean
isMapped()
Returns true if this is either a bit-mapped or byte-mapped blockboolean
isRead()
Returns the value of the read property associated with this blockboolean
isVolatile()
Returns the value of the volatile property associated with this block.boolean
isWrite()
Returns the value of the write property associated with this blockvoid
putByte(Address addr, byte b)
Puts the given byte at the given address in this block.int
putBytes(Address addr, byte[] b)
Tries to put b.length bytes from the specified byte array to this block.int
putBytes(Address addr, byte[] b, int off, int len)
Tries to put len bytes from the specified byte array to this block.void
setComment(java.lang.String comment)
Set the comment associated with this block.void
setExecute(boolean e)
Sets the execute property associated with this block.void
setName(java.lang.String name)
Set the name for this block.void
setPermissions(boolean read, boolean write, boolean execute)
Sets the read, write, execute permissions on this blockvoid
setRead(boolean r)
Sets the read property associated with this block.void
setSourceName(java.lang.String sourceName)
Sets the name of the source file that provided the data.void
setVolatile(boolean v)
Sets the volatile property associated with this block.void
setWrite(boolean w)
Sets the write property associated with this block.
-
-
-
Method Detail
-
compareTo
public int compareTo(MemoryBlock o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<MemoryBlock>
-
getPermissions
public int getPermissions()
Description copied from interface:MemoryBlock
Returns block permissions as a bit mask. Permission bits defined as READ, WRITE, EXECUTE and VOLATILE- Specified by:
getPermissions
in interfaceMemoryBlock
-
getData
public java.io.InputStream getData()
Description copied from interface:MemoryBlock
Get memory data in the form of an InputStream. Null is returned for thos memory blocks which have no data.- Specified by:
getData
in interfaceMemoryBlock
-
contains
public boolean contains(Address addr)
Description copied from interface:MemoryBlock
Return whether addr is contained in this block.- Specified by:
contains
in interfaceMemoryBlock
- Parameters:
addr
- address
-
getStart
public Address getStart()
Description copied from interface:MemoryBlock
Return the starting address for this block.- Specified by:
getStart
in interfaceMemoryBlock
- Returns:
- block's start address
-
getEnd
public Address getEnd()
Description copied from interface:MemoryBlock
Return the end address of this block.- Specified by:
getEnd
in interfaceMemoryBlock
- Returns:
- end address of the block
-
getSize
public long getSize()
Description copied from interface:MemoryBlock
Get the number of bytes in this block.- Specified by:
getSize
in interfaceMemoryBlock
- Returns:
- number of bytes in the block
-
getName
public java.lang.String getName()
Description copied from interface:MemoryBlock
Get the name of this block- Specified by:
getName
in interfaceMemoryBlock
-
setName
public void setName(java.lang.String name) throws DuplicateNameException, LockException
Description copied from interface:MemoryBlock
Set the name for this block.- Specified by:
setName
in interfaceMemoryBlock
- Parameters:
name
- the new name for this block.- Throws:
DuplicateNameException
LockException
- renaming an Overlay block without exclusive access
-
getComment
public java.lang.String getComment()
Description copied from interface:MemoryBlock
Get the comment associated with this block.- Specified by:
getComment
in interfaceMemoryBlock
-
setComment
public void setComment(java.lang.String comment)
Description copied from interface:MemoryBlock
Set the comment associated with this block.- Specified by:
setComment
in interfaceMemoryBlock
- Parameters:
comment
- the comment to associate with this block.
-
isRead
public boolean isRead()
Description copied from interface:MemoryBlock
Returns the value of the read property associated with this block- Specified by:
isRead
in interfaceMemoryBlock
-
setRead
public void setRead(boolean r)
Description copied from interface:MemoryBlock
Sets the read property associated with this block.- Specified by:
setRead
in interfaceMemoryBlock
- Parameters:
r
- the value to set the read property to.
-
isWrite
public boolean isWrite()
Description copied from interface:MemoryBlock
Returns the value of the write property associated with this block- Specified by:
isWrite
in interfaceMemoryBlock
-
setWrite
public void setWrite(boolean w)
Description copied from interface:MemoryBlock
Sets the write property associated with this block.- Specified by:
setWrite
in interfaceMemoryBlock
- Parameters:
w
- the value to set the write property to.
-
isExecute
public boolean isExecute()
Description copied from interface:MemoryBlock
Returns the value of the execute property associated with this block- Specified by:
isExecute
in interfaceMemoryBlock
-
setExecute
public void setExecute(boolean e)
Description copied from interface:MemoryBlock
Sets the execute property associated with this block.- Specified by:
setExecute
in interfaceMemoryBlock
- Parameters:
e
- the value to set the execute property to.
-
setPermissions
public void setPermissions(boolean read, boolean write, boolean execute)
Description copied from interface:MemoryBlock
Sets the read, write, execute permissions on this block- Specified by:
setPermissions
in interfaceMemoryBlock
- Parameters:
read
- the read permissionwrite
- the write permissionexecute
- the execute permission
-
isVolatile
public boolean isVolatile()
Description copied from interface:MemoryBlock
Returns the value of the volatile property associated with this block. This attribute is generally associated with block of I/O regions of memory.- Specified by:
isVolatile
in interfaceMemoryBlock
-
setVolatile
public void setVolatile(boolean v)
Description copied from interface:MemoryBlock
Sets the volatile property associated with this block.- Specified by:
setVolatile
in interfaceMemoryBlock
- Parameters:
v
- the value to set the volatile property to.
-
getSourceName
public java.lang.String getSourceName()
Description copied from interface:MemoryBlock
Get the name of the source of this memory block.- Specified by:
getSourceName
in interfaceMemoryBlock
- Returns:
- source name
-
setSourceName
public void setSourceName(java.lang.String sourceName)
Description copied from interface:MemoryBlock
Sets the name of the source file that provided the data.- Specified by:
setSourceName
in interfaceMemoryBlock
- Parameters:
sourceName
- the name of the source file.
-
getByte
public byte getByte(Address addr) throws MemoryAccessException
Description copied from interface:MemoryBlock
Returns the byte at the given address in this block.- Specified by:
getByte
in interfaceMemoryBlock
- Parameters:
addr
- the address.- Throws:
MemoryAccessException
- if any of the requested bytes are uninitialized.
-
getBytes
public int getBytes(Address addr, byte[] b) throws MemoryAccessException
Description copied from interface:MemoryBlock
Tries to get b.length bytes from this block at the given address. May return fewer bytes if the requested length is beyond the end of the block.- Specified by:
getBytes
in interfaceMemoryBlock
- Parameters:
addr
- the address from which to get the bytes.b
- the byte array to populate.- Returns:
- the number of bytes actually populated.
- Throws:
MemoryAccessException
- if any of the requested bytes are uninitialized.
-
getBytes
public int getBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException
Description copied from interface:MemoryBlock
Tries to get len bytes from this block at the given address and put them into the given byte array at the specified offet. May return fewer bytes if the requested length is beyond the end of the block.- Specified by:
getBytes
in interfaceMemoryBlock
- Parameters:
addr
- the address from which to get the bytes.b
- the byte array to populate.off
- the offset into the byte array.len
- the number of bytes to get.- Returns:
- the number of bytes actually populated.
- Throws:
MemoryAccessException
- if any of the requested bytes are uninitialized.
-
putByte
public void putByte(Address addr, byte b) throws MemoryAccessException
Description copied from interface:MemoryBlock
Puts the given byte at the given address in this block.- Specified by:
putByte
in interfaceMemoryBlock
- Parameters:
addr
- the address.- Throws:
MemoryAccessException
- if the block is uninitialized
-
putBytes
public int putBytes(Address addr, byte[] b) throws MemoryAccessException
Description copied from interface:MemoryBlock
Tries to put b.length bytes from the specified byte array to this block. All the bytes may not be put if the requested length is beyond the end of the block.- Specified by:
putBytes
in interfaceMemoryBlock
- Parameters:
addr
- the address of where to put the bytes.b
- the byte array containing the bytes to write.- Returns:
- the number of bytes actually written.
- Throws:
MemoryAccessException
- if the block is uninitialized
-
putBytes
public int putBytes(Address addr, byte[] b, int off, int len) throws MemoryAccessException
Description copied from interface:MemoryBlock
Tries to put len bytes from the specified byte array to this block. All the bytes may not be written if the requested length is beyond the end of the block.- Specified by:
putBytes
in interfaceMemoryBlock
- Parameters:
addr
- the address of where to put the bytes.b
- the byte array containing the bytes to write.off
- the offset into the byte array.len
- the number of bytes to write.- Returns:
- the number of bytes actually written.
- Throws:
MemoryAccessException
- if the block is uninitialized
-
getType
public MemoryBlockType getType()
Description copied from interface:MemoryBlock
Get the type for this block: TYPE_DEFAULT, TYPE_OVERLAY, TYPE_BIT_MAPPED, or TYPE_BYTE_MAPPED- Specified by:
getType
in interfaceMemoryBlock
-
isInitialized
public boolean isInitialized()
Description copied from interface:MemoryBlock
Return whether this block has been initialized.- Specified by:
isInitialized
in interfaceMemoryBlock
-
isMapped
public boolean isMapped()
Description copied from interface:MemoryBlock
Returns true if this is either a bit-mapped or byte-mapped block- Specified by:
isMapped
in interfaceMemoryBlock
-
isLoaded
public boolean isLoaded()
Description copied from interface:MemoryBlock
Returns true if this memory block is a real loaded block (i.e. RAM) and not a special block containing file header data such as debug sections.- Specified by:
isLoaded
in interfaceMemoryBlock
- Returns:
- true if this is a loaded block and not a "special" block such as a file header.
-
getSourceInfos
public java.util.List<MemoryBlockSourceInfo> getSourceInfos()
Description copied from interface:MemoryBlock
Returns a list ofMemoryBlockSourceInfo
objects for this block. A block may consist of multiple sequences of bytes from different sources. Each such source of bytes is described by its respective SourceInfo object. Blocks may have multiple sources after two or more memory blocks have been joined together and the underlying byte sources can't be joined.- Specified by:
getSourceInfos
in interfaceMemoryBlock
- Returns:
- a list of SourceInfo objects, one for each different source of bytes in this block.
-
-