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

The following examples show how to use ghidra.program.model.address.AddressSpace#getName() . 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: PcodeFormatter.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void formatMemoryInput(Program program, VarnodeTpl input0, VarnodeTpl input1,
		List<AttributedString> lineList) {
	if (!input0.getSpace().isConstSpace() || input0.getOffset().getType() != ConstTpl.REAL) {
		throw new RuntimeException("Expected constant input[0] for LOAD/STORE pcode op");
	}
	int id = (int) input0.getOffset().getReal();
	AddressSpace space = program.getAddressFactory().getAddressSpace(id);
	String spaceName;
	if (space == null) {
		Msg.error(PcodeFormatter.class, "Address space id not found: " + id);
		spaceName = "unknown";
	}
	else {
		spaceName = space.getName();
	}
	lineList.add(new AttributedString(spaceName, Color.BLUE, metrics));
	lineList.add(LEFT_PAREN);
	formatVarnodeTpl(program, -1, 1, input1, lineList);
	lineList.add(RIGHT_PAREN);
}
 
Example 2
Source File: PcodeFormatter.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Format VarnodeTpl in a manner consistent with Varnode.toString().
 * @param space address space
 * @param offset offset of type ConstTpl.REAL
 * @param size size of type ConstTpl.REAL
 * @param lineList
 */
private void formatRaw(AddressSpace space, ConstTpl offset, ConstTpl size,
		List<AttributedString> lineList) {
	// same format as the Varnode.toString
	String str =
		"(" + space.getName() + ", 0x" + Long.toHexString(offset.getReal()) + ", " +
			size.getReal() + ")";
	lineList.add(new AttributedString(str, Color.BLUE, metrics));
}
 
Example 3
Source File: VarnodeOperation.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String toString(Language language) {
	if (pcodeOp.getOpcode() == PcodeOp.INDIRECT) {
		return getIndirectString(language);
	}
	String s = pcodeOp.getMnemonic() + " ";
	for (int i = 0; i < inputValues.length; i++) {
		if (i == 0 &&
			(pcodeOp.getOpcode() == PcodeOp.LOAD || pcodeOp.getOpcode() == PcodeOp.STORE)) {
			AddressSpace space =
				language.getAddressFactory().getAddressSpace((int) inputValues[0].getOffset());
			if (space != null) {
				s += "[" + space.getName() + "], ";
				continue;
			}
		}
		if (inputValues[i] == null) {
			s += "null";
		}
		else if (inputValues[i] instanceof VarnodeOperation) {
			s += "{" + inputValues[i].toString(language) + "}";
		}
		else {
			s += inputValues[i].toString(language);
		}
		if (i < inputValues.length - 1) {
			s += ", ";
		}
	}
	return s;
}
 
Example 4
Source File: PIC30_ElfRelocationContext.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private boolean isDebugSection(AddressSpace overlaySpace) {
	String name = overlaySpace.getName();
	return name.startsWith(".debug_") || ".comment".equals(name);
}
 
Example 5
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);
}
 
Example 6
Source File: MemoryState.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * This is the main interface for setting values for a range of bytes in the MemoryState.
 * The MemoryBank associated with the desired address space is looked up and the
 * write is forwarded to the setChunk method on the MemoryBank. If there is no
 * registered MemoryBank or some other error, an exception  is throw.
 * All setValue methods utilize this method to read the bytes from the
 * appropriate memory bank. 
 * @param val the byte values to be written into the MemoryState
 * @param spc the address space being written
 * @param off the starting offset of the range being written
 * @param size the number of bytes to write
 * @throws LowlevelError if spc has not been mapped within this MemoryState
 */
public void setChunk(byte[] val, AddressSpace spc, long off, int size) {
	MemoryBank mspace = getMemoryBank(spc);
	if (mspace == null)
		throw new LowlevelError("Setting chunk of unmapped memory space: " + spc.getName());
	mspace.setChunk(off, size, val);
}
 
Example 7
Source File: MemoryState.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * This is the main interface for setting the initialization status for a range of bytes
 * in the MemoryState.
 * The MemoryBank associated with the desired address space is looked up and the
 * write is forwarded to the setInitialized method on the MemoryBank. If there is no
 * registered MemoryBank or some other error, an exception  is throw.
 * All setValue methods utilize this method to read the bytes from the
 * appropriate memory bank. 
 * @param initialized indicates if range should be marked as initialized or not
 * @param spc the address space being written
 * @param off the starting offset of the range being written
 * @param size the number of bytes to write
 */
public void setInitialized(boolean initialized, AddressSpace spc, long off, int size) {
	MemoryBank mspace = getMemoryBank(spc);
	if (mspace == null)
		throw new LowlevelError("Setting intialization status of unmapped memory space: " +
			spc.getName());
	mspace.setInitialized(off, size, initialized);
}