ghidra.app.plugin.core.colorizer.ColorizingService Java Examples

The following examples show how to use ghidra.app.plugin.core.colorizer.ColorizingService. 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: GhidraScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Clears the background of the Listing at the given addresses to the given color.  See the
 * Listing help page in Ghidra help for more information.
 * <p>
 * This method is unavailable in headless mode.
 * <p>
 * Note: you can use the {@link ColorizingService} directly to access more color changing
 * functionality.  See the source code of this method to learn how to access services from
 * a script.
 *
 * @param addresses The address at which to clear the color
 * @see #setBackgroundColor(AddressSetView, Color)
 * @see #clearBackgroundColor(AddressSetView)
 * @see ColorizingService
 * @throws ImproperUseException if this method is run in headless mode
 */
public void clearBackgroundColor(AddressSetView addresses) throws ImproperUseException {

	if (isRunningHeadless()) {
		throw new ImproperUseException(
			"The clearBackgroundColor() method can only be used when running headed Ghidra.");
	}

	PluginTool tool = state.getTool();
	ColorizingService service = tool.getService(ColorizingService.class);
	if (service == null) {
		printerr("Cannot clear background colors without the " +
			ColorizingService.class.getSimpleName() + " installed");
		return;
	}

	service.clearBackgroundColor(addresses);
}
 
Example #2
Source File: GhidraScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Clears the background of the Listing at the given address to the given color.  See the
 * Listing help page in Ghidra help for more information.
 * <p>
 * This method is unavailable in headless mode.
 * <p>
 * Note: you can use the {@link ColorizingService} directly to access more color changing
 * functionality.  See the source code of this method to learn how to access services from
 * a script.
 *
 * @param address The address at which to clear the color
 * @see #setBackgroundColor(AddressSetView, Color)
 * @see #clearBackgroundColor(AddressSetView)
 * @see ColorizingService
 * @throws ImproperUseException if this method is run in headless mode
 */
public void clearBackgroundColor(Address address) throws ImproperUseException {

	if (isRunningHeadless()) {
		throw new ImproperUseException(
			"The clearBackgroundColor() method can only be used when running headed Ghidra.");
	}

	PluginTool tool = state.getTool();
	ColorizingService service = tool.getService(ColorizingService.class);
	if (service == null) {
		printerr("Cannot clear background colors without the " +
			ColorizingService.class.getSimpleName() + " installed");
		return;
	}

	service.clearBackgroundColor(address, address);
}
 
Example #3
Source File: GhidraScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the background of the Listing at the given addresses to the given color.  See the
 * Listing help page in Ghidra help for more information.
 * <p>
 * This method is unavailable in headless mode.
 * <p>
 * Note: you can use the {@link ColorizingService} directly to access more color changing
 * functionality.  See the source code of this method to learn how to access services from
 * a script.
 *
 * @param addresses The addresses at which to set the color
 * @param color The color to set
 * @see #setBackgroundColor(Address, Color)
 * @see #clearBackgroundColor(AddressSetView)
 * @see ColorizingService
 * @throws ImproperUseException if this method is run in headless mode
 */
public void setBackgroundColor(AddressSetView addresses, Color color)
		throws ImproperUseException {

	if (isRunningHeadless()) {
		throw new ImproperUseException(
			"The setBackgroundColor() method can only be used when running headed Ghidra.");
	}

	PluginTool tool = state.getTool();
	ColorizingService service = tool.getService(ColorizingService.class);
	if (service == null) {
		printerr("Cannot set background colors without the " +
			ColorizingService.class.getSimpleName() + " installed");
		return;
	}

	service.setBackgroundColor(addresses, color);
}
 
Example #4
Source File: BlockGraphTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public BlockGraphTask(String actionName, boolean graphEntryPointNexus, boolean showCode,
		boolean reuseGraph,
		boolean appendGraph, PluginTool tool, ProgramSelection selection,
		CodeBlockModel blockModel, GraphDisplayProvider graphService) {
	super("Graph Program", true, false, true);
	this.actionName = actionName;

	this.graphEntryPointNexus = graphEntryPointNexus;
	this.showCode = showCode;
	this.reuseGraph = reuseGraph;
	this.appendGraph = appendGraph;
	this.tool = tool;
	this.blockModel = blockModel;
	this.graphService = graphService;
	this.colorizingService = tool.getService(ColorizingService.class);
	this.selection = selection;
	this.program = blockModel.getProgram();
}
 
Example #5
Source File: GhidraScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the background of the Listing at the given address to the given color.  See the
 * Listing help page in Ghidra help for more information.
 * <p>
 * This method is unavailable in headless mode.
 * <p>
 * Note: you can use the {@link ColorizingService} directly to access more color changing
 * functionality.  See the source code of this method to learn how to access services from
 * a script.
 *
 * @param address The address at which to set the color
 * @param color The color to set
 * @see #setBackgroundColor(AddressSetView, Color)
 * @see #clearBackgroundColor(Address)
 * @see ColorizingService
 * @throws ImproperUseException if this method is run in headless mode
 */
public void setBackgroundColor(Address address, Color color) throws ImproperUseException {

	if (isRunningHeadless()) {
		throw new ImproperUseException(
			"The setBackgroundColor() method can only be used when running headed Ghidra.");
	}

	PluginTool tool = state.getTool();
	ColorizingService service = tool.getService(ColorizingService.class);
	if (service == null) {
		printerr("Cannot set background colors without the " +
			ColorizingService.class.getSimpleName() + " installed");
		return;
	}

	service.setBackgroundColor(address, address, color);
}
 
Example #6
Source File: FunctionGraphPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void serviceRemoved(Class<?> interfaceClass, Object service) {
	if (interfaceClass == ClipboardService.class) {
		connectedProvider.setClipboardService((ClipboardService) service);
		for (FGProvider disconnectedProvider : disconnectedProviders) {
			disconnectedProvider.setClipboardService((ClipboardService) service);
		}
	}
	else if (interfaceClass == ColorizingService.class) {
		colorProvider = new IndependentColorProvider(tool);
		connectedProvider.refreshAndKeepPerspective();
	}
}
 
Example #7
Source File: ExampleColorScript.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	ColorizingService service = state.getTool().getService(ColorizingService.class);
	if (service == null) {
		println("Can't find ColorizingService service");
		return;
	}

	if (currentSelection != null) {
		service.setBackgroundColor(currentSelection, new Color(255, 200, 200));
	}
	else if (currentAddress != null) {
		service.setBackgroundColor(currentAddress, currentAddress, new Color(255, 200, 200));
	}
	else {
		println("No selection or current address to color");
		return;
	}

	Address anotherAddress = currentAddress.add(10);
	setBackgroundColor(anotherAddress, Color.YELLOW);

	// create an address set with values you want to change
	AddressSet addresses = new AddressSet();
	addresses.add(currentAddress.add(10));
	addresses.add(currentAddress.add(11));
	addresses.add(currentAddress.add(12));

	setBackgroundColor(addresses, new Color(100, 100, 200));
}
 
Example #8
Source File: FunctionGraphPlugin2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetMostRecentColorAction() throws Exception {
	//
	// Test that the 'set most recent color' action will set the color of the vertex *and* 
	// in the Listing.
	//
	// install ColorizerPlugin
	tool.addPlugin(ColorizingPlugin.class.getName());

	FGVertex focusedVertex = getFocusedVertex();
	ColorizingService colorizingService = tool.getService(ColorizingService.class);
	Color startBackgroundColor =
		colorizingService.getBackgroundColor(focusedVertex.getVertexAddress());

	FGController controller = getFunctionGraphController();
	Color mostRecentColor = controller.getMostRecentColor();

	Assert.assertNotEquals(
		"Test environment not setup correctly--should have default backgrond " +
			"colors applied",
		startBackgroundColor, mostRecentColor);

	SetVertexMostRecentColorAction setRecentColorAction =
		getSetMostRecentColorAction(focusedVertex);
	performAction(setRecentColorAction, graphProvider, true);

	Color newVertexBackgroundColor = focusedVertex.getBackgroundColor();
	assertEquals("'Set Most Recent Color' action did not apply that color to the vertex",
		mostRecentColor, newVertexBackgroundColor);

	Color newBackgroundColor =
		colorizingService.getBackgroundColor(focusedVertex.getVertexAddress());
	assertEquals("'Set Most Recent Color' action did not apply that color to the color service",
		mostRecentColor, newBackgroundColor);
}
 
Example #9
Source File: FunctionGraphPlugin2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSharedColorExperience() throws Exception {
	//
	// Tests the new way of coloring vertices, by way of the ColorizerService, which will
	// set the color in both the vertex and the listing (really just in the listing, but 
	// the vertex displays this color.
	//

	// install ColorizerPlugin
	tool.addPlugin(ColorizingPlugin.class.getName());

	FGVertex vertex = getFocusedVertex();
	ColorizingService colorizingService = tool.getService(ColorizingService.class);
	Color appliedBackgroundColor =
		colorizingService.getBackgroundColor(vertex.getVertexAddress());

	Color testColor = Color.RED;
	assertTrue("Unexpected start color--must change the test!",
		!testColor.equals(appliedBackgroundColor));

	chooseColor(vertex, testColor);

	// make sure the service is also cognizant of the color change
	appliedBackgroundColor = colorizingService.getBackgroundColor(vertex.getVertexAddress());
	assertEquals(testColor, appliedBackgroundColor);

	Color vBg = vertex.getBackgroundColor();
	assertEquals(appliedBackgroundColor, vBg);

	// 
	// Reload and make sure the color is re-applied to the vertex (this was broken)
	//
	Address vertexAddress = vertex.getVertexAddress();
	performReload();
	FGVertex reloadedVertex = vertex(vertexAddress);
	assertNotSame(vertex, reloadedVertex);
	vBg = reloadedVertex.getBackgroundColor();
	assertEquals(appliedBackgroundColor, vBg);
}
 
Example #10
Source File: FunctionGraphPlugin1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearColorAction() throws Exception {
	tool.addPlugin(ColorizingPlugin.class.getName());

	FGVertex focusedVertex = getFocusedVertex();
	ColorizingService colorizingService = tool.getService(ColorizingService.class);
	Color appliedBackgroundColor =
		colorizingService.getBackgroundColor(focusedVertex.getVertexAddress());

	Color testColor = Color.RED;
	assertTrue("Unexpected start color--must change the test!",
		!testColor.equals(appliedBackgroundColor));

	chooseColor(focusedVertex, testColor);

	Color newVertexBackgroundColor = focusedVertex.getUserDefinedColor();
	assertEquals("Background color not set", testColor, newVertexBackgroundColor);

	DockingAction clearColorAction = getClearColorAction(focusedVertex);
	performAction(clearColorAction, graphProvider, true);

	Color userDefinedColor = focusedVertex.getUserDefinedColor();
	assertNull(userDefinedColor);

	Color serviceBackgroundColor =
		colorizingService.getBackgroundColor(focusedVertex.getVertexAddress());
	assertNull("Clear action did not clear the service's applied color",
		serviceBackgroundColor);
}
 
Example #11
Source File: FunctionGraphPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void serviceAdded(Class<?> interfaceClass, Object service) {
	if (interfaceClass == ClipboardService.class) {
		connectedProvider.setClipboardService((ClipboardService) service);
		for (FGProvider disconnectedProvider : disconnectedProviders) {
			disconnectedProvider.setClipboardService((ClipboardService) service);
		}
	}
	else if (interfaceClass == ColorizingService.class) {
		colorProvider = new ToolBasedColorProvider(this, (ColorizingService) service);
		connectedProvider.refreshAndKeepPerspective();
	}
}
 
Example #12
Source File: FunctionGraphPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
	super.init();

	layoutProviders = loadLayoutProviders();

	createNewProvider();
	initializeOptions();

	ColorizingService colorizingService = tool.getService(ColorizingService.class);
	if (colorizingService != null) {
		colorProvider = new ToolBasedColorProvider(this, colorizingService);
	}
}
 
Example #13
Source File: BlockModelScreenShots.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void highlightCodeBlocks(final AddressSet addressSet) {
	int tx = program.startTransaction("Test");
	runSwing(() -> {

		ColorizingService colorizer = tool.getService(ColorizingService.class);

		Color c1 = new Color(0xE8F2FE);

		Color c2 = new Color(170, 204, 245);
		Color color = c1;

		BasicBlockModel basicBlockModel = new BasicBlockModel(program);
		CodeBlockIterator iterator;
		try {
			iterator = basicBlockModel.getCodeBlocksContaining(addressSet,
				TaskMonitorAdapter.DUMMY_MONITOR);

			while (iterator.hasNext()) {
				CodeBlock block = iterator.next();
				Address min = block.getMinAddress();
				Address max = block.getMaxAddress();
				colorizer.setBackgroundColor(min, max, color);
				color = (color == c1) ? c2 : c1;
			}
		}
		catch (CancelledException e) {
			// can't happen--dummy monitor
		}
	});
	program.endTransaction(tx, true);

	waitForSwing();
}
 
Example #14
Source File: BreakpointEvent.java    From gdbghidra with MIT License 5 votes vote down vote up
private static void doBreakpointTransaction(String action, BreakpointEvent breakpoint, Program currentProgram, ProgramPlugin plugin, long relocate) {
	var caddress = getBreakpointAddress(breakpoint, currentProgram, relocate);
	var category = "breakpoint";

	var tx = currentProgram.startTransaction(action);
	
	/*==================== Begin Transaction ====================================*/
	var service = plugin.getTool().getService(ColorizingService.class);
	var bm = currentProgram.getBookmarkManager().getBookmark(caddress, category, category);
	
	switch(breakpoint.getAction()) {
		case ENABLE:
			service.setBackgroundColor(caddress, caddress, Color.RED);
			break;
		case DISABLE:
			service.setBackgroundColor(caddress, caddress, Color.LIGHT_GRAY);
			break;
		case DELETE:
			service.setBackgroundColor(caddress, caddress, Color.WHITE);
			break;
	}

	if(bm != null) {
		if(breakpoint.action == BreakpointEventAction.DELETE) {
			currentProgram.getBookmarkManager().removeBookmark(bm);
			service = plugin.getTool().getService(ColorizingService.class);
		}else {
			bm.set(category, action);
		}
	}else {
		currentProgram.getBookmarkManager().setBookmark(caddress, category, category, action);
	}
	/*==================== END Transaction ====================================*/
	currentProgram.endTransaction(tx, true);
	
}
 
Example #15
Source File: CursorEvent.java    From gdbghidra with MIT License 5 votes vote down vote up
public static long handleEvent(CursorEvent cursor, Program currentProgram, GDBGhidraPlugin plugin) {
	var newAddress = currentProgram.getImageBase().add(cursor.getOffset());
	plugin.getTool().getService(GoToService.class).goTo(newAddress);
	
	var tx = currentProgram.startTransaction("change cursor color");
	
	/*==================== Begin Transaction ====================================*/
	var service = plugin.getTool().getService(ColorizingService.class);
	var currentColor = service.getBackgroundColor(newAddress);
	
	var previousAddress = plugin.getProvider().getPreviousAddress();
	
	service.setBackgroundColor(newAddress, newAddress, Color.GREEN);
	
	if(previousAddress != null ) {	
		service.setBackgroundColor(plugin.getProvider().getPreviousAddress(), plugin.getProvider().getPreviousAddress(), plugin.getProvider().getPreviousColor());
	}
	plugin.getProvider().setPreviousAddress(newAddress);
	if(currentColor == null) {
		plugin.getProvider().setPreviousColor(Color.WHITE);
	}else {
		plugin.getProvider().setPreviousColor(currentColor);
	}
	/*==================== END Transaction ====================================*/
	currentProgram.endTransaction(tx, true);
	
	
	if(!cursor.getRelocationAddressString().equals("unknown")) {
		return cursor.getRelocationAddress();
	}
	return 0;
}
 
Example #16
Source File: VTPlugin.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ColorizingService getDestinationColorizingService() {
	return toolManager.getDestinationColorizingService();
}
 
Example #17
Source File: VTControllerImpl.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public ColorizingService getSourceColorizingService() {
	return plugin.getSourceColorizingService();
}
 
Example #18
Source File: VTSubToolManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ColorizingService getDestinationColorizingService() {
	return destinationTool.getService(ColorizingService.class);
}
 
Example #19
Source File: VTControllerImpl.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public ColorizingService getDestinationColorizingService() {
	return plugin.getDestinationColorizingService();
}
 
Example #20
Source File: VTSubToolManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ColorizingService getSourceColorizingService() {
	return sourceTool.getService(ColorizingService.class);
}
 
Example #21
Source File: DragonHelper.java    From dragondance with GNU General Public License v3.0 4 votes vote down vote up
public static boolean setInstructionBackgroundColor(long addr, Color color) {
	
	Address ba;
	
	ColorizingService colorService = tool.getService(ColorizingService.class);
	
	if (colorService == null) {
		return false;
	}
	
	ba = getAddress(addr);
	
	colorService.setBackgroundColor(ba, ba, color);
	
	return true;
}
 
Example #22
Source File: VTPlugin.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public ColorizingService getSourceColorizingService() {
	return toolManager.getSourceColorizingService();
}
 
Example #23
Source File: ToolBasedColorProvider.java    From ghidra with Apache License 2.0 4 votes vote down vote up
ToolBasedColorProvider(FunctionGraphPlugin plugin, ColorizingService colorizingService) {
	this.plugin = plugin;
	this.service = colorizingService;
}
 
Example #24
Source File: DragonHelper.java    From dragondance with GNU General Public License v3.0 4 votes vote down vote up
public static boolean clearInstructionBackgroundColor(long addr) {
	
	Address ba;
	
	ColorizingService colorService = tool.getService(ColorizingService.class);
	
	if (colorService == null) {
		return false;
	}
	
	ba = getAddress(addr);
	
	colorService.clearBackgroundColor(ba, ba);
	
	return true;
}
 
Example #25
Source File: VTController.java    From ghidra with Apache License 2.0 votes vote down vote up
public ColorizingService getDestinationColorizingService(); 
Example #26
Source File: VTController.java    From ghidra with Apache License 2.0 votes vote down vote up
public ColorizingService getSourceColorizingService();