Class AbstractVirtualMemory
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.memory.AbstractVirtualMemory
- All Implemented Interfaces:
IVirtualMemory
A skeleton implementation for virtual memory classes. Most trivial methods are implemented here.
-
Field Summary
Fields inherited from interface com.pnfsoftware.jeb.core.units.code.asm.memory.IVirtualMemory
ACCESS_EXECUTE, ACCESS_NONE, ACCESS_READ, ACCESS_RW, ACCESS_RWX, ACCESS_RX, ACCESS_WRITE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllocListener
(IMemoryAllocListener listener) void
addFreeListener
(IMemoryFreeListener listener) void
addPreWriteListener
(IMemoryWriteListener listener) Note: The callback is invoked before the write operation takes place.void
addPropertyListener
(IMemoryPropertyListener listener) void
void
addWriteListener
(IMemoryWriteListener listener) void
allocatePage
(long address, int protection) Allocate a single page.void
freePage
(long address) Free a single page.protected List<IMemoryAllocListener>
int
Determine the approximate memory footprint of this object, in kilobytes.protected List<IMemoryFreeListener>
protected List<IMemoryWriteListener>
protected List<IMemoryPropertyListener>
protected List<IMemoryProtectionListener>
protected List<IMemoryWriteListener>
int
readBEInt
(long address) Read a big-endian 32-bit integer.long
readBELong
(long address) Read a big-endian 64-bit integer.short
readBEShort
(long address) Read a big-endian 16-bit integer.byte
readByte
(long address) Convenience method.int
readInt
(long address) Read a 32-bit integer using thestandard endianness
.int
readInt
(long address, Endianness end) Read a 32-bit integer.int
readLEInt
(long address) Read a little-endian 32-bit integer.long
readLELong
(long address) Read a little-endian 64-bit integer.short
readLEShort
(long address) Read a little-endian 16-bit integer.long
readLong
(long address) Read a 64-bit integer using thestandard endianness
.long
readLong
(long address, Endianness end) Read a 64-bit integer.long
readPointer
(long address) short
readShort
(long address) Read a 16-bit integer using thestandard endianness
.short
readShort
(long address, Endianness end) Read a 16-bit integer.void
removeAllocListener
(IMemoryAllocListener listener) void
removeFreeListener
(IMemoryFreeListener listener) void
removePreWriteListener
(IMemoryWriteListener listener) void
void
void
removeWriteListener
(IMemoryWriteListener listener) long
roundToPage
(long address) Round an address to the page this address currently resides in, that is the highest page so that boundary ≤ address.long
roundToSize
(long address) Round an address to the lowest page boundary so that address ≤ boundary.void
setLazyMemoryProvider
(ILazyMemoryProvider lazyMemoryProvider, boolean skipFailedAllocations) Set a lazy memory provider.void
writeBEInt
(long address, int v) Write a big-endian 32-bit integer.void
writeBELong
(long address, long v) Write a big-endian 64-bit integer.void
writeBEShort
(long address, short v) Write a big-endian 16-bit integer.void
writeByte
(long address, byte v) Write a byte.void
writeInt
(long address, int v) Write a 32-bit integer using thestandard endianness
.void
writeInt
(long address, int v, Endianness end) Write a 32-bit integer.void
writeLEInt
(long address, int v) Write a little-endian 32-bit integer.void
writeLELong
(long address, long v) Write a little-endian 64-bit integer.void
writeLEShort
(long address, short v) Write a little-endian 16-bit integer.void
writeLong
(long address, long v) Write a 64-bit integer using thestandard endianness
.void
writeLong
(long address, long v, Endianness end) Write a 64-bit integer.void
writePointer
(long address, long ptr) void
writeShort
(long address, short v) Write a 16-bit integer using thestandard endianness
.void
writeShort
(long address, short v, Endianness end) Write a 16-bit integer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.pnfsoftware.jeb.core.units.code.asm.memory.IVirtualMemory
allocate, check, duplicate, free, getAllocatedPageBases, getAllocatedPageCount, getPageBits, getPageProtection, getPageSize, getSpaceBits, getStandardEndianess, isAllocatedPage, isValidAddress, read, read, setPageProtection, setStandardEndianness, write, write
-
Constructor Details
-
AbstractVirtualMemory
public AbstractVirtualMemory()
-
-
Method Details
-
roundToPage
public long roundToPage(long address) Description copied from interface:IVirtualMemory
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.- Specified by:
roundToPage
in interfaceIVirtualMemory
- Parameters:
address
- an address- Returns:
- the containing page address
-
roundToSize
public long roundToSize(long address) Description copied from interface:IVirtualMemory
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.- Specified by:
roundToSize
in interfaceIVirtualMemory
- Parameters:
address
- an address or a size- Returns:
-
allocatePage
Description copied from interface:IVirtualMemory
Allocate a single page. SeeIVirtualMemory.allocate(long, int, int)
.- Specified by:
allocatePage
in interfaceIVirtualMemory
- Throws:
MemoryException
-
freePage
Description copied from interface:IVirtualMemory
Free a single page. SeeIVirtualMemory.free(long, int)
.- Specified by:
freePage
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readByte
Description copied from interface:IVirtualMemory
Convenience method. Read a byte.- Specified by:
readByte
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeByte
Description copied from interface:IVirtualMemory
Write a byte.- Specified by:
writeByte
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readLEShort
Description copied from interface:IVirtualMemory
Read a little-endian 16-bit integer. This method does not do partial reads.- Specified by:
readLEShort
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeLEShort
Description copied from interface:IVirtualMemory
Write a little-endian 16-bit integer. This method does not do partial writes.- Specified by:
writeLEShort
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readLEInt
Description copied from interface:IVirtualMemory
Read a little-endian 32-bit integer. This method does not do partial reads.- Specified by:
readLEInt
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeLEInt
Description copied from interface:IVirtualMemory
Write a little-endian 32-bit integer. This method does not do partial writes.- Specified by:
writeLEInt
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readLELong
Description copied from interface:IVirtualMemory
Read a little-endian 64-bit integer. This method does not do partial reads.- Specified by:
readLELong
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeLELong
Description copied from interface:IVirtualMemory
Write a little-endian 64-bit integer. This method does not do partial writes.- Specified by:
writeLELong
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readBEShort
Description copied from interface:IVirtualMemory
Read a big-endian 16-bit integer. This method does not do partial reads.- Specified by:
readBEShort
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeBEShort
Description copied from interface:IVirtualMemory
Write a big-endian 16-bit integer. This method does not do partial writes.- Specified by:
writeBEShort
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readBEInt
Description copied from interface:IVirtualMemory
Read a big-endian 32-bit integer. This method does not do partial reads.- Specified by:
readBEInt
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeBEInt
Description copied from interface:IVirtualMemory
Write a big-endian 32-bit integer. This method does not do partial writes.- Specified by:
writeBEInt
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readBELong
Description copied from interface:IVirtualMemory
Read a big-endian 64-bit integer. This method does not do partial reads.- Specified by:
readBELong
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeBELong
Description copied from interface:IVirtualMemory
Write a big-endian 64-bit integer. This method does not do partial writes.- Specified by:
writeBELong
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readShort
Description copied from interface:IVirtualMemory
Read a 16-bit integer using thestandard endianness
. This method does not do partial reads.- Specified by:
readShort
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeShort
Description copied from interface:IVirtualMemory
Write a 16-bit integer using thestandard endianness
. This method does not do partial writes.- Specified by:
writeShort
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readInt
Description copied from interface:IVirtualMemory
Read a 32-bit integer using thestandard endianness
. This method does not do partial reads.- Specified by:
readInt
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeInt
Description copied from interface:IVirtualMemory
Write a 32-bit integer using thestandard endianness
. This method does not do partial writes.- Specified by:
writeInt
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readLong
Description copied from interface:IVirtualMemory
Read a 64-bit integer using thestandard endianness
. This method does not do partial reads.- Specified by:
readLong
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeLong
Description copied from interface:IVirtualMemory
Write a 64-bit integer using thestandard endianness
. This method does not do partial writes.- Specified by:
writeLong
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readShort
Description copied from interface:IVirtualMemory
Read a 16-bit integer. This method does not do partial reads.- Specified by:
readShort
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeShort
Description copied from interface:IVirtualMemory
Write a 16-bit integer. This method does not do partial writes.- Specified by:
writeShort
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readInt
Description copied from interface:IVirtualMemory
Read a 32-bit integer. This method does not do partial reads.- Specified by:
readInt
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeInt
Description copied from interface:IVirtualMemory
Write a 32-bit integer. This method does not do partial writes.- Specified by:
writeInt
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readLong
Description copied from interface:IVirtualMemory
Read a 64-bit integer. This method does not do partial reads.- Specified by:
readLong
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writeLong
Description copied from interface:IVirtualMemory
Write a 64-bit integer. This method does not do partial writes.- Specified by:
writeLong
in interfaceIVirtualMemory
- Throws:
MemoryException
-
readPointer
- Specified by:
readPointer
in interfaceIVirtualMemory
- Returns:
- Throws:
MemoryException
-
writePointer
- Specified by:
writePointer
in interfaceIVirtualMemory
- Throws:
MemoryException
-
getPropertyListeners
-
getAllocListeners
-
getFreeListeners
-
getProtectionListeners
-
getPreWriteListeners
-
getWriteListeners
-
addPropertyListener
- Specified by:
addPropertyListener
in interfaceIVirtualMemory
-
removePropertyListener
- Specified by:
removePropertyListener
in interfaceIVirtualMemory
-
addAllocListener
- Specified by:
addAllocListener
in interfaceIVirtualMemory
-
removeAllocListener
- Specified by:
removeAllocListener
in interfaceIVirtualMemory
-
addFreeListener
- Specified by:
addFreeListener
in interfaceIVirtualMemory
-
removeFreeListener
- Specified by:
removeFreeListener
in interfaceIVirtualMemory
-
addProtectionListener
- Specified by:
addProtectionListener
in interfaceIVirtualMemory
-
removeProtectionListener
- Specified by:
removeProtectionListener
in interfaceIVirtualMemory
-
addPreWriteListener
Description copied from interface:IVirtualMemory
Note: The callback is invoked before the write operation takes place.- Specified by:
addPreWriteListener
in interfaceIVirtualMemory
-
removePreWriteListener
- Specified by:
removePreWriteListener
in interfaceIVirtualMemory
-
addWriteListener
- Specified by:
addWriteListener
in interfaceIVirtualMemory
-
removeWriteListener
- Specified by:
removeWriteListener
in interfaceIVirtualMemory
-
setLazyMemoryProvider
public void setLazyMemoryProvider(ILazyMemoryProvider lazyMemoryProvider, boolean skipFailedAllocations) throws MemoryException, UnsupportedOperationException Description copied from interface:IVirtualMemory
Set a lazy memory provider. This operation is optional. If the memory object supports it, theILazyMemoryProvider.getRanges()
method will be called to reserve the ranges of memory that the provider can provide. A lazy provider provides memory data on demand, i.e. when the data bytes are accessed (read or write).- Specified by:
setLazyMemoryProvider
in interfaceIVirtualMemory
- Parameters:
lazyMemoryProvider
- a non-null lazy memory providerskipFailedAllocations
- if true, the provider will not hard-fail if it provides data for a range for which data already exists in the virtual memory; else, the method will throw- Throws:
MemoryException
- if a page reservation failed and skipFailedAllocations isfalse
(example: the memory provider requests to allocate an already allocated range)UnsupportedOperationException
- if the implementation does not support that feature
-
getAproximateFootprint
public int getAproximateFootprint()Description copied from interface:IVirtualMemory
Determine the approximate memory footprint of this object, in kilobytes.- Specified by:
getAproximateFootprint
in interfaceIVirtualMemory
- Returns:
- a size in Kb
-