Package ghidra.program.model.mem
Interface MemBuffer
-
- All Known Subinterfaces:
CodeUnit,Data,Instruction,MutableMemBuffer
- All Known Implementing Classes:
ByteMemBufferImpl,DataStub,DumbMemBufferImpl,EmulateMemoryStateBuffer,InstructionDB,InstructionStub,MemoryBufferImpl,PseudoData,PseudoInstruction,WrappedMemBuffer
public interface MemBufferMemBuffer provides an array like interface into memory at a specific address. Bytes can be retrieved by using a positive offset from the current position. Depending on the implementation, the offset may be restricted to a specific positive range. If the implementation does have a restriction, then a MemoryAccessException will be thrown, except for thegetBytes(byte[], int)method which will return 0. The purpose of this class is to allow an efficient implementation that buffers memory accesses and does not have to keep translating addresses. This was designed to be passed to a language parser. One advantage of MemBuffer over a byte array is that if necessary the actual Memory and Address can be retrieved in case all of the necessary bytes are not local. This interface does not provide methods to reposition the memory buffer. This is so that it is clear that methods accepting this base class are not to mess which the base Address for this object. Memory-backed access is an optional implementation dependent capability. In addition, the use of the relative offset is implementation dependent, but in general those implementations which are backed by memory may choose to wrap the offset when computing the corresponding memory address. The treatment of the offset argument should be consistent across the various methods for a given implementation.- See Also:
MutableMemBuffer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description AddressgetAddress()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.default intgetUnsignedByte(int offset)Get one unsigned byte from memory at the current position plus offset.default longgetUnsignedInt(int offset)Returns the unsigned int at the given offset, taking into account the endianess.default intgetUnsignedShort(int offset)Returns the unsigned short at the given offset, taking into account the endian-ness.default intgetVarLengthInt(int offset, int len)Returns the signed value of the integer (of the specified length) at the specified offset.default longgetVarLengthUnsignedInt(int offset, int len)Returns the unsigned value of the integer (of the specified length) at the specified offset.booleanisBigEndian()Returns true if the underlying bytes are in big-endian order, false if they are little endian.
-
-
-
Method Detail
-
getByte
byte getByte(int offset) throws MemoryAccessExceptionGet one byte from memory at the current position plus offset.- 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
-
getUnsignedByte
default int getUnsignedByte(int offset) throws MemoryAccessExceptionGet one unsigned byte from memory at the current position plus offset.- Parameters:
offset- the displacement from the current position.- Returns:
- the byte data at offset from the current position, as a
intvalue. - Throws:
MemoryAccessException- if memory cannot be read at the specified offset
-
getBytes
int getBytes(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. The actual number of bytes may be fewer if bytes can't be read.- 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.
-
getAddress
Address getAddress()
Get the Address which corresponds to the offset 0.- Returns:
- the current address of offset 0.
-
getMemory
Memory getMemory()
Get the Memory object actually used by the MemBuffer.- Returns:
- the Memory used by this MemBuffer.
-
isBigEndian
boolean isBigEndian()
Returns true if the underlying bytes are in big-endian order, false if they are little endian.- Returns:
- true if the underlying bytes are in big-endian order, false if they are little endian.
-
getShort
short getShort(int offset) throws MemoryAccessExceptionreturns the short at the given offset, taking into account the endianess.- 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
-
getUnsignedShort
default int getUnsignedShort(int offset) throws MemoryAccessExceptionReturns the unsigned short at the given offset, taking into account the endian-ness.- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)- Returns:
- the unsigned short at the given offset, as a
int, taking into account the endianess. - Throws:
MemoryAccessException- if a 2-byte short value cannot be read at the specified offset
-
getInt
int getInt(int offset) throws MemoryAccessExceptionreturns the int at the given offset, taking into account the endianess.- 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
-
getUnsignedInt
default long getUnsignedInt(int offset) throws MemoryAccessExceptionReturns the unsigned int at the given offset, taking into account the endianess.- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)- Returns:
- the unsigned int at the given offset, as a
long, taking into account the endianess. - Throws:
MemoryAccessException- if a 4-byte integer value cannot be read at the specified offset
-
getLong
long getLong(int offset) throws MemoryAccessExceptionreturns the long at the given offset, taking into account the endianess.- 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
java.math.BigInteger getBigInteger(int offset, int size, boolean signed) throws MemoryAccessExceptionreturns the value at the given offset, taking into account the endianess.- 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
-
getVarLengthInt
default int getVarLengthInt(int offset, int len) throws MemoryAccessExceptionReturns the signed value of the integer (of the specified length) at the specified offset.- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)len- the number of bytes that the integer occupies (ie. 2 bytes == short int, 4 bytes == 32bit int, etc), valid lens are 1, 2 and 4.- Returns:
- int integer value
- Throws:
MemoryAccessException
-
getVarLengthUnsignedInt
default long getVarLengthUnsignedInt(int offset, int len) throws MemoryAccessExceptionReturns the unsigned value of the integer (of the specified length) at the specified offset.- Parameters:
offset- the offset from the membuffers origin (the address that it is set at)len- the number of bytes that the integer occupies (ie. 2 bytes == short int, 4 bytes == 32bit int, etc), valid lens are 1, 2 and 4.- Returns:
- long integer value
- Throws:
MemoryAccessException
-
-