Java Code Examples for ghidra.framework.cmd.CompoundCmd#add()

The following examples show how to use ghidra.framework.cmd.CompoundCmd#add() . 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: FunctionWindowPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAndRestore() throws Exception {

	int numData = functionTable.getRowCount();

	CompoundCmd cmd = new CompoundCmd("Clear");
	FunctionIterator itr = program.getListing().getFunctions(true);
	while (itr.hasNext()) {
		Function f = itr.next();
		cmd.add(new ClearCmd(f.getBody(), new ClearOptions()));
	}
	applyCmd(program, cmd);
	waitForNotBusy(functionTable);

	assertEquals(0, functionTable.getRowCount());

	undo(program);
	waitForNotBusy(functionTable);

	assertEquals(numData, functionTable.getRowCount());

}
 
Example 2
Source File: SetStackDepthChangeAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setFunctionPurge(final Program program, final Address fromAddress,
		final int newFunctionPurgeSize, final Address callToAddress) {
	Function function = program.getFunctionManager().getFunctionAt(callToAddress);
	if (function == null) {
		return;
	}
	// Set the function purge.
	Command purgeCmd = new SetFunctionPurgeCommand(function, newFunctionPurgeSize);

	Integer dephtChange = CallDepthChangeInfo.getStackDepthChange(program, fromAddress);
	if (dephtChange != null) {
		// If we have a stack depth change here, remove it since we are setting the purge.
		CompoundCmd compoundCmd = new CompoundCmd("Set Function Purge via StackDepthChange");
		compoundCmd.add(new RemoveStackDepthChangeCommand(program, fromAddress));
		compoundCmd.add(purgeCmd);
		funcPlugin.execute(program, compoundCmd);
	}
	else {
		funcPlugin.execute(program, purgeCmd);
	}
}
 
Example 3
Source File: BookmarkPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testMarkerAdded() throws Exception {
	MarkerService markerService = tool.getService(MarkerService.class);
	MarkerSet markerSet = markerService.getMarkerSet("Type1 Bookmarks", program);
	AddressSet addressSet = runSwing(() -> markerSet.getAddressSet());
	assertFalse(addressSet.contains(addr("01001100")));
	assertFalse(addressSet.contains(addr("01001120")));

	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("01001100"), "Type1", "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("01001120"), "Type1", "Cat1a", "Cmt1B"));
	applyCmd(program, addCmd);

	MarkerSet type1MarkerSet = markerService.getMarkerSet("Type1 Bookmarks", program);
	addressSet = runSwing(() -> type1MarkerSet.getAddressSet());
	assertTrue(addressSet.contains(addr("01001100")));
	assertTrue(addressSet.contains(addr("01001120")));
}
 
Example 4
Source File: RegisterValuesPanel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void deleteSelectedRanges() {
	CompoundCmd cmd = new CompoundCmd("Delete Register Value Ranges");
	int[] rows = table.getSelectedRows();
	boolean containsDefaultValues = false;
	for (int row : rows) {
		RegisterValueRange rvr = model.values.get(row);
		if (rvr.isDefault()) {
			containsDefaultValues = true;
		}
		cmd.add(new SetRegisterCmd(selectedRegister, rvr.getStartAddress(), rvr.getEndAddress(),
			null));
	}
	if (containsDefaultValues) {
		int result = OptionDialog.showOptionDialog(table, "Warning",
			"The selected ranges " +
				"contain default values that can't be deleted.\n  Do you want to continue?",
			"Yes", OptionDialog.WARNING_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	if (cmd.size() > 0) {
		tool.execute(cmd, currentProgram);
	}
}
 
Example 5
Source File: BookmarkPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteOffcutBookmarks() throws Exception {
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	Address a = addr("0100b6db");
	for (int i = 0; i < 20; i++) {
		addCmd.add(new BookmarkEditCmd(a, "Type1", "Cat1a", "Cmt1A"));
		a = a.add(1);
	}
	applyCmd(program, addCmd);

	//make a structure
	CreateStructureCmd cmd = new CreateStructureCmd(addr("0100b6db"), 20);
	applyCmd(program, cmd);

	List<DockingActionIf> actions = runSwing(() -> plugin.getPopupActions(null,
		createContext(new MarkerLocation(null, addr("0100b6db"), 0, 0))));
	assertEquals(10, actions.size());
}
 
Example 6
Source File: DualProgramTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testOpenSameSecondProgram() throws Exception {
	openSecondProgram(diffTestP1, diffTestP1);
	assertNotNull(fp2.getTopLevelAncestor());

	// Check action enablement.
	assertTrue(viewDiffs.isEnabled());
	assertTrue(!applyDiffs.isEnabled());
	assertTrue(!applyDiffsNext.isEnabled());
	assertTrue(!ignoreDiffs.isEnabled());
	assertTrue(!nextDiff.isEnabled());
	assertTrue(!prevDiff.isEnabled());
	assertTrue(diffDetails.isEnabled());
	assertTrue(!diffApplySettings.isEnabled());
	assertTrue(getDiffs.isEnabled());
	assertTrue(selectAllDiffs.isEnabled());
	assertTrue(!setPgm2Selection.isEnabled());

	// Modify the active program.
	setLocation("100f3ff");
	CompoundCmd cmd = new CompoundCmd("test");
	cmd.add(new AddLabelCmd(addr("100f3ff"), "TestLabel", false, SourceType.USER_DEFINED));
	cmd.add(
		new AddLabelCmd(addr("100f3ff"), "AnotherTestLabel", false, SourceType.USER_DEFINED));
	try {
		txId = diffTestP1.startTransaction("Modify Program");
		cmd.applyTo(diffTestP1);
	}
	finally {
		diffTestP1.endTransaction(txId, true);
	}

	// Check that the two programs now differ.
	assertTrue(viewDiffs.isEnabled());
	LayoutModel lm1 = fp1.getLayoutModel();
	LayoutModel lm2 = fp2.getLayoutModel();
	int num1 = lm1.getNumIndexes().intValue();
	int num2 = lm2.getNumIndexes().intValue();
	assertEquals(num1, num2);
}
 
Example 7
Source File: BookmarkEditCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Address[] createBookmarks(ProgramLocation[] locs) {

		CompoundCmd compoundCmd = new CompoundCmd("Create Bookmarks");

		Address[] addrs = new Address[locs.length];
		for (int i = 0; i < locs.length; i++) {
			Address addr = locs[i].getAddress();
			BookmarkEditCmd cmd = new BookmarkEditCmd(addr, "Type" + i, "Cat" + i, "Cmt" + i);
			compoundCmd.add(cmd);
			addrs[i] = addr;
		}
		applyCmd(notepad, compoundCmd);
		System.out.println("Created " + addrs.length + " Bookmarks");
		return addrs;
	}
 
Example 8
Source File: NextPrevCodeUnitPluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchAllTypesBookmark() throws Exception {
	loadProgram("notepad");
	showTool(tool);
	assertEquals(addr("01001000"), cb.getCurrentAddress());

	//
	// Setup:
	// 100c - error bookmark
	// 101c - info bookmark
	// 101e - warning bookmark
	//
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("0100100c"), BookmarkType.ERROR, "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("0100101c"), BookmarkType.INFO, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("0100101e"), BookmarkType.WARNING, "Cat1a", "Cmt1B"));
	applyCmd(program, addCmd);

	selectBookmarkType(BookmarkType.ALL_TYPES);

	pressBookmark();
	assertEquals(addr("0100100c"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("0100101c"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("0100101e"), cb.getCurrentAddress());

	toggleDirection();

	pressBookmark();
	assertEquals(addr("0100101c"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("0100100c"), cb.getCurrentAddress());
}
 
Example 9
Source File: ClearExternalNameAssociationAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	Program program = provider.getProgram();
	List<String> externalNames = provider.getSelectedExternalNames();
	CompoundCmd cmd = new CompoundCmd("Clear External Program Associations");
	for (String externalName : externalNames) {
		cmd.add(new ClearExternalNameCmd(externalName));
	}
	provider.getTool().execute(cmd, program);
}
 
Example 10
Source File: DeleteExternalReferenceNameAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	Program program = provider.getProgram();
	ExternalManager externalManager = program.getExternalManager();
	List<String> externalNames = provider.getSelectedExternalNames();
	StringBuffer buf = new StringBuffer();
	CompoundCmd cmd = new CompoundCmd("Delete External Program Name");
	for (String externalName : externalNames) {
		boolean hasLocations = externalManager.getExternalLocations(externalName).hasNext();
		if (hasLocations) {
			buf.append("\n     ");
			buf.append(externalName);
		}
		else {
			cmd.add(new RemoveExternalNameCmd(externalName));
		}
	}
	if (cmd.size() > 0) {
		provider.getTool().execute(cmd, program);
	}
	if (buf.length() > 0) {
		Msg.showError(getClass(), provider.getComponent(),
			"Delete Failure", "The following external reference names could not be deleted\n" +
				"because they contain external locations:\n" + buf.toString());
	}

}
 
Example 11
Source File: BookmarkPluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initProgram() {
	addrFactory = program.getAddressFactory();

	// Remove all existing bookmarks
	BookmarkDeleteCmd delCmd = new BookmarkDeleteCmd(addrFactory.getAddressSet(), null, null);
	applyCmd(program, delCmd);

	// Add specific bookmarks
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("01001010"), "Type1", "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("01001020"), "Type1", "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001020"), "Type1", "Cat1b", "Cmt1C"));
	addCmd.add(new BookmarkEditCmd(addr("01001030"), "Type1", "Cat1b", "Cmt1D"));
	addCmd.add(new BookmarkEditCmd(addr("01001030"), "Type2", "Cat2a", "Cmt2E"));
	addCmd.add(new BookmarkEditCmd(addr("01001040"), "Type2", "Cat2b", "Cmt2F"));
	addCmd.add(new BookmarkEditCmd(addr("01001040"), "Type3", "Cat3a", "Cmt2G"));
	addCmd.add(new BookmarkEditCmd(addr("01001050"), "Type3", "Cat3a", "Cmt2H"));
	addCmd.add(new BookmarkEditCmd(addr("01001060"), "Type3", "Cat3b", "Cmt2I"));
	applyCmd(program, addCmd);

	AddLabelCmd labelCmd =
		new AddLabelCmd(addr("01001020"), "Test20", false, SourceType.USER_DEFINED);
	applyCmd(program, labelCmd);

	labelCmd = new AddLabelCmd(addr("01001050"), "Test50", false, SourceType.USER_DEFINED);
	applyCmd(program, labelCmd);

	List<Bookmark> list = getBookmarks(program.getBookmarkManager());
	assertEquals(9, list.size());
	bookmarks = new Bookmark[9];
	list.toArray(bookmarks);
	Arrays.sort(bookmarks);
}
 
Example 12
Source File: FallThroughModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
void clearOverride(AddressSetView view) {
	CompoundCmd cmd = new CompoundCmd("Clear FallThroughs");
	InstructionIterator it = program.getListing().getInstructions(view, true);
	while(it.hasNext()) {
		Instruction inst = it.next();
		if (inst.isFallThroughOverridden()) {
			cmd.add(new ClearFallThroughCmd(inst.getMinAddress()));
		}
	}
	if (cmd.size() > 0) {
		tool.execute(cmd, program);
	}
}
 
Example 13
Source File: BookmarkPluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleDelete() throws Exception {
	showBookmarkProvider();

	// note: we want to test a specific code path, so we must delete more than 20 items

	// add more to our current set
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("01001110"), "Type1", "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("01001120"), "Type1", "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001120"), "Type1", "Cat1b", "Cmt1C"));
	addCmd.add(new BookmarkEditCmd(addr("01001130"), "Type1", "Cat1b", "Cmt1D"));
	addCmd.add(new BookmarkEditCmd(addr("01001130"), "Type2", "Cat2a", "Cmt2E"));
	addCmd.add(new BookmarkEditCmd(addr("01001140"), "Type2", "Cat2b", "Cmt2F"));
	addCmd.add(new BookmarkEditCmd(addr("01001140"), "Type3", "Cat3a", "Cmt2G"));
	addCmd.add(new BookmarkEditCmd(addr("01001150"), "Type3", "Cat3a", "Cmt2H"));
	addCmd.add(new BookmarkEditCmd(addr("01001160"), "Type3", "Cat3b", "Cmt2I"));
	addCmd.add(new BookmarkEditCmd(addr("01001210"), "Type1", "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("01001220"), "Type1", "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001220"), "Type1", "Cat1b", "Cmt1C"));
	addCmd.add(new BookmarkEditCmd(addr("01001230"), "Type1", "Cat1b", "Cmt1D"));
	addCmd.add(new BookmarkEditCmd(addr("01001230"), "Type2", "Cat2a", "Cmt2E"));
	addCmd.add(new BookmarkEditCmd(addr("01001240"), "Type2", "Cat2b", "Cmt2F"));
	addCmd.add(new BookmarkEditCmd(addr("01001240"), "Type3", "Cat3a", "Cmt2G"));
	addCmd.add(new BookmarkEditCmd(addr("01001250"), "Type3", "Cat3a", "Cmt2H"));
	addCmd.add(new BookmarkEditCmd(addr("01001260"), "Type3", "Cat3b", "Cmt2I"));
	applyCmd(program, addCmd);

	waitForTable();

	selectAllTableRows();
	runSwing(() -> provider.delete());
	waitForCondition(() -> table.getRowCount() == 0, "Bookmarks not deleted");
}
 
Example 14
Source File: NextPrevCodeUnitPluginTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testErrorBookmark() throws Exception {
	loadProgram("notepad");
	showTool(tool);
	assertEquals(addr("01001000"), cb.getCurrentAddress());
	clearExisingBookmarks();

	// add more to our current set
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("01001110"), BookmarkType.ERROR, "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("01001118"), BookmarkType.NOTE, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001120"), BookmarkType.ERROR, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001130"), BookmarkType.ERROR, "Cat1b", "Cmt1C"));
	addCmd.add(new BookmarkEditCmd(addr("01001140"), BookmarkType.ERROR, "Cat1b", "Cmt1D"));
	addCmd.add(new BookmarkEditCmd(addr("01001143"), BookmarkType.WARNING, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001150"), BookmarkType.ERROR, "Cat2a", "Cmt2E"));
	addCmd.add(new BookmarkEditCmd(addr("01001154"), BookmarkType.INFO, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01001160"), BookmarkType.ERROR, "Cat2b", "Cmt2F"));
	applyCmd(program, addCmd);

	selectBookmarkType(BookmarkType.ERROR);

	pressBookmark();
	assertEquals(addr("01001110"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001120"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001130"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001140"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001150"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001160"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001160"), cb.getCurrentAddress());

	toggleDirection();

	pressBookmark();
	assertEquals(addr("01001150"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001140"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001130"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001120"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001110"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01001110"), cb.getCurrentAddress());
}
 
Example 15
Source File: MarkerTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testToolTipMaxLines() throws Exception {
	tool.addPlugin(BookmarkPlugin.class.getName());
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	Address a = addr("0x0100b6db");
	for (int i = 0; i < 20; i++) {
		addCmd.add(new BookmarkEditCmd(a, "Type1", "Cat1a", "Cmt1A_" + (i + 1)));
		a = a.add(1);
	}

	if (!applyCmd(program, addCmd)) {
		Assert.fail("Could not create bookmarks - " + addCmd.getStatusMsg());
	}

	//make a structure
	CreateStructureCmd cmd = new CreateStructureCmd(addr("0100b6db"), 20);
	applyCmd(program, cmd);
	program.flushEvents();
	waitForPostedSwingRunnables();

	MarkerManager mm = (MarkerManager) markerService;

	cb.goToField(addr("0x100b6db"), "Address", 0, 4);

	Point cursor = cb.getListingPanel().getCursorPoint();

	int x = 1;
	int y = cursor.y;
	MouseEvent dummyEvent = new MouseEvent(cb.getFieldPanel(), (int) System.currentTimeMillis(),
		System.currentTimeMillis(), 0, x, y, 1, false);

	// debug
	ProgramLocation location = cb.getListingPanel().getProgramLocation(dummyEvent.getPoint());
	Msg.debug(this, "location for point: " + location + "; at " + location.getAddress());

	String tooltip = runSwing(() -> mm.generateToolTip(dummyEvent));
	assertNotNull("No tooltip for field: " + cb.getCurrentField() + "\n\tat address: " +
		cb.getCurrentAddress(), tooltip);

	// should have a line for "Cursor" and comments 1 through 9 for a max of 10 lines
	String expected = "<html><font size=\"4\">Cursor<BR>Type1 [Cat1a]: Cmt1A_1<BR>";
	assertTrue("Expected text to start with:\n\t" + expected + "\nfound:\n\t" + tooltip,
		tooltip.startsWith(expected));

	expected = "Type1 [Cat1a]: Cmt1A_9<BR>...<BR>";
	assertTrue("Expected text to end with:\n\t" + expected + "\nfound:\n\t" + tooltip,
		tooltip.endsWith(expected));
}
 
Example 16
Source File: AddEditDialog.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected void okCallback() {

	String labelText = getText();
	Namespace namespace = getSelectedNamespace();
	SymbolPath symbolPath = getSymbolPath(labelText);
	if (symbolPath == null) {
		return;
	}

	String symbolName = symbolPath.getName();

	// see if the user specified a namespace path and if so, then get the
	// new namespace name from that path
	Namespace parent = getOrCreateNamespaces(symbolPath, namespace);
	if (parent == null) {
		return;
	}

	boolean isCurrentlyEntryPoint = false;
	boolean isCurrentlyPinned = false;
	CompoundCmd cmd = new CompoundCmd(symbol == null ? "Add Label" : "Edit Label");
	if (symbol == null) {
		cmd.add(new AddLabelCmd(addr, symbolName, parent, SourceType.USER_DEFINED));
	}
	else {
		cmd.add(new RenameLabelCmd(addr, symbol.getName(), symbolName,
			symbol.getParentNamespace(), parent, SourceType.USER_DEFINED));
		isCurrentlyEntryPoint = symbol.isExternalEntryPoint();
		isCurrentlyPinned = symbol.isPinned();
	}

	if (primaryCheckBox.isEnabled() && primaryCheckBox.isSelected()) {
		cmd.add(new SetLabelPrimaryCmd(addr, symbolName, parent));
	}
	if (entryPointCheckBox.isEnabled() &&
		entryPointCheckBox.isSelected() != isCurrentlyEntryPoint) {
		cmd.add(new ExternalEntryCmd(addr, !isCurrentlyEntryPoint));
	}
	if (pinnedCheckBox.isEnabled() && pinnedCheckBox.isSelected() != isCurrentlyPinned) {
		cmd.add(new PinSymbolCmd(addr, symbolName, !isCurrentlyPinned));
	}

	if (cmd.size() > 0) {

		if (!tool.execute(cmd, program)) {
			setStatusText(cmd.getStatusMsg());
			return;
		}
		updateRecentLabels(symbolName);
	}
	program = null;
	close();
}
 
Example 17
Source File: Function1Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testParamCycleActions2() throws Exception {
	env.showTool();
	loadProgram("notepad");
	Address a = addr("0x100248f");
	cb.goToField(a, "Address", 0, 0);

	DockingActionIf action = getAction(dp, "Disassemble");
	assertNotNull(action);
	performAction(action, cb.getProvider(), true);
	waitForBusyTool();

	Function function = program.getListing().getFunctionAt(addr("0x100248f"));
	assertNotNull(function);// function created by FunctionStartAnalyzer

	CompoundCmd cmd = new CompoundCmd("test");
	for (Parameter parm : function.getParameters()) {
		cmd.add(new DeleteVariableCmd(parm));
	}
	cmd.add(new AddStackParameterCommand(function, 0x4, "param_1", Undefined4DataType.dataType,
		0, SourceType.USER_DEFINED));
	cmd.add(new AddStackParameterCommand(function, 0xc, "param_2", Undefined4DataType.dataType,
		1, SourceType.USER_DEFINED));
	cmd.add(new AddStackParameterCommand(function, 0x10, "param_3", Undefined4DataType.dataType,
		2, SourceType.USER_DEFINED));
	cmd.add(new AddStackParameterCommand(function, 0x18, "param_4", Undefined4DataType.dataType,
		3, SourceType.USER_DEFINED));
	tool.execute(cmd, program);
	waitForBusyTool();

	assertTrue(cb.goToField(a, "Variable Type", 3, 0, 0));
	DockingActionIf clearDataType = getAction(fp, "Define undefined");
	performAction(clearDataType, cb.getProvider(), true);
	waitForBusyTool();

	assertEquals("undefined", cb.getCurrentFieldText());

	doCycleAction(byteCycleAction);
	assertEquals("byte", cb.getCurrentFieldText());
	waitForBusyTool();
	cb.goToField(a, "Function Signature", 0, 0);

	String text = cb.getCurrentFieldText();
	assertTrue(text.contains(
		"FUN_0100248f(undefined4 param_1, undefined4 param_2, byte param_3, undefined4 param_4)"));

	assertTrue(cb.goToField(a, "Variable Type", 3, 0, 0));

	doCycleAction(byteCycleAction);
	assertEquals("word", cb.getCurrentFieldText());
	cb.goToField(a, "Function Signature", 0, 0);

	text = cb.getCurrentFieldText();
	assertTrue(text.contains(
		"FUN_0100248f(undefined4 param_1, undefined4 param_2, word param_3, undefined4 param_4)"));

	assertTrue(cb.goToField(a, "Variable Type", 3, 0, 0));

	doCycleAction(byteCycleAction);
	assertEquals("dword", cb.getCurrentFieldText());
	cb.goToField(a, "Function Signature", 0, 0);

	text = cb.getCurrentFieldText();
	assertTrue(text.contains(
		"FUN_0100248f(undefined4 param_1, undefined4 param_2, dword param_3, undefined4 param_4)"));

	assertTrue(cb.goToField(a, "Variable Type", 3, 0, 0));

	doCycleAction(byteCycleAction);
	assertEquals("qword", cb.getCurrentFieldText());
	cb.goToField(a, "Function Signature", 0, 0);

	text = cb.getCurrentFieldText();
	assertTrue(text.contains(
		"FUN_0100248f(undefined4 param_1, undefined4 param_2, qword param_3, undefined4 param_4)"));

	assertTrue(cb.goToField(a, "Variable Type", 3, 0, 0));

	doCycleAction(byteCycleAction);
	assertEquals("byte", cb.getCurrentFieldText());
	cb.goToField(a, "Function Signature", 0, 0);

	text = cb.getCurrentFieldText();
	assertTrue(text.contains(
		"FUN_0100248f(undefined4 param_1, undefined4 param_2, byte param_3, undefined4 param_4)"));

	assertTrue(cb.goToField(a, "Variable Type", 3, 0, 0));

	doCycleAction(floatCycleAction);
	assertEquals("float", cb.getCurrentFieldText());

	doCycleAction(floatCycleAction);
	assertEquals("double", cb.getCurrentFieldText());

	doCycleAction(floatCycleAction);
	assertEquals("float", cb.getCurrentFieldText());

}
 
Example 18
Source File: SymbolTableModel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
void delete(List<Symbol> rowObjects) {
	if (rowObjects == null || rowObjects.size() == 0) {
		return;
	}

	tool.setStatusInfo("");
	List<Symbol> deleteList = new LinkedList<>();
	CompoundCmd cmd = new CompoundCmd("Delete symbol(s)");
	for (Symbol symbol : rowObjects) {
		if (symbol.isDynamic()) {
			Symbol[] symbols = symbolTable.getSymbols(symbol.getAddress());
			if (symbols.length == 1) {
				tool.setStatusInfo("Unable to delete symbol: " + symbol.getName());
				continue;//can't delete dynamic symbols...
			}
		}

		deleteList.add(symbol);
		String label = symbol.getName();
		if (symbol.getSymbolType() == SymbolType.FUNCTION) {
			Function function = (Function) symbol.getObject();
			boolean ignoreMissingFunction = function.isThunk();
			cmd.add(new DeleteFunctionCmd(symbol.getAddress(), ignoreMissingFunction));
			if (symbol.getSource() != SourceType.DEFAULT) {
				// remove label which gets created when non-default function is removed
				cmd.add(new DeleteLabelCmd(symbol.getAddress(), label,
					symbol.getParentNamespace()));
			}
		}
		else {
			cmd.add(
				new DeleteLabelCmd(symbol.getAddress(), label, symbol.getParentNamespace()));
		}
	}
	if (cmd.size() == 0) {
		return;
	}

	if (tool.execute(cmd, getProgram())) {
		for (Symbol s : deleteList) {
			removeObject(s);
		}
		updateNow();
	}
	else {
		tool.setStatusInfo(cmd.getStatusMsg());
		reload();
	}
}
 
Example 19
Source File: NextPrevCodeUnitPluginTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testWarningBookmark() throws Exception {
	loadProgram("notepad");
	showTool(tool);
	assertEquals(addr("01001000"), cb.getCurrentAddress());
	clearExisingBookmarks();

	// add more to our current set
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("01003e2c"), BookmarkType.WARNING, "Cat1a", "Cmt1A"));
	addCmd.add(new BookmarkEditCmd(addr("01003e2e"), BookmarkType.NOTE, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01003e30"), BookmarkType.WARNING, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01003e32"), BookmarkType.WARNING, "Cat1b", "Cmt1C"));
	addCmd.add(new BookmarkEditCmd(addr("01003e38"), BookmarkType.WARNING, "Cat1b", "Cmt1D"));
	addCmd.add(new BookmarkEditCmd(addr("01003e3a"), BookmarkType.WARNING, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01003e40"), BookmarkType.ANALYSIS, "Cat2a", "Cmt2E"));
	addCmd.add(new BookmarkEditCmd(addr("01003e41"), BookmarkType.INFO, "Cat1a", "Cmt1B"));
	addCmd.add(new BookmarkEditCmd(addr("01003e43"), BookmarkType.WARNING, "Cat2b", "Cmt2F"));
	applyCmd(program, addCmd);

	selectBookmarkType(BookmarkType.WARNING);

	pressBookmark();
	assertEquals(addr("01003e2c"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e30"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e32"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e38"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e3a"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e43"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e43"), cb.getCurrentAddress());

	toggleDirection();

	pressBookmark();
	assertEquals(addr("01003e3a"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e38"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e32"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e30"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e2c"), cb.getCurrentAddress());

	pressBookmark();
	assertEquals(addr("01003e2c"), cb.getCurrentAddress());
}
 
Example 20
Source File: NextPrevCodeUnitPluginTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testBookmarksOffcutInStructures() throws Exception {
	loadProgram("notepad");
	showTool(tool);
	assertEquals(addr("01001000"), cb.getCurrentAddress());

	//
	// Setup:
	// 1000 - info bookmark
	// 1006 - offcut info bookmark
	// 101e - info bookmark
	//
	CompoundCmd addCmd = new CompoundCmd("Add Bookmarks");
	addCmd.add(new BookmarkEditCmd(addr("01001000"), BookmarkType.INFO, "Cat1a", "A"));
	addCmd.add(new BookmarkEditCmd(addr("01001004"), BookmarkType.INFO, "Cat1a", "B"));
	addCmd.add(new BookmarkEditCmd(addr("0100100d"), BookmarkType.INFO, "Cat1a", "C"));
	addCmd.add(new BookmarkEditCmd(addr("01001010"), BookmarkType.INFO, "Cat1a", "C"));
	addCmd.add(new BookmarkEditCmd(addr("01001015"), BookmarkType.INFO, "Cat1a", "D"));
	addCmd.add(new BookmarkEditCmd(addr("01001020"), BookmarkType.INFO, "Cat1a", "E"));

	StructureDataType struct = new StructureDataType("Test", 0);
	struct.add(new DWordDataType());
	struct.add(new DWordDataType());
	struct.add(new DWordDataType());
	assertEquals(12, struct.getLength());

	addCmd.add(new CreateDataCmd(addr("0100100c"), struct));

	applyCmd(program, addCmd);

	selectBookmarkType(BookmarkType.ALL_TYPES);

	pressBookmark();
	assertEquals(addr("01001004"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("0100100c"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("01001010"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("01001014"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("01001020"), cb.getCurrentAddress());

	toggleDirection();

	pressBookmark();
	assertEquals(addr("01001014"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("01001010"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("0100100c"), cb.getCurrentAddress());
	pressBookmark();
	assertEquals(addr("01001004"), cb.getCurrentAddress());
}