Java Code Examples for ghidra.program.model.listing.Instruction#getPrototype()

The following examples show how to use ghidra.program.model.listing.Instruction#getPrototype() . 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: InstructionStasher.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void clearAndSave() {
	Instruction instruction = program.getListing().getInstructionContaining(address);
	if (instruction == null) {
		return;
	}
	minAddress = instruction.getMinAddress();
	prototype = instruction.getPrototype();
	referencesFrom = instruction.getReferencesFrom();
	program.getListing().clearCodeUnits(minAddress, instruction.getMaxAddress(), false);
}
 
Example 2
Source File: ScalarOperandListingHover.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Object getOperand(OperandFieldLocation loc, Instruction instruction) {
	int opIndex = loc.getOperandIndex();
	Object[] operands = instruction.getOpObjects(opIndex);
	if (operands.length == 1) {
		return operands[0];
	}

	InstructionPrototype prototype = instruction.getPrototype();
	List<Object> list =
		prototype.getOpRepresentationList(opIndex, instruction.getInstructionContext());
	if (list == null) {
		return null;
	}
	return list.get(loc.getSubOperandIndex());
}
 
Example 3
Source File: InstructionMaskValueFieldFactory.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the FactoryField for the given object at index index.
 * @param varWidth the amount of variable width spacing for any fields
 * before this one.
 * @param proxy the object whose properties should be displayed.
 */
@Override
public ListingField getField(ProxyObj<?> proxy, int varWidth) {
	Object obj = proxy.getObject();

	if (!enabled || !(obj instanceof Instruction)) {
		return null;
	}
	Instruction instr = (Instruction) obj;
	InstructionPrototype proto = instr.getPrototype();
	int operandCount = proto.getNumOperands();
	Mask instructionMask = proto.getInstructionMask();
	if (instructionMask == null) {
		return null;
	}
	Mask[] operandMasks = new Mask[operandCount];
	for (int i = 0; i < operandCount; i++) {
		operandMasks[i] = proto.getOperandValueMask(i);
		if (operandMasks[i] == null) {
			// disable operand mask display
			operandCount = 0;
			break;
		}
	}

	try {
		FieldElement[] fieldElements = new FieldElement[2 * (operandCount + 1)];
		fieldElements[0] =
			getLine("M[m]: ", instructionMask.getBytes(), MASK_COLOR, proxy, varWidth);
		fieldElements[1] =
			getLine("V[m]: ", instructionMask.applyMask(instr), VALUE_COLOR, proxy, varWidth);
		for (int i = 0; i < operandCount; i++) {
			fieldElements[2 * (i + 1)] = getLine("M[" + i + "]: ", operandMasks[i].getBytes(),
				MASK_COLOR, proxy, varWidth);
			fieldElements[2 * (i + 1) + 1] = getLine("V[" + i + "]: ",
				operandMasks[i].applyMask(instr), VALUE_COLOR, proxy, varWidth);
		}

		return ListingTextField.createMultilineTextField(this, proxy, fieldElements,
			startX + varWidth, width, fieldElements.length, hlProvider);
	}
	catch (MemoryAccessException e) {
		return null;
	}
}