public class

VirtualMemoryUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.units.code.asm.memory.VirtualMemoryUtil

Class Overview

Utility methods for virtual memory classes.

Summary

Public Constructors
VirtualMemoryUtil()
Public Methods
static long allocate(IVirtualMemory mem, long start, int size, int protection)
Search an available range and allocate at least the requested amount of bytes.
static int allocateFillGaps(IVirtualMemory mem, long address, int size, int protection)
Allocate a memory range, filling gaps in between already allocated pages if needed.
static int convertSegmentFlagsToVMFlags(int segmentFlags)
static IVirtualMemory createMemory(int spaceBits, int pageBits, Endianness standardEndianness)
Facade factory method returning a concrete, private implementation of an efficient page-based virtual memory.
static long findAvailableRange(IVirtualMemory mem, long start, int size)
Search for an available memory range.
static boolean isPageAllocated(IVirtualMemory mem, long address)
Verify if a page was allocated (regardless of protection rights on the page).
static int read(IVirtualMemory mem, long address)
Read a single byte and perform a zero-extension.
static boolean readByteSafe(IVirtualMemory mem, long address, byte[] out)
Read a byte safely (this method does not raise MemoryException).
static int readBytesSafe(IVirtualMemory mem, long address, int size, byte[] dst, int dstOffset, int protection)
Safely read at most the requested amount of bytes.
static boolean readIntSafe(Endianness end, IVirtualMemory mem, long address, int[] out)
static boolean readLEIntSafe(IVirtualMemory mem, long address, int[] out)
static boolean readLELongSafe(IVirtualMemory mem, long address, long[] out)
static boolean readLEShortSafe(IVirtualMemory mem, long address, short[] out)
static boolean readLongSafe(Endianness end, IVirtualMemory mem, long address, long[] out)
static boolean readSafe(IVirtualMemory mem, long address, byte[] data)
Read an array of bytes from memory (this method does not raise MemoryException).
static boolean readShortSafe(Endianness end, IVirtualMemory mem, long address, short[] out)
static boolean writeByteSafe(IVirtualMemory mem, long address, byte v)
Write a byte safely (this method does not raise MemoryException).
static boolean writeIntSafe(Endianness end, IVirtualMemory mem, long address, int v)
static boolean writeLEIntSafe(IVirtualMemory mem, long address, int v)
static boolean writeLELongSafe(IVirtualMemory mem, long address, long v)
static boolean writeLEShortSafe(IVirtualMemory mem, long address, short v)
static boolean writeLongSafe(Endianness end, IVirtualMemory mem, long address, long v)
static boolean writeSafe(IVirtualMemory mem, long address, byte[] data)
Write an array of bytes to memory (this method does not raise MemoryException).
static boolean writeShortSafe(Endianness end, IVirtualMemory mem, long address, short v)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public VirtualMemoryUtil ()

Public Methods

public static long allocate (IVirtualMemory mem, long start, int size, int protection)

Search an available range and allocate at least the requested amount of bytes. Do not confuse this method with allocate(long, int, int).

Parameters
start soft start address, considered a hint by this allocator routine; if you wish to allocate at a fixed, given address, use allocate(long, int, int)
size range size
Returns
  • the base address of the allocated memory range; 0 on error

public static int allocateFillGaps (IVirtualMemory mem, long address, int size, int protection)

Allocate a memory range, filling gaps in between already allocated pages if needed. (The given range [address, address + size) may have already allocated pages. Those pages will not be re-allocated.) When the method returns, the range [address, address + size) is guaranteed to be allocated.

Returns
  • the number of pages that were actually allocated

public static int convertSegmentFlagsToVMFlags (int segmentFlags)

public static IVirtualMemory createMemory (int spaceBits, int pageBits, Endianness standardEndianness)

Facade factory method returning a concrete, private implementation of an efficient page-based virtual memory.

public static long findAvailableRange (IVirtualMemory mem, long start, int size)

Search for an available memory range.

Parameters
start soft start address, a hint
size range size
Returns
  • the range start address, 0 on error

public static boolean isPageAllocated (IVirtualMemory mem, long address)

Verify if a page was allocated (regardless of protection rights on the page).

public static int read (IVirtualMemory mem, long address)

Read a single byte and perform a zero-extension. This method does not raise MemoryException; on error, -1 is returned.

Returns
  • the byte, zero-extended over 32-bit; in other words, an integer in [0, 255]. On error, -1 is returned.

public static boolean readByteSafe (IVirtualMemory mem, long address, byte[] out)

Read a byte safely (this method does not raise MemoryException).

Parameters
mem virtual memory
address address
out a 1-unit long array that will receive the value read
Returns
  • success indicator

public static int readBytesSafe (IVirtualMemory mem, long address, int size, byte[] dst, int dstOffset, int protection)

Safely read at most the requested amount of bytes.

Parameters
mem the memory
address target address
size requested read size
dst destination buffer
dstOffset position within the destination buffer
protection the requested protection level, should be at least ACCESS_READ
Returns
  • the number of bytes read; may be less than requested. -1 if an unknown error occurs

public static boolean readIntSafe (Endianness end, IVirtualMemory mem, long address, int[] out)

public static boolean readLEIntSafe (IVirtualMemory mem, long address, int[] out)

public static boolean readLELongSafe (IVirtualMemory mem, long address, long[] out)

public static boolean readLEShortSafe (IVirtualMemory mem, long address, short[] out)

public static boolean readLongSafe (Endianness end, IVirtualMemory mem, long address, long[] out)

public static boolean readSafe (IVirtualMemory mem, long address, byte[] data)

Read an array of bytes from memory (this method does not raise MemoryException).

Returns
  • success indicator

public static boolean readShortSafe (Endianness end, IVirtualMemory mem, long address, short[] out)

public static boolean writeByteSafe (IVirtualMemory mem, long address, byte v)

Write a byte safely (this method does not raise MemoryException).

Parameters
mem virtual memory
address address
v the value to be written
Returns
  • success indicator

public static boolean writeIntSafe (Endianness end, IVirtualMemory mem, long address, int v)

public static boolean writeLEIntSafe (IVirtualMemory mem, long address, int v)

public static boolean writeLELongSafe (IVirtualMemory mem, long address, long v)

public static boolean writeLEShortSafe (IVirtualMemory mem, long address, short v)

public static boolean writeLongSafe (Endianness end, IVirtualMemory mem, long address, long v)

public static boolean writeSafe (IVirtualMemory mem, long address, byte[] data)

Write an array of bytes to memory (this method does not raise MemoryException).

Returns
  • success indicator

public static boolean writeShortSafe (Endianness end, IVirtualMemory mem, long address, short v)