public interface

IVirtualMemory

com.pnfsoftware.jeb.core.units.code.IVirtualMemory
Known Indirect Subclasses

Class Overview

Definition of a virtual memory space addressing bytes. Up to 2^64 bytes may addressed. The page size is variable.

Implementors may decide to provide support for concurrency.

Summary

Constants
int ACCESS_EXECUTE
int ACCESS_NONE No access.
int ACCESS_READ
int ACCESS_RW Read/Write access.
int ACCESS_RWX Read/Write/Execute access.
int ACCESS_RX Read/Execute access.
int ACCESS_WRITE
Public Methods
abstract void allocate(long address, int size, int protection)
Allocate the entire memory range or nothing.
abstract int check(long address, int size, int protection)
Check if a memory range has at least the given set of protection flags.
abstract int getPageProtection(long address)
Set the protection flags for a page.
abstract int getPageSize()
Get the size of a page in bytes.
abstract int getSpaceBits()
Get the size of this memory space in bits.
abstract boolean isValidAddress(long address)
Determine if an address is valid for this memory space.
abstract int read(long address, int size, byte[] dst, int dstOffset)
Read a range of bytes.
abstract byte readByte(long address)
Read a byte.@return
abstract int readLEInt(long address)
Read a little-endian 32-bit integer.
abstract long readLELong(long address)
Read a little-endian 64-bit integer.
abstract short readLEShort(long address)
Read a little-endian 16-bit integer.
abstract long roundToPage(long address)
Round an address to the page this address currently resides in, that is the highest page so that boundary ≤ address.
abstract long roundToSize(long address)
Round an address to the lowest page boundary so that address ≤ boundary.
abstract void setPageProtection(long address, int protection)
Get the protection flags for a page.
abstract int write(long address, int size, byte[] src, int srcOffset)
Write a range of bytes.
abstract void writeByte(long address, byte v)
Write a byte.
abstract void writeLEInt(long address, int v)
Write a little-endian 32-bit integer.
abstract void writeLELong(long address, long v)
Write a little-endian 64-bit integer.
abstract void writeLEShort(long address, short v)
Write a little-endian 16-bit integer.

Constants

public static final int ACCESS_EXECUTE

Constant Value: 4 (0x00000004)

public static final int ACCESS_NONE

No access. The page exists but any attempt to write, read, or execute from/to it will raise.

Constant Value: 0 (0x00000000)

public static final int ACCESS_READ

Constant Value: 1 (0x00000001)

public static final int ACCESS_RW

Read/Write access.

Constant Value: 3 (0x00000003)

public static final int ACCESS_RWX

Read/Write/Execute access.

Constant Value: 7 (0x00000007)

public static final int ACCESS_RX

Read/Execute access.

Constant Value: 5 (0x00000005)

public static final int ACCESS_WRITE

Constant Value: 2 (0x00000002)

Public Methods

public abstract void allocate (long address, int size, int protection)

Allocate the entire memory range or nothing. On error, this method should throw a MemoryException, and no page should have been allocated. If successful, all pages within the range should have been been allocated.

public abstract int check (long address, int size, int protection)

Check if a memory range has at least the given set of protection flags. For example, if the `protection` argument is ACCESS_RW,

Parameters
address start address
size range size
protection protection to check
Returns
  • the number of contiguous bytes, starting from `address`, that have the given protection flags. The amount may be less than `size`. If the check is successful, the returned value should be equal to `size`

public abstract int getPageProtection (long address)

Set the protection flags for a page. This method raises on error (invalid address, no page, etc.)

Parameters
address address within the page
Returns
  • the protection bits

public abstract int getPageSize ()

Get the size of a page in bytes. A page size should always be a multiple of 2.

public abstract int getSpaceBits ()

Get the size of this memory space in bits. Example: 32 for a 32-bit address space.

public abstract boolean isValidAddress (long address)

Determine if an address is valid for this memory space.

Returns
  • true if the address is not larger than what this memory space allows, that is, 0 ≤ address < spaceSize

public abstract int read (long address, int size, byte[] dst, int dstOffset)

Read a range of bytes. This method should do its best to transact: the entire range is read, or nothing is and an error is thrown. If the implementor cannot support transaction, this method simply returns the amount of bytes read.

Returns
  • the amount of bytes read
Throws
MemoryException if the method failed

public abstract byte readByte (long address)

Read a byte.@return

public abstract int readLEInt (long address)

Read a little-endian 32-bit integer. This method does not do partial reads.@return

public abstract long readLELong (long address)

Read a little-endian 64-bit integer. This method does not do partial reads.@return

public abstract short readLEShort (long address)

Read a little-endian 16-bit integer. This method does not do partial reads.@return

public abstract long roundToPage (long address)

Round an address to the page this address currently resides in, that is the highest page so that boundary ≤ address. This method does not raise, even if the address is invalid for this memory space.

Parameters
address an address
Returns
  • the containing page address

public abstract long roundToSize (long address)

Round an address to the lowest page boundary so that address ≤ boundary. This method does not raise, even if the address is invalid for this memory space.

Parameters
address an address or a size

public abstract void setPageProtection (long address, int protection)

Get the protection flags for a page. This method raises on error (invalid address, no page, etc.)

Parameters
address address within the page
protection the new protection for the page

public abstract int write (long address, int size, byte[] src, int srcOffset)

Write a range of bytes. This method should do its best to transact: the entire range is written, or nothing is and an error is thrown. If the implementor cannot support transaction, this method returns the amount of bytes written, or throws on error.

Returns
  • the amount of bytes written
Throws
MemoryException if the method failed

public abstract void writeByte (long address, byte v)

Write a byte.

public abstract void writeLEInt (long address, int v)

Write a little-endian 32-bit integer. This method does not do partial writes.

public abstract void writeLELong (long address, long v)

Write a little-endian 64-bit integer. This method does not do partial writes.

public abstract void writeLEShort (long address, short v)

Write a little-endian 16-bit integer. This method does not do partial writes.