Java Code Examples for ghidra.framework.plugintool.PluginTool#showDialog()

The following examples show how to use ghidra.framework.plugintool.PluginTool#showDialog() . 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: FindDataTypesAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {

	InputDialog inputDialog =
		new InputDialog("Find Data Types", "Please enter the search string: ");
	PluginTool tool = plugin.getTool();
	tool.showDialog(inputDialog);

	if (inputDialog.isCanceled()) {
		return;
	}

	final String searchString = inputDialog.getValue();
	String title = "Find Data Type";
	final DataTypesProvider newProvider = plugin.createProvider();
	newProvider.setIncludeDataTypeMembersInFilter(plugin.includeDataMembersInSearch());
	newProvider.setTitle(title);
	newProvider.setFilterText(searchString);
	newProvider.setVisible(true);
}
 
Example 2
Source File: TagFilterEditorDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, VTMatchTag> getExcludedTags(Map<String, VTMatchTag> allTagsMap,
		Map<String, VTMatchTag> currentExcludedTagsMap) {
	this.allTags = allTagsMap;
	this.excludedTags = currentExcludedTagsMap;

	rebuild();

	PluginTool tool = controller.getTool();
	tool.showDialog(this);

	int size = listModel.getSize();
	Map<String, VTMatchTag> newExcludedTags = new TreeMap<>();
	for (int i = 0; i < size; i++) {
		TagInfo info = (TagInfo) listModel.get(i);
		if (!info.isIncluded()) {
			VTMatchTag tag = info.getTag();
			newExcludedTags.put(tag.getName(), tag);
		}
	}
	return newExcludedTags;
}
 
Example 3
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 4
Source File: EditPluginPathDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Reset the list of paths each time the dialog is shown
 * @param tool the tool
 */
public void show(PluginTool tool) {
	setPluginPathsListData(Preferences.getPluginPaths());
	setApplyEnabled(pluginPathsChanged);
	setStatusMessage(EMPTY_STATUS);

	// setting the path enables the apply, but we know we haven't
	// made any changes yet, so disable
	setApplyEnabled(false);
	tool.showDialog(this);
}
 
Example 5
Source File: OffsetTableDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Displays the dialog for specifying the information for offset table references.
 * @throws CancelledException if the user cancels the dialog.
 */
void showDialog(PluginTool tool) throws CancelledException {
	canceled = false;
	tool.showDialog(this);
	if (canceled) {
		throw new CancelledException();
	}
}
 
Example 6
Source File: MemSearchDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
void show(ComponentProvider provider) {
	clearStatusText();
	valueField.requestFocus();
	valueField.selectAll();
	PluginTool tool = plugin.getTool();
	tool.showDialog(MemSearchDialog.this, provider);
}
 
Example 7
Source File: ScalarSearchDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public void show() {
	clearStatusText();
	exactValueField.requestFocus();
	exactValueField.selectAll();
	PluginTool tool = plugin.getTool();
	tool.showDialog(ScalarSearchDialog.this, provider);
}
 
Example 8
Source File: ChooseDataTypeAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private DataType getDataType(ListingActionContext context, int maxElements,
		int defaultPointerSize) {
	PluginTool tool = plugin.getTool();
	Data data = plugin.getDataUnit(context);
	DataTypeSelectionDialog selectionDialog = new DataTypeSelectionDialog(tool,
		data.getProgram().getDataTypeManager(), maxElements, AllowedDataTypes.ALL);
	DataType currentDataType = data.getBaseDataType();
	selectionDialog.setInitialDataType(currentDataType);
	tool.showDialog(selectionDialog);
	return selectionDialog.getUserChosenDataType();
}
 
Example 9
Source File: InstructionSearchApi.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Opens the search dialog and populates it with instructions represented by the
 * bytes given. A program must be loaded in Ghidra for this to work, as determining the 
 * instructions would be impossible otherwise. 
 * 
 * @param bytes binary or hex string representing the bytes to be loaded
 */
public void loadInstructions(String bytes, PluginTool tool) {

	InstructionSearchDialog searchDialog = new InstructionSearchDialog(
		InstructionSearchUtils.getInstructionSearchPlugin(tool), "Search Dialog", null);
	tool.showDialog(searchDialog);
	searchDialog.loadBytes(bytes);
}
 
Example 10
Source File: ChooseDataTypeAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private DataTypeSelectionDialog showSelectionDialog(ListingActionContext context,
		int maxStorageSize, PluginTool tool, DataTypeManager dataTypeManager) {
	DataTypeSelectionDialog selectionDialog = new DataTypeSelectionDialog(tool, dataTypeManager,
		maxStorageSize, AllowedDataTypes.FIXED_LENGTH);
	DataType currentDataType = plugin.getCurrentDataType(context);
	selectionDialog.setInitialDataType(currentDataType);
	tool.showDialog(selectionDialog);
	return selectionDialog;
}
 
Example 11
Source File: AbstractDecompilerAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public DataType chooseDataType(PluginTool tool, Program program, DataType currentDataType) {
	DataTypeManager dataTypeManager = program.getDataTypeManager();
	DataTypeSelectionDialog chooserDialog = new DataTypeSelectionDialog(tool, dataTypeManager,
		Integer.MAX_VALUE, AllowedDataTypes.FIXED_LENGTH);
	chooserDialog.setInitialDataType(currentDataType);
	tool.showDialog(chooserDialog);
	return chooserDialog.getUserChosenDataType();
}
 
Example 12
Source File: SpecifyCPrototypeAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void decompilerActionPerformed(DecompilerActionContext context) {
	Function function =
		getFunction(context.getFunction(), context.getTokenAtCursor());
	PluginTool tool = context.getTool();
	DataTypeManagerService service = tool.getService(DataTypeManagerService.class);

	FunctionEditorModel model = new FunctionEditorModel(service, function);

	HighFunction hf = context.getHighFunction();
	FunctionPrototype functionPrototype = hf.getFunctionPrototype();

	// If editing the decompiled function (i.e., not a subfunction) and function
	// is not fully locked update the model to reflect the decompiled results
	if (function.getEntryPoint().equals(hf.getFunction().getEntryPoint())) {
		if (function.getSignatureSource() == SourceType.DEFAULT) {
			model.setUseCustomizeStorage(false);
			model.setCallingConventionName(functionPrototype.getModelName());
			model.setFunctionData(buildSignature(hf));
			verifyDynamicEditorModel(hf, model);
		}
		else if (function.getReturnType() == DataType.DEFAULT) {
			model.setFormalReturnType(functionPrototype.getReturnType());
			if (model.canCustomizeStorage()) {
				model.setReturnStorage(functionPrototype.getReturnStorage());
			}
		}
	}

	// make the model think it is not changed, so if the user doesn't change anything, 
	// we don't save the changes made above.
	model.setModelChanged(false);

	FunctionEditorDialog dialog = new FunctionEditorDialog(model);
	tool.showDialog(dialog, context.getComponentProvider());
}
 
Example 13
Source File: ChooseDataTypeScript.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() throws Exception {

	PluginTool tool = state.getTool();
	DataTypeManager dtm = currentProgram.getDataTypeManager();
	DataTypeSelectionDialog selectionDialog =
		new DataTypeSelectionDialog(tool, dtm, -1, AllowedDataTypes.FIXED_LENGTH);
	tool.showDialog(selectionDialog);
	DataType dataType = selectionDialog.getUserChosenDataType();

	if (dataType != null) {
		println("Chosen data type: " + dataType);
	}
}
 
Example 14
Source File: AboutDomainObjectUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Displays an informational dialog about the specified domain object
 *
 * @param tool			 plugin tool
 * @param domainFile     domain file to display information about
 * @param metadata		 the metadata for the domainFile
 * @param title          title to use for the dialog
 * @param additionalInfo additional custom user information to append to
 *                       the bottom of the dialog
 * @param helpLocation	 the help location
 */
public static void displayInformation(PluginTool tool, DomainFile domainFile,
		Map<String, String> metadata, String title, String additionalInfo,
		HelpLocation helpLocation) {
	JComponent aboutComp = getAboutPanel(domainFile, metadata, additionalInfo);
	if (aboutComp == null) {
		return;
	}
	Dialog dialog = new Dialog(title, aboutComp);
	if (helpLocation != null) {
		dialog.setHelpLocation(helpLocation);
	}
	tool.showDialog(dialog);
}
 
Example 15
Source File: InstructionSearchDialog.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Displays this dialog.
 *
 * @param provider the component provider
 */
public void showDialog(ComponentProvider provider) {
	clearStatusText();
	PluginTool tool = plugin.getTool();
	tool.showDialog(InstructionSearchDialog.this, provider);
}
 
Example 16
Source File: OverridePrototypeAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected void decompilerActionPerformed(DecompilerActionContext context) {
	Function func = context.getFunction();
	Program program = func.getProgram();
	PcodeOp op = getCallOp(program, context.getTokenAtCursor());
	Function calledfunc = getCalledFunction(program, op);
	boolean varargs = false;
	if (calledfunc != null) {
		varargs = calledfunc.hasVarArgs();
	}
	if ((op.getOpcode() == PcodeOp.CALL) && !varargs) {
		if (OptionDialog.showOptionDialog(context.getDecompilerPanel(),
			"Warning : Localized Override",
			"Incorrect information entered here may hide other good information.\n" +
				"For direct calls, it is usually better to alter the prototype on the function\n" +
				"itself, rather than overriding the local call. Proceed anyway?",
			"Proceed") != 1) {
			return;
		}
	}
	Address addr = op.getSeqnum().getTarget();
	String name = "func"; // Default if we don't have a real name
	String conv = program.getCompilerSpec().getDefaultCallingConvention().getName();
	if (calledfunc != null) {
		name = calledfunc.getName();
		conv = calledfunc.getCallingConventionName();
	}

	String signature = generateSignature(op, name);
	PluginTool tool = context.getTool();
	ProtoOverrideDialog dialog = new ProtoOverrideDialog(tool, func, signature, conv);
	//     dialog.setHelpLocation( new HelpLocation( getOwner(), "Edit_Function_Signature" ) );
	tool.showDialog(dialog);
	FunctionDefinition fdef = dialog.getFunctionDefinition();
	if (fdef == null) {
		return;
	}
	int transaction = program.startTransaction("Override Signature");
	boolean commit = false;
	try {
		HighFunctionDBUtil.writeOverride(func, addr, fdef);
		commit = true;
	}
	catch (Exception e) {
		Msg.showError(getClass(), context.getDecompilerPanel(), "Override Signature Failed",
			"Error overriding signature: " + e);
	}
	finally {
		program.endTransaction(transaction, commit);
	}
}
 
Example 17
Source File: DataTypeEditorManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void editFunctionSignature(final Category category,
		final FunctionDefinition functionDefinition) {

	Function function =
		new UndefinedFunction(plugin.getProgram(), plugin.getProgram().getMinAddress()) {
			@Override
			public String getCallingConventionName() {
				if (functionDefinition == null) {
					return super.getCallingConventionName();
				}
				return functionDefinition.getGenericCallingConvention().toString();
			}

			@Override
			public void setCallingConvention(String name) throws InvalidInputException {
				// no-op; we handle this in the editor dialog
			}

			@Override
			public void setInline(boolean isInline) {
				// can't edit this from the DataTypeManager
			}

			@Override
			public void setNoReturn(boolean hasNoReturn) {
				// can't edit this from the DataTypeManager
			}

			@Override
			public FunctionSignature getSignature() {
				if (functionDefinition != null) {
					return functionDefinition;
				}
				return super.getSignature();
			}

			@Override
			public String getName() {
				if (functionDefinition != null) {
					return functionDefinition.getName();
				}
				return "newFunction";
			}
		};

	// DT how do I do the same as the other creates.
	PluginTool tool = plugin.getTool();
	DTMEditFunctionSignatureDialog editSigDialog = new DTMEditFunctionSignatureDialog(
		plugin.getTool(), "Edit Function Signature", function, category, functionDefinition);
	editSigDialog.setHelpLocation(
		new HelpLocation("DataTypeManagerPlugin", "Function_Definition"));
	tool.showDialog(editSigDialog);
}
 
Example 18
Source File: CreateEnumFromSelectionAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {

	//Get the selected enums 
	final GTree gTree = (GTree) context.getContextObject();
	TreePath[] paths = gTree.getSelectionPaths();
	Enum[] enumArray = new Enum[paths.length];
	int i = 0;

	for (TreePath element : paths) {
		GTreeNode node = (GTreeNode) element.getLastPathComponent();
		DataTypeNode dataTypeNode = (DataTypeNode) node;
		enumArray[i++] = (Enum) dataTypeNode.getDataType();
	}
	Category category = null;
	DataTypeManager[] dataTypeManagers = plugin.getDataTypeManagers();
	DataTypeManager myDataTypeManager = null;
	for (DataTypeManager dataTypeManager : dataTypeManagers) {
		if (dataTypeManager instanceof ProgramDataTypeManager) {
			myDataTypeManager = dataTypeManager;
			category = myDataTypeManager.getCategory(new CategoryPath("/"));
			if (category == null) {
				Msg.error(this, "Could not find program data type manager");
				return;
			}

		}
	}

	String newName = "";
	PluginTool tool = plugin.getTool();

	while (newName.equals("")) {
		InputDialog inputDialog =
			new InputDialog("Name new ENUM", "Please enter a name for the new ENUM: ");
		tool = plugin.getTool();
		tool.showDialog(inputDialog);

		if (inputDialog.isCanceled()) {
			return;
		}
		newName = inputDialog.getValue();
	}

	DataType dt = myDataTypeManager.getDataType(category.getCategoryPath(), newName);
	while (dt != null) {
		InputDialog dupInputDialog =
			new InputDialog("Duplicate ENUM Name",
				"Please enter a unique name for the new ENUM: ");
		tool = plugin.getTool();
		tool.showDialog(dupInputDialog);

		if (dupInputDialog.isCanceled()) {
			return;
		}
		newName = dupInputDialog.getValue();
		dt = myDataTypeManager.getDataType(category.getCategoryPath(), newName);
	}
	createNewEnum(category, enumArray, newName);

	// select new node in tree.  Must use invoke later to give the tree a chance to add the
	// the new node to the tree.
	myDataTypeManager.flushEvents();
	final String parentNodeName = myDataTypeManager.getName();
	final String newNodeName = newName;
	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			GTreeNode rootNode = gTree.getViewRoot();
			gTree.setSelectedNodeByNamePath(new String[] { rootNode.getName(), parentNodeName,
				newNodeName });
		}
	});
}
 
Example 19
Source File: VersionControlDialog.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Show the dialog; return an ID for the action that the user chose.
 * @param parent parent to this dialog
 * @return OK, APPLY_TO_ALL, or CANCEL
 */
int showDialog(PluginTool tool, Component parent) {
	tool.showDialog(this, parent);
	return actionID;
}
 
Example 20
Source File: CheckoutDialog.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Show the dialog; return an ID for the action that the user chose.
 * 
 * @param tool the tool used to show the dialog
 * @return OK, or CANCEL
 */
public int showDialog(PluginTool tool) {
	exclusiveCB.setSelected(false);
	tool.showDialog(this);
	return actionID;
}