Package ghidra.program.model.mem
Class MemoryBufferImpl
- java.lang.Object
-
- ghidra.program.model.mem.MemoryBufferImpl
-
- All Implemented Interfaces:
MemBuffer,MutableMemBuffer
- Direct Known Subclasses:
DumbMemBufferImpl
public class MemoryBufferImpl extends java.lang.Object implements MutableMemBuffer
MemBufferImpl implements the MemBuffer interface. It buffers up N bytes at time, reducing the overall number of calls to Memory, greatly reducing the overhead of various error checks. This implementation will not wrap if the end of the memory space is encountered. ThegetByte(int)method can cause the buffer cache to adjust if outside the current cache range. This is not the case for other methods which will simply defer to the underlying memory if outside the cache range.
-
-
Constructor Summary
Constructors Constructor Description MemoryBufferImpl(Memory mem, Address addr)Construct a new MemoryBufferImplMemoryBufferImpl(Memory mem, Address addr, int bufSize)Construct a new MemoryBufferImpl
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvance(int displacement)Advance the Address pointer.MemoryBufferImplclone()Create a cloned copy of this MutableMemBufferAddressgetAddress()Get the Address which corresponds to the offset 0.java.math.BigIntegergetBigInteger(int offset, int size, boolean signed)returns the value at the given offset, taking into account the endianess.bytegetByte(int offset)Get one byte from memory at the current position plus offset.intgetBytes(byte[] b, int offset)Reads b.length bytes from this memory buffer starting at the address of this memory buffer plus the given memoryBufferOffset from that position.intgetInt(int offset)returns the int at the given offset, taking into account the endianess.longgetLong(int offset)returns the long at the given offset, taking into account the endianess.MemorygetMemory()Get the Memory object actually used by the MemBuffer.shortgetShort(int offset)returns the short at the given offset, taking into account the endianess.booleanisBigEndian()Returns true if the underlying bytes are in big-endian order, false if they are little endian.voidsetPosition(Address addr)Sets the Address to which offset of 0 points to.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ghidra.program.model.mem.MemBuffer
getUnsignedByte, getUnsignedInt, getUnsignedShort, getVarLengthInt, getVarLengthUnsignedInt, isInitializedMemory
-
-
-
-
Method Detail
-
clone
public MemoryBufferImpl clone()
Description copied from interface:MutableMemBufferCreate a cloned copy of this MutableMemBuffer- Specified by:
clonein interfaceMutableMemBuffer- Overrides:
clonein classjava.lang.Object- Returns:
- new cloned instance of this buffer object
-
advance
public void advance(int displacement) throws AddressOverflowExceptionDescription copied from interface:MutableMemBufferAdvance the Address pointer.- Specified by:
advancein interfaceMutableMemBuffer- Parameters:
displacement- the amount to adjust the pointer by.- Throws:
AddressOverflowException- if displacement would cause the buffer position to wrap.
-
setPosition
public void setPosition(Address addr)
Description copied from interface:MutableMemBufferSets the Address to which offset of 0 points to.- Specified by:
setPositionin interfaceMutableMemBuffer- Parameters:
addr- the new base Address.
-
getByte
public byte getByte(int offset) throws MemoryAccessExceptionDescription copied from interface:MemBufferGet one byte from memory at the current position plus offset.- Specified by:
getBytein interfaceMemBuffer- Parameters:
offset- the displacement from the current position.- Returns:
- the data at offset from the current position.
- Throws:
MemoryAccessException- if memory cannot be read at the specified offset
-
getAddress
public Address getAddress()
Description copied from interface:MemBufferGet the Address which corresponds to the offset 0.- Specified by:
getAddressin interfaceMemBuffer- Returns:
- the current address of offset 0.
-
getMemory
public Memory getMemory()
Description copied from interface:MemBufferGet the Memory object actually used by the MemBuffer.
-
getBytes
public int getBytes(byte[] b, int offset)Description copied from interface:MemBufferReads b.length bytes from this memory buffer starting at the address of this memory buffer plus the given memoryBufferOffset from that position. The actual number of bytes may be fewer if bytes can't be read.- Specified by:
getBytesin interfaceMemBuffer- Parameters:
b- the buffer into which bytes will be placedoffset- the offset in this memory buffer from which to start reading bytes.- Returns:
- the number of bytes read which may be fewer than b.length if available bytes are exhausted or no bytes are available at the specified offset.
-
isBigEndian
public boolean isBigEndian()
Description copied from interface:MemBufferReturns true if the underlying bytes are in big-endian order, false if they are little endian.- Specified by:
isBigEndianin interfaceMemBuffer- Returns:
- true if the underlying bytes are in big-endian order, false if they are little endian.
-
getShort
public short getShort(int offset) throws MemoryAccessExceptionDescription copied from interface:MemBufferreturns the short at the given offset, taking into account the endianess.- Specified by:
getShortin interfaceMemBuffer- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)- Returns:
- the short at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException- if a 2-byte short value cannot be read at the specified offset
-
getInt
public int getInt(int offset) throws MemoryAccessExceptionDescription copied from interface:MemBufferreturns the int at the given offset, taking into account the endianess.- Specified by:
getIntin interfaceMemBuffer- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)- Returns:
- the int at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException- if a 4-byte integer value cannot be read at the specified offset
-
getLong
public long getLong(int offset) throws MemoryAccessExceptionDescription copied from interface:MemBufferreturns the long at the given offset, taking into account the endianess.- Specified by:
getLongin interfaceMemBuffer- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)- Returns:
- the long at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException- if a 8-byte long value cannot be read at the specified offset
-
getBigInteger
public java.math.BigInteger getBigInteger(int offset, int size, boolean signed) throws MemoryAccessExceptionDescription copied from interface:MemBufferreturns the value at the given offset, taking into account the endianess.- Specified by:
getBigIntegerin interfaceMemBuffer- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)size- the number of bytes to include in the valuesigned- true if value should be treated as a signed twos-compliment value.- Returns:
- the value at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException- if the request size value cannot be read at the specified offset
-
-