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

The following examples show how to use ghidra.framework.plugintool.PluginTool#executeBackgroundCommand() . 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: CaptureFunctionDataTypesAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	GTree gTree = (GTree) context.getContextObject();
	TreePath selectionPath = gTree.getSelectionPath();
	ArchiveNode node = (ArchiveNode) selectionPath.getLastPathComponent();
	if (!node.getArchive().isModifiable()) {
		informNotModifiable(node);
		return;
	}

	Program program = plugin.getProgram();
	AddressSetView currentSelection = plugin.getCurrentSelection();
	if (currentSelection == null || currentSelection.isEmpty()) {
		currentSelection = program.getMemory();
	}
	final DataTypeManager manager = node.getArchive().getDataTypeManager();
	final PluginTool tool = plugin.getTool();
	CaptureFunctionDataTypesCmd cmd =
		new CaptureFunctionDataTypesCmd(manager, currentSelection,
			new CaptureFunctionDataTypesListener() {

				@Override
				public void captureFunctionDataTypesCompleted(
						CaptureFunctionDataTypesCmd command) {
					tool.setStatusInfo("Captured function data types to \"" +
						manager.getName() + "\".");
				}
			});
	tool.executeBackgroundCommand(cmd, program);
}
 
Example 2
Source File: ApplyFunctionDataTypesAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	GTree gTree = (GTree) context.getContextObject();
	TreePath selectionPath = gTree.getSelectionPath();
	ArchiveNode node = (ArchiveNode) selectionPath.getLastPathComponent();

	Program program = plugin.getProgram();
	DataTypeManager manager = node.getArchive().getDataTypeManager();
	List<DataTypeManager> managerList = new ArrayList<DataTypeManager>();
	managerList.add(manager);
	ApplyFunctionDataTypesCmd cmd =
		new ApplyFunctionDataTypesCmd(managerList, null, SourceType.USER_DEFINED, true, true);
	PluginTool tool = plugin.getTool();
	tool.executeBackgroundCommand(cmd, program);
}
 
Example 3
Source File: CloseToolTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCannotCloseToolWithBackgroundTaskRunning() throws Exception {
	// open a program
	ProgramDB program = new ProgramBuilder("notepad", ProgramBuilder._TOY).getProgram();

	// launch a tool with the program
	PluginTool tool = env.launchDefaultTool(program);

	// start a background task that will run until we tell it to finish.
	ControllableBackgroundCommand cmd = new ControllableBackgroundCommand();
	tool.executeBackgroundCommand(cmd, program);
	waitForCommandToStart(cmd);

	// try to close the tool
	closeTool(tool);

	// check for warning dialog
	Window window = waitForWindow("Tool Busy");
	assertNotNull("Did not get tool busy dialog", window);
	closeWindow(window);

	// try to close the program
	closeProgram(tool, program);

	// check for warning dialog
	window = waitForWindow("Close notepad Failed");
	assertNotNull("Did not get \"close failed\" dialog", window);
	closeWindow(window);

	// stop background task
	stopBackgroundCommand(tool, cmd);

	// close tool
	assertNotNull(tool.getToolFrame());
	closeTool(tool);
	assertNull("Tool did not close after task", tool.getToolFrame());
}