Package ghidra.app.util
Class MemoryBlockUtils
- java.lang.Object
-
- ghidra.app.util.MemoryBlockUtils
-
public class MemoryBlockUtils extends java.lang.Object
Convenience methods for creating memory blocks.
-
-
Constructor Summary
Constructors Constructor Description MemoryBlockUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
adjustFragment(Program program, Address address, java.lang.String name)
Adjusts the name of the fragment at the given address to the given name.static MemoryBlock
createBitMappedBlock(Program program, java.lang.String name, Address start, Address base, int length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, boolean overlay, MessageLog log)
Creates a new bit mapped memory block.static MemoryBlock
createByteMappedBlock(Program program, java.lang.String name, Address start, Address base, int length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, boolean overlay, MessageLog log)
Creates a new byte mapped memory block with a 1:1 byte mapping scheme.static FileBytes
createFileBytes(Program program, ByteProvider provider, long offset, long length, TaskMonitor monitor)
Creates a newFileBytes
object using a portion of the bytes from aByteProvider
static FileBytes
createFileBytes(Program program, ByteProvider provider, TaskMonitor monitor)
Creates a newFileBytes
object using all the bytes from aByteProvider
static MemoryBlock
createInitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, long length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log)
Create a new initialized memory block.static MemoryBlock
createInitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, FileBytes fileBytes, long offset, long length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log)
Creates a new initialized block in memory using the bytes from aFileBytes
object.static MemoryBlock
createInitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, java.io.InputStream dataInput, long dataLength, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log, TaskMonitor monitor)
Creates a new initialized block in memory using the bytes from the given input stream.static MemoryBlock
createUninitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, long length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log)
Creates a new uninitialized memory block.
-
-
-
Method Detail
-
createUninitializedBlock
public static MemoryBlock createUninitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, long length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log)
Creates a new uninitialized memory block.- Parameters:
program
- the program in which to create the block.isOverlay
- if true, the block will be created in a new overlay space for that blockname
- the name of the new block.start
- the starting address of the new block.length
- the length of the new blockcomment
- the comment text to associate with the new block.source
- the source of the block (This field is not well defined - currently another comment)r
- the read permission for the new block.w
- the write permission for the new block.x
- the execute permission for the new block.log
- aMessageLog
for appending error messages- Returns:
- the newly created block or null if the operation failed.
-
createInitializedBlock
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, long length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log)
Create a new initialized memory block. Initialized to all zeros.- Parameters:
program
- the program in which to create the block.isOverlay
- if true, the block will be created in a new overlay space for that blockname
- the name of the new block.start
- the starting address of the new block.length
- the length of the new blockcomment
- the comment text to associate with the new block.source
- the source of the block (This field is not well defined - currently another comment)r
- the read permission for the new block.w
- the write permission for the new block.x
- the execute permission for the new block.log
- aMessageLog
for appending error messages- Returns:
- the newly created block or null if the operation failed.
-
createBitMappedBlock
public static MemoryBlock createBitMappedBlock(Program program, java.lang.String name, Address start, Address base, int length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, boolean overlay, MessageLog log)
Creates a new bit mapped memory block. (A bit mapped block is a block where each byte value is either 1 or 0 and the value is taken from a bit in a byte at some other address in memory)- Parameters:
program
- the program in which to create the block.name
- the name of the new block.start
- the starting address of the new block.base
- the address of the region in memory to map to.length
- the length of the new blockcomment
- the comment text to associate with the new block.source
- the source of the block (This field is not well defined - currently another comment)r
- the read permission for the new block.w
- the write permission for the new block.x
- the execute permission for the new block.overlay
- create overlay block if true otherwise a normal mapped block will be createdlog
- aStringBuffer
for appending error messages- Returns:
- the new created block
-
createByteMappedBlock
public static MemoryBlock createByteMappedBlock(Program program, java.lang.String name, Address start, Address base, int length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, boolean overlay, MessageLog log)
Creates a new byte mapped memory block with a 1:1 byte mapping scheme. (A byte mapped block is a block where each byte value is taken from a byte at some other address in memory)- Parameters:
program
- the program in which to create the block.name
- the name of the new block.start
- the starting address of the new block.base
- the address of the region in memory to map to.length
- the length of the new blockcomment
- the comment text to associate with the new block.source
- the source of the block (This field is not well defined - currently another comment)r
- the read permission for the new block.w
- the write permission for the new block.x
- the execute permission for the new block.overlay
- create overlay block if true otherwise a normal mapped block will be createdlog
- aMessageLog
for appending error messages- Returns:
- the new created block
-
createInitializedBlock
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, FileBytes fileBytes, long offset, long length, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log) throws AddressOverflowException
Creates a new initialized block in memory using the bytes from aFileBytes
object. If there is a conflict when creating this block (some other block occupies at least some of the addresses that would be occupied by the new block), then an attempt will be made to create the new block in an overlay.- Parameters:
program
- the program in which to create the block.isOverlay
- if true, the block will be created in a new overlay space for that blockname
- the name of the new block.start
- the starting address of the new block.fileBytes
- theFileBytes
object that supplies the bytes for this block.offset
- the offset into theFileBytes
object where the bytes for this block reside.length
- the length of the new blockcomment
- the comment text to associate with the new block.source
- the source of the block (This field is not well defined - currently another comment)r
- the read permission for the new block.w
- the write permission for the new block.x
- the execute permission for the new block.log
- aMessageLog
for appending error messages- Returns:
- the new created block
- Throws:
AddressOverflowException
- if the address
-
createInitializedBlock
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay, java.lang.String name, Address start, java.io.InputStream dataInput, long dataLength, java.lang.String comment, java.lang.String source, boolean r, boolean w, boolean x, MessageLog log, TaskMonitor monitor) throws AddressOverflowException
Creates a new initialized block in memory using the bytes from the given input stream. If there is a conflict when creating this block (some other block occupies at least some of the addresses that would be occupied by the new block), then an attempt will be made to create the new block in an overlay.- Parameters:
program
- the program in which to create the block.isOverlay
- if true, the block will be created in a new overlay space for that blockname
- the name of the new block.start
- the starting address of the new block.dataInput
- theInputStream
object that supplies the bytes for this block.dataLength
- the length of the new blockcomment
- the comment text to associate with the new block.source
- the source of the block (This field is not well defined - currently another comment)r
- the read permission for the new block.w
- the write permission for the new block.x
- the execute permission for the new block.log
- aMessageLog
for appending error messagesmonitor
- the monitor for canceling this potentially long running operation.- Returns:
- the new created block
- Throws:
AddressOverflowException
- if the address
-
adjustFragment
public static void adjustFragment(Program program, Address address, java.lang.String name)
Adjusts the name of the fragment at the given address to the given name.- Parameters:
program
- the program whose fragment is to be renamed.address
- the address of the fragment to be renamed.name
- the new name for the fragment.
-
createFileBytes
public static FileBytes createFileBytes(Program program, ByteProvider provider, TaskMonitor monitor) throws java.io.IOException, CancelledException
Creates a newFileBytes
object using all the bytes from aByteProvider
- Parameters:
program
- the program in which to create a new FileBytes objectprovider
- the ByteProvider from which to get the bytes.monitor
- the monitor for canceling this potentially long running operation.- Returns:
- the newly created FileBytes object.
- Throws:
java.io.IOException
- if an IOException occurred.CancelledException
-
createFileBytes
public static FileBytes createFileBytes(Program program, ByteProvider provider, long offset, long length, TaskMonitor monitor) throws java.io.IOException, CancelledException
Creates a newFileBytes
object using a portion of the bytes from aByteProvider
- Parameters:
program
- the program in which to create a new FileBytes objectprovider
- the ByteProvider from which to get the bytes.offset
- the offset into the ByteProvider from which to start loading bytes.length
- the number of bytes to loadmonitor
- the monitor for canceling this potentially long running operation.- Returns:
- the newly created FileBytes object.
- Throws:
java.io.IOException
- if an IOException occurred.CancelledException
- if the user cancelled the operation
-
-