Java Code Examples for ghidra.program.model.address.AddressSpace#isConstantSpace()

The following examples show how to use ghidra.program.model.address.AddressSpace#isConstantSpace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryState.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * This is the main interface for reading values from the MemoryState.
 * If there is no registered MemoryBank for the desired address space, or
 * if there is some other error, an exception is thrown.
 * @param spc is the address space being queried
 * @param off is the offset of the value being queried
 * @param size is the number of bytes to query
 * @param signed true if signed value should be returned, false for unsigned value
 * @return the queried unsigned value
 */
public final BigInteger getBigInteger(AddressSpace spc, long off, int size, boolean signed) {
	if (spc.isConstantSpace()) {
		if (!signed && off < 0) {
			return new BigInteger(1, Utils.longToBytes(off, 8, true));
		}
		return BigInteger.valueOf(off);
	}
	byte[] bytes = new byte[size];
	getChunk(bytes, spc, off, size, false);
	return Utils.bytesToBigInteger(bytes, size, language.isBigEndian(), signed);
}
 
Example 2
Source File: MemoryState.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * This is the main interface for reading values from the MemoryState.
 * If there is no registered MemoryBank for the desired address space, or
 * if there is some other error, an exception is thrown.
 * @param spc is the address space being queried
 * @param off is the offset of the value being queried
 * @param size is the number of bytes to query
 * @return the queried value
 */
public final long getValue(AddressSpace spc, long off, int size) {
	if (spc.isConstantSpace()) {
		return off;
	}
	byte[] bytes = new byte[size];
	getChunk(bytes, spc, off, size, false);
	return Utils.bytesToLong(bytes, size, language.isBigEndian());
}
 
Example 3
Source File: MemoryState.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * This is the main interface for reading a range of bytes from the MemorySate.
 * The MemoryBank associated with the address space of the query is looked up
 * and the request is forwarded to the getChunk method on the MemoryBank. If there
 * is no registered MemoryBank or some other error, an exception is thrown.
 * All getLongValue methods utilize this method to read the bytes from the
 * appropriate memory bank. 
 * @param res the result buffer for storing retrieved bytes
 * @param spc the desired address space
 * @param off the starting offset of the byte range being read
 * @param size the number of bytes being read
 * @param stopOnUnintialized if true a partial read is permitted and returned size may be 
 * smaller than size requested
 * @return number of bytes actually read
 * @throws LowlevelError if spc has not been mapped within this MemoryState or memory fault
 * handler generated error
 */
public int getChunk(byte[] res, AddressSpace spc, long off, int size,
		boolean stopOnUnintialized) {
	if (spc.isConstantSpace()) {
		System.arraycopy(Utils.longToBytes(off, size, language.isBigEndian()), 0, res, 0, size);
		return size;
	}
	MemoryBank mspace = getMemoryBank(spc);
	if (mspace == null)
		throw new LowlevelError("Getting chunk from unmapped memory space: " + spc.getName());
	return mspace.getChunk(off, size, res, stopOnUnintialized);
}