Java Code Examples for ghidra.program.model.listing.CodeUnit#getProgram()

The following examples show how to use ghidra.program.model.listing.CodeUnit#getProgram() . 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: CommentHistoryDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void showDialog(CodeUnit cu, int commentType, PluginTool tool, ActionContext context) {
	codeUnit = cu;
	program = cu.getProgram();
	CommentHistoryPanel panel = getHistoryPanel(commentType);
	panel.showCommentHistory(program, cu.getMinAddress());
	tabbedPane.removeChangeListener(this);
	
	for (int i=0;i<COMMENT_INDEXES.length; i++) {
		if (COMMENT_INDEXES[i] == commentType) {
			tabbedPane.setSelectedIndex(i);
			break;
		}
	}
	tabbedPane.addChangeListener(this);
       tool.showDialog( this, context.getComponentProvider() );
}
 
Example 2
Source File: MemoryBlockStartFieldFactory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Overridden to ensure that we return a {@link MemoryBlockStartFieldLocation} instance.
 * 
 * @see ghidra.app.util.viewer.field.FieldFactory#getProgramLocation(int, int, ghidra.app.util.viewer.field.ListingField)
 */
@Override
public ProgramLocation getProgramLocation(int row, int col, ListingField bf) {

	Object proxyObject = bf.getProxy().getObject();
	if (!(proxyObject instanceof CodeUnit)) {
		return null;
	}
	CodeUnit cu = (CodeUnit) proxyObject;

	String[] comments;
	List<AttributedString> attributedStrings = createBlockStartText(cu);
	if (attributedStrings == null) {
		comments = new String[0];
	}
	else {
		comments = new String[attributedStrings.size()];
		for (int i = 0; i < comments.length; i++) {
			comments[i] = attributedStrings.get(i).getText();
		}
	}

	return new MemoryBlockStartFieldLocation(cu.getProgram(), cu.getMinAddress(), null, row,
		col, comments, 0);
}
 
Example 3
Source File: SpaceFieldFactory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * @see ghidra.app.util.viewer.field.FieldFactory#getProgramLocation(int, int, ghidra.app.util.viewer.field.ListingField)
 */
@Override
public ProgramLocation getProgramLocation(int row, int col, ListingField bf) {
	Object obj = bf.getProxy().getObject();
	if (!(obj instanceof CodeUnit)) {
		return null;
	}
	CodeUnit cu = (CodeUnit) obj;

	int[] cpath = null;
	if (obj instanceof Data) {
		cpath = ((Data) obj).getComponentPath();
	}

	return new SpaceFieldLocation(cu.getProgram(), cu.getMinAddress(), null, cpath, row);
}
 
Example 4
Source File: AddressFieldFactory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public ProgramLocation getProgramLocation(int row, int col, ListingField lf) {
	Object obj = lf.getProxy().getObject();
	if (!(obj instanceof CodeUnit)) {
		return null;
	}
	CodeUnit cu = (CodeUnit) obj;

	Address addr = cu.getMinAddress();

	int[] cpath = null;
	if (cu instanceof Data) {
		cpath = ((Data) cu).getComponentPath();
	}

	return new AddressFieldLocation(cu.getProgram(), addr, cpath, addr.toString(), col);
}
 
Example 5
Source File: SpacerFieldFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public ProgramLocation getProgramLocation(int row, int col, ListingField bf) {
	Object obj = bf.getProxy().getObject();
	if (!(obj instanceof CodeUnit)) {
		return null;
	}
	CodeUnit cu = (CodeUnit) obj;

	int[] cpath = null;
	if (obj instanceof Data) {
		cpath = ((Data) obj).getComponentPath();
	}

	return new SpacerFieldLocation(cu.getProgram(), cu.getMinAddress(), cpath, col, text);
}
 
Example 6
Source File: ExternalDisassemblyFieldFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public ProgramLocation getProgramLocation(int row, int col, ListingField bf) {
	ProxyObj<?> proxy = bf.getProxy();
	Object obj = proxy.getObject();
	if (!(obj instanceof CodeUnit)) {
		return null;
	}
	CodeUnit cu = (CodeUnit) obj;

	return new ExternalDisassemblyFieldLocation(cu.getProgram(), cu.getMinAddress(), row, col);
}
 
Example 7
Source File: EditReferenceDialog.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void setAddOpIndex(int opIndex, int subIndex) {

		CodeUnit cu = instrPanel.getCurrentCodeUnit();
		Program p = cu.getProgram();
		boolean inFunction =
			(p.getFunctionManager().getFunctionContaining(cu.getMinAddress()) != null);
		Reference[] refs = p.getReferenceManager().getReferencesFrom(cu.getMinAddress(), opIndex);
		Address existingRefAddr = refs.length != 0 ? refs[0].getToAddress() : null;

		if (!memRefPanel.initialize(cu, opIndex, subIndex)) {
			throw new AssertException("Memory reference must always be permitted");
		}

		memRefChoice.setEnabled(true);
		extRefChoice.setEnabled(extRefPanel.initialize(cu, opIndex, subIndex));
		stackRefChoice.setEnabled(inFunction && stackRefPanel.initialize(cu, opIndex, subIndex));
		regRefChoice.setEnabled(inFunction && regRefPanel.initialize(cu, opIndex, subIndex));

		memRefChoice.setSelected(true);
		if (existingRefAddr != null) {
			if (existingRefAddr.isStackAddress()) {
				if (stackRefChoice.isEnabled()) {
					stackRefChoice.setSelected(true);
				}
			}
			else if (existingRefAddr.isRegisterAddress()) {
				if (regRefChoice.isEnabled()) {
					regRefChoice.setSelected(true);
				}
			}
			else if (existingRefAddr.isExternalAddress()) {
				if (extRefChoice.isEnabled()) {
					extRefChoice.setSelected(true);
				}
			}
		}
		else {
			if (stackRefChoice.isEnabled() && stackRefPanel.isValidStackRef()) {
				stackRefChoice.setSelected(true);
			}
			else if (regRefChoice.isEnabled()) {
				regRefChoice.setSelected(true);
			}
		}
	}