decompiler
1.0.0
|
Memory storage/state for a single AddressSpace. More...
#include <memstate.hh>
Public Member Functions | |
MemoryBank (AddrSpace *spc, int4 ws, int4 ps) | |
Generic constructor for a memory bank. More... | |
int4 | getWordSize (void) const |
Get the number of bytes in a word for this memory bank. More... | |
int4 | getPageSize (void) const |
Get the number of bytes in a page for this memory bank. More... | |
AddrSpace * | getSpace (void) const |
Get the address space associated with this memory bank. More... | |
void | setValue (uintb offset, int4 size, uintb val) |
Set the value of a (small) range of bytes. More... | |
uintb | getValue (uintb offset, int4 size) const |
Retrieve the value encoded in a (small) range of bytes. More... | |
void | setChunk (uintb offset, int4 size, const uint1 *val) |
Set values of an arbitrary sequence of bytes. More... | |
void | getChunk (uintb offset, int4 size, uint1 *res) const |
Retrieve an arbitrary sequence of bytes. More... | |
Static Public Member Functions | |
static uintb | constructValue (const uint1 *ptr, int4 size, bool bigendian) |
Decode bytes to value. More... | |
static void | deconstructValue (uint1 *ptr, uintb val, int4 size, bool bigendian) |
Encode value to bytes. More... | |
Protected Member Functions | |
virtual void | insert (uintb addr, uintb val)=0 |
Insert a word in memory bank at an aligned location. | |
virtual uintb | find (uintb addr) const =0 |
Retrieve a word from memory bank at an aligned location. | |
virtual void | getPage (uintb addr, uint1 *res, int4 skip, int4 size) const |
Retrieve data from a memory page. More... | |
virtual void | setPage (uintb addr, const uint1 *val, int4 skip, int4 size) |
Write data into a memory page. More... | |
Private Attributes | |
int4 | wordsize |
Number of bytes in an aligned word access. | |
int4 | pagesize |
Number of bytes in an aligned page access. | |
AddrSpace * | space |
The address space associated with this memory. | |
Friends | |
class | MemoryPageOverlay |
class | MemoryHashOverlay |
Memory storage/state for a single AddressSpace.
Class for setting and getting memory values within a space The basic API is to get/set arrays of byte values via offset within the space. Helper functions getValue and setValue easily retrieve/store integers of various sizes from memory, using the endianness encoding specified by the space. Accesses through the public interface, are automatically broken down into word accesses, through the private insert/find methods, and page accesses through getPage/setPage. So these are the virtual methods that need to be overridden in the derived classes.
ghidra::MemoryBank::MemoryBank | ( | AddrSpace * | spc, |
int4 | ws, | ||
int4 | ps | ||
) |
Generic constructor for a memory bank.
A MemoryBank must be associated with a specific address space, have a preferred or natural wordsize and a natural pagesize. Both the wordsize and pagesize must be a power of 2.
spc | is the associated address space |
ws | is the number of bytes in the preferred wordsize |
ps | is the number of bytes in a page |
|
static |
Decode bytes to value.
This is a static convenience routine for decoding a value from a sequence of bytes depending on the desired endianness
ptr | is the pointer to the bytes to decode |
size | is the number of bytes |
bigendian | is true if the bytes are encoded in big endian form |
Referenced by ghidra::MemoryPageOverlay::find().
|
static |
Encode value to bytes.
This is a static convenience routine for encoding bytes from a given value, depending on the desired endianness
ptr | is a pointer to the location to write the encoded bytes |
val | is the value to be encoded |
size | is the number of bytes to encode |
bigendian | is true if a big endian encoding is desired |
Referenced by ghidra::MemoryPageOverlay::insert().
void ghidra::MemoryBank::getChunk | ( | uintb | offset, |
int4 | size, | ||
uint1 * | res | ||
) | const |
Retrieve an arbitrary sequence of bytes.
This is the most general method for reading a sequence of bytes from the memory bank. There is no restriction on the offset or the number of bytes to read, except that the range must be contained in the address space.
offset | is the start of the byte range to read |
size | is the number of bytes to read |
res | is a pointer to where the retrieved bytes should be stored |
References getPage(), and pagesize.
Referenced by ghidra::MemoryState::getChunk().
|
protectedvirtual |
Retrieve data from a memory page.
This routine only retrieves data from a single page in the memory bank. Bytes need not be retrieved from the exact start of a page, but all bytes must come from one page. A page is a fixed number of bytes, and the address of a page is always aligned based on that number of bytes. This routine may be overridden for a page based implementation of the MemoryBank. The default implementation retrieves the page as aligned words using the find method.
addr | is the aligned offset of the desired page |
res | is a pointer to where fetched data should be written |
skip | is the offset into the page to get the bytes from |
size | is the number of bytes to retrieve |
Reimplemented in ghidra::MemoryPageOverlay, and ghidra::MemoryImage.
References find(), ghidra::AddrSpace::isBigEndian(), space, and wordsize.
Referenced by getChunk(), and ghidra::MemoryImage::insert().
|
inline |
Get the number of bytes in a page for this memory bank.
A MemoryBank is instantiated with a natural page size. Requests for large chunks of data may be broken down into units of this size.
References pagesize.
Referenced by ghidra::MemoryPageOverlay::find(), ghidra::MemoryPageOverlay::insert(), and ghidra::MemoryPageOverlay::setPage().
|
inline |
Get the address space associated with this memory bank.
A MemoryBank is a contiguous sequence of bytes associated with a particular address space.
References space.
Referenced by ghidra::MemoryImage::find(), ghidra::MemoryPageOverlay::find(), ghidra::MemoryImage::getPage(), ghidra::MemoryPageOverlay::insert(), and ghidra::MemoryState::setMemoryBank().
uintb ghidra::MemoryBank::getValue | ( | uintb | offset, |
int4 | size | ||
) | const |
Retrieve the value encoded in a (small) range of bytes.
This routine gets the value from a range of bytes at an arbitrary address. It takes into account the endianness of the underlying space when decoding the value. The value is constructed by making one or more aligned word queries, using the find method. The desired value may span multiple words and is reconstructed properly.
offset | is the start of the byte range encoding the value |
size | is the number of bytes in the range |
References ghidra::calc_mask(), find(), ghidra::AddrSpace::isBigEndian(), space, and wordsize.
Referenced by ghidra::JumpBasic::backup2Switch(), ghidra::JumpBasic::findNormalized(), and ghidra::MemoryState::getValue().
|
inline |
Get the number of bytes in a word for this memory bank.
A MemoryBank is instantiated with a natural word size. Requests for arbitrary byte ranges may be broken down into units of this size.
References wordsize.
Referenced by ghidra::MemoryImage::find(), ghidra::MemoryPageOverlay::find(), and ghidra::MemoryPageOverlay::insert().
void ghidra::MemoryBank::setChunk | ( | uintb | offset, |
int4 | size, | ||
const uint1 * | val | ||
) |
Set values of an arbitrary sequence of bytes.
This the most general method for writing a sequence of bytes into the memory bank. There is no restriction on the offset to write to or the number of bytes to be written, except that the range must be contained in the address space.
offset | is the start of the byte range to be written |
size | is the number of bytes to write |
val | is a pointer to the sequence of bytes to be written into the bank |
References pagesize, and setPage().
Referenced by ghidra::MemoryState::setChunk().
|
protectedvirtual |
Write data into a memory page.
This routine writes data only to a single page of the memory bank. Bytes need not be written to the exact start of the page, but all bytes must be written to only one page when using this routine. A page is a fixed number of bytes, and the address of a page is always aligned based on this size. This routine may be overridden for a page based implementation of the MemoryBank. The default implementation writes the page as a sequence of aligned words, using the insert method.
addr | is the aligned offset of the desired page |
val | is a pointer to the bytes to be written into the page |
skip | is the offset into the page where bytes will be written |
size | is the number of bytes to be written |
Reimplemented in ghidra::MemoryPageOverlay.
References find(), insert(), ghidra::AddrSpace::isBigEndian(), space, and wordsize.
Referenced by setChunk().
void ghidra::MemoryBank::setValue | ( | uintb | offset, |
int4 | size, | ||
uintb | val | ||
) |
Set the value of a (small) range of bytes.
This routine is used to set a single value in the memory bank at an arbitrary address It takes into account the endianness of the associated address space when encoding the value as bytes in the bank. The value is broken up into aligned pieces of wordsize and the actual write is performed with the insert routine. If only parts of aligned words are written to, then the remaining parts are filled in with the original value, via the find routine.
offset | is the start of the byte range to write |
size | is the number of bytes in the range to write |
val | is the value to be written |
References ghidra::calc_mask(), find(), insert(), ghidra::AddrSpace::isBigEndian(), space, and wordsize.
Referenced by ghidra::MemoryState::setValue().