ghidra.program.model.address.AddressSet Java Examples

The following examples show how to use ghidra.program.model.address.AddressSet. 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: FunctionMergeManager2Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
	public void testRemoveConflictUseForAll() throws Exception {
		setupRemoveConflictUseForAll();

		executeMerge(ASK_USER);
		verticalChooseFunction("0x10031ee", KEEP_MY, true);
//		verticalChooseFunction("0x1003bed", KEEP_MY, false); // Handled by "Use For All".
		waitForMergeCompletion();

		AddressSet body10031ee = new AddressSet(addr("0x10031ee"), addr("0x100324f"));
		checkFunction(resultProgram, "0x10031ee", "FUN_010031ee", body10031ee);
		Function func10031ee = getFunction(resultProgram, "0x10031ee");
		assertTrue(new ByteDataType().isEquivalent(func10031ee.getReturnType()));
		AddressSet body1003bed = new AddressSet(addr("0x1003bed"), addr("0x1003efb"));
		checkFunction(resultProgram, "0x1003bed", "FUN_01003bed", body1003bed);
		Function func1003bed = getFunction(resultProgram, "0x1003bed");
		assertTrue(new ByteDataType().isEquivalent(func1003bed.getReturnType()));
	}
 
Example #2
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtRefDiff5() throws Exception {
	// 0x100103c: p2 set ToAddress to 0x77f4abcd.

	programBuilder1.applyDataType("0x0100103c", new Pointer32DataType(), 1);
	programBuilder1.createExternalReference("0x0100103c", "GDI32.dll", "XYZ", "0x77f4cdef", 0);

	programBuilder2.applyDataType("0x0100103c", new Pointer32DataType(), 1);
	programBuilder2.createExternalReference("0x0100103c", "GDI32.dll", "XYZ", "0x77f4abcd", 0);

	programDiff =
		new ProgramDiff(p1, p2, new AddressSet(addr(p1, 0x01001000), addr(p1, 0x010017ff)));
	AddressSet as = new AddressSet();
	as.addRange(addr(p1, 0x0100103c), addr(p1, 0x0100103f));

	programDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.REFERENCE_DIFFS));
	assertEquals(as, programDiff.getDifferences(programDiff.getFilter(), null));
}
 
Example #3
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtRefDiff3() throws Exception {
	// 0x1001034: p2 set ExternalName to myGDI32.dll.

	programBuilder1.applyDataType("0x01001034", new Pointer32DataType(), 1);
	programBuilder1.createExternalReference("0x01001034", "GDI32.dll", "SomePlace", 0);

	programBuilder2.applyDataType("0x01001034", new Pointer32DataType(), 1);
	programBuilder2.createExternalReference("0x01001034", "myGDI32.dll", "SomePlace", 0);

	programDiff =
		new ProgramDiff(p1, p2, new AddressSet(addr(p1, 0x01001000), addr(p1, 0x010017ff)));
	AddressSet as = new AddressSet();
	as.addRange(addr(p1, 0x01001034), addr(p1, 0x01001037));

	programDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.REFERENCE_DIFFS));
	assertEquals(as, programDiff.getDifferences(programDiff.getFilter(), null));
}
 
Example #4
Source File: CreateNamespacesCmdTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private Function createFunction()
		throws DuplicateNameException, InvalidInputException, OverlappingFunctionException {

	int txId = program.startTransaction("Transaction");
	try {
		Address addr = program.getAddressFactory().getDefaultAddressSpace().getAddress(0x0);
		Function func1 = program.getFunctionManager().createFunction("func1", addr,
			new AddressSet(addr), SourceType.USER_DEFINED);
		assertNotNull(func1);
		return func1;
	}
	finally {
		program.endTransaction(txId, true);
	}

}
 
Example #5
Source File: FollowFlowForwardTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFollowAllFlowsFrom0x5024() {

	AddressSetView flowAddresses = getFlowsFrom(0x5024, followAllFlows());

	AddressSet expectedAddresses = new AddressSet();
	expectedAddresses.add(addr(0x90), addr(0xb4));
	expectedAddresses.add(addr(0xb6), addr(0xbf));
	expectedAddresses.add(addr(0x330), addr(0x331));
	expectedAddresses.add(addr(0x360), addr(0x361));
	expectedAddresses.add(addr(0x390), addr(0x391));
	expectedAddresses.add(addr(0x5024), addr(0x5027));
	expectedAddresses.add(addr(0x5040), addr(0x5043));

	assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses));
}
 
Example #6
Source File: DiffApplyIgnoreTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testProgramContextIgnore() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	assertNotNull(dialog);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	ignore(programContextApplyCB);
	AddressSet as = new AddressSet(addr("1002378"), addr("1002383"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs, diffPlugin.getDiffHighlightSelection());
}
 
Example #7
Source File: ProgramTreeSelectionPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Method selectModule.
 */
private void selectModule(ActionContext context) {
	AddressSet addressSet = new AddressSet();
	ProgramNode node = (ProgramNode) context.getContextObject();

	JTree tree = node.getTree();
	int count = tree.getSelectionCount();
	TreePath paths[] = node.getTree().getSelectionPaths();
	for (int i = 0; i < count; i++) {
		TreePath path = paths[i];
		ProgramNode pNode = (ProgramNode) path.getLastPathComponent();
		getAddressSet(pNode.getGroup(), addressSet);
	}
	ProgramSelection selection = new ProgramSelection(addressSet);
	ProgramSelectionPluginEvent pspe =
		new ProgramSelectionPluginEvent("Selection", selection, node.getProgram());
	firePluginEvent(pspe);
}
 
Example #8
Source File: DiffIgnoreTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Tests to see if Equate Tables are properly ignored and the next difference is properly selected
 * @throws Exception
 */
@Test
public void testIgnoreDiffsNextActionMiddle() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();

	List<Equate> eqs = diffTestP1.getEquateTable().getEquates(addr("1002261"), 0);
	assertEquals(0, eqs.size());

	AddressSet addrSet = new AddressSet(addr("1002261"), addr("1002262"));
	setDiffSelection(addrSet);
	setLocation("1002261"); // has Equate Diff
	ignoreAndNext();

	checkDiffSelection(new AddressSet(addr("10022d4"), addr("10022e5")));
	assertEquals(addr("10022d4"), getDiffAddress());
	eqs = program.getEquateTable().getEquates(addr("1002261"), 0);
	assertEquals(0, eqs.size());
}
 
Example #9
Source File: DiffApplyIgnoreTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFunctionIgnore() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	assertNotNull(dialog);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	AddressSet as = new AddressSet(addr("100299e"), addr("100299e"));
	assertTrue("Original diff set doesn't contain " + as.toString(), origDiffs.contains(as));
	ignore(functionApplyCB);
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs, diffPlugin.getDiffHighlightSelection());
}
 
Example #10
Source File: DiffEnablementTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectMultipleDiffBlockEnablement() {
	AddressSet as = new AddressSet(addr("10018ce"), addr("10018cf"));
	as.addRange(addr("1002040"), addr("1002042"));
	as.addRange(addr("100233c"), addr("1002347"));

	ProgramSelection sel = new ProgramSelection(as);
	setDiffSelection(sel);
	tool.firePluginEvent(new ProgramSelectionPluginEvent("test", sel, program));

	tool.firePluginEvent(new ProgramLocationPluginEvent("test", new ProgramLocation(program,
		addr("1002040")), program));

	// 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());
}
 
Example #11
Source File: DiffIgnoreTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Tests to see if a difference is ignored and the next difference is selected
 * @throws Exception
 */
@Test
public void testIgnoreDiffsNextActionFirst() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();

	byte[] bytes = diffTestP1.getListing().getCodeUnitAt(addr("100")).getBytes();
	assertEquals((byte) 0xac, bytes[0]);

	AddressSet addrSet = new AddressSet(addr("100"), addr("1ff"));
	setDiffSelection(addrSet);
	setLocation("100");
	ignoreAndNext();

	checkDiffSelection(new AddressSet(addr("00000200"), addr("000002ff")));
	assertTrue(diffPlugin.getDiffHighlightSelection().intersect(addrSet).isEmpty());
	assertEquals(addr("00000200"), getDiffAddress());
	bytes = diffTestP1.getListing().getCodeUnitAt(addr("100")).getBytes();
	assertEquals((byte) 0xac, bytes[0]);
}
 
Example #12
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Test that ProgramDiff can determine that function local names are
 * different.
 */
@Test
public void testFunctionLocalNameDiff() throws Exception {

	// 0x10059a3: renamed local_18 to numAvailable in p1.

	int transactionID1 = p1.startTransaction("Test Transaction");
	Function function1 = p1.getFunctionManager().getFunctionAt(addr(p1, 0x10059a3));
	Variable[] localVariables = function1.getLocalVariables();
	assertEquals(5, localVariables.length);
	assertEquals(-0x18, localVariables[4].getStackOffset());
	localVariables[4].setName("numAvailable", SourceType.USER_DEFINED);
	p1.endTransaction(transactionID1, true);

	AddressSet expectedDiffs = new AddressSet(addr(0x10059a3), addr(0x10059a3));
	checkDiff(expectedDiffs, ProgramDiffFilter.FUNCTION_DIFFS);
}
 
Example #13
Source File: CreateSelectionAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	Program sourceProgram = controller.getSourceProgram();
	Program destinationProgram = controller.getDestinationProgram();
	AddressSet sourceSet = new AddressSet();
	AddressSet destinationSet = new AddressSet();
	VTMatchContext matchContext = (VTMatchContext) context;
	List<VTMatch> matches = matchContext.getSelectedMatches();
	for (VTMatch vtMatch : matches) {
		VTAssociation association = vtMatch.getAssociation();
		sourceSet.add(association.getSourceAddress());
		destinationSet.add(association.getDestinationAddress());
	}
	controller.setSelectionInSourceTool(sourceSet);
	controller.setSelectionInDestinationTool(destinationSet);
}
 
Example #14
Source File: EquatePlugin1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetEquate_ApplyToWholeProgram() throws Exception {

	// put the cursor on a scalar 
	putCursorOnOperand(0x010018d6, 0);

	// grab the dialog and select the radio button for 'apply to whole program'
	SetEquateDialog d = getSetEquatesDialog();
	pressButtonByText(d, "Entire program");
	String equateText = "Bob";
	setEquateString(equateText, d);
	pressButtonByText(d, "OK");

	flushProgramEvents();

	// verify all scalars were changed
	AddressSet scalarAddresses = new AddressSet();
	scalarAddresses.add(addr("10035be"));
	scalarAddresses.add(addr("100364c"));
	scalarAddresses.add(addr("1004ad6"));

	assertEquateAt(equateText, scalarAddresses);
}
 
Example #15
Source File: SetHighlightPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubtractSelectionFromHighlight() {
	DockingActionIf subtractSelectionAction =
		getAction(plugin, "Subtract Selection From Highlight");
	assertNotNull(subtractSelectionAction);

	AddressSet selectionSet = new AddressSet(addr(0x01001234), addr(0x01001277));
	tool.firePluginEvent(
		new ProgramSelectionPluginEvent("test", new ProgramSelection(selectionSet), program));
	waitForPostedSwingRunnables();

	AddressSet highlightSet = new AddressSet(addr(0x01001270), addr(0x01001297));
	tool.firePluginEvent(
		new ProgramHighlightPluginEvent("test", new ProgramSelection(highlightSet), program));
	waitForPostedSwingRunnables();

	assertEquals(new ProgramSelection(selectionSet), cb.getCurrentSelection());
	assertEquals(new ProgramSelection(highlightSet), getHighlight());

	performAction(subtractSelectionAction, cb.getProvider(), true);

	AddressSet resultHighlightSet = new AddressSet(addr(0x01001278), addr(0x01001297));

	assertEquals(new ProgramSelection(selectionSet), cb.getCurrentSelection());
	assertEquals(new ProgramSelection(resultHighlightSet), getHighlight());
}
 
Example #16
Source File: SetHighlightPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHighlight() {
	DockingActionIf setHighlightAction =
		getAction(plugin, "Set Highlight From Selection");
	assertNotNull(setHighlightAction);

	AddressSet selectionSet = new AddressSet(addr(0x01001234), addr(0x01001277));
	tool.firePluginEvent(
		new ProgramSelectionPluginEvent("test", new ProgramSelection(selectionSet), program));
	waitForPostedSwingRunnables();

	assertEquals(new ProgramSelection(selectionSet), cb.getCurrentSelection());
	assertEquals(new ProgramSelection(), getHighlight());

	performAction(setHighlightAction, cb.getProvider(), true);

	assertEquals(new ProgramSelection(selectionSet), cb.getCurrentSelection());
	assertEquals(new ProgramSelection(selectionSet), getHighlight());
}
 
Example #17
Source File: ProgramTreePlugin3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDnDCodeUnits2FragNotInView() throws Exception {
	// drag code units to another fragment
	// verify that the destination fragment contains the dragged
	// code units
	ProgramNode dataNode = root.getChild(".data");
	setViewPaths(new TreePath[] { dataNode.getTreePath() });

	AddressSet set = new AddressSet();
	set.addRange(getAddr(0x01002a9b), getAddr(0x01002aad));
	SelectionTransferData data =
		new SelectionTransferData(set, program.getDomainFile().getPathname());
	ProgramNode debugNode = root.getChild(".debug_data");

	dropSelectionOnTree(debugNode, data);

	assertTrue(debugNode.getFragment().contains(set));

	// verify that the view remains unaffected
	assertTrue(plugin.getView().hasSameAddresses(dataNode.getFragment()));
}
 
Example #18
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Test that ProgramDiff can determine that function parameter names are
 * different.
 */
@Test
public void testFunctionParamNameDiff() throws Exception {

	// 0x01002cf5: renamed parm_2 to value in p1.
	int transactionID = p1.startTransaction("Test Transaction");
	Function function = p1.getFunctionManager().getFunctionAt(addr(p1, 0x1002cf5));
	function.getParameter(0).setName("value", SourceType.USER_DEFINED);
	p1.endTransaction(transactionID, true);

	programDiff = new ProgramDiff(p1, p2);
	programDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.FUNCTION_DIFFS));
	AddressSet diffAs = new AddressSet();
	diffAs.addRange(addr(0x01002cf5), addr(0x01002cf5));
	assertEquals(diffAs, programDiff.getDifferences(programDiff.getFilter(), null));
}
 
Example #19
Source File: CreateDiffTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private String getMemoryDifferenceMessage(final boolean noFilteredDifferencesFound,
		ProgramMemoryComparator programMemoryComparator) {
	String message;
	message = "The memory addresses defined by the two programs are not the same.\n \n" +
		(noFilteredDifferencesFound ? "However, no differences were found "
				: "Differences are highlighted ") +
		"for the addresses that are compatible between" +
		"\nthe two programs for the types of program information being compared by this Diff.";

	AddressSet addressesOnlyInOne = programMemoryComparator.getAddressesOnlyInOne();
	if (!addressesOnlyInOne.isEmpty()) {
		message +=
			"\n \nSome addresses are only in program 1 : " + addressesOnlyInOne.toString();
	}

	AddressSet addressesOnlyInTwo = programMemoryComparator.getAddressesOnlyInTwo();
	if (!addressesOnlyInTwo.isEmpty()) {
		message +=
			"\n \nSome addresses are only in program 2 : " + addressesOnlyInTwo.toString();
	}
	return message;
}
 
Example #20
Source File: FollowDelaySlotFlowTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * 
 *     10: callds 20 --+
 *     12: _or         |
 *     14: ret         |
 *                     |
 *     20: or   <------+
 *     22: ret
 *     
 * simple delay slot flow
 */
@Test
public void testBackwardFlowConditionalDelaySlotBranch() throws Exception {

	programBuilder.addBytesCallWithDelaySlot(10, 20);
	programBuilder.addBytesReturn(14);

	programBuilder.addBytesFallthrough(20);
	programBuilder.addBytesReturn(22);

	programBuilder.disassemble(toHex(10), 6, false);
	programBuilder.disassemble(toHex(20), 4, false);

	Address addr = address(22);
	AddressSet addressSet = new AddressSet(addr);
	FlowType[] flowsNotToFollow = new FlowType[] {};
	FollowFlow followFlow = new FollowFlow(program, addressSet, flowsNotToFollow); // FollowAllFlows
	AddressSet flowAddresses = followFlow.getFlowToAddressSet(TaskMonitorAdapter.DUMMY_MONITOR);

	AddressSet expectedAddresses = new AddressSet();
	expectedAddresses.add(address(10), address(13));
	expectedAddresses.add(address(20), address(23));

	assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses));

}
 
Example #21
Source File: FollowFlowBackwardTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointersBackFrom0x5040() {

	AddressSetView flowAddresses = getFlowsTo(0x5040, followOnlyPointers());

	AddressSet expectedAddresses = new AddressSet();
	expectedAddresses.add(addr(0x390), addr(0x390));
	expectedAddresses.add(addr(0x5040), addr(0x5040));

	assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses));
}
 
Example #22
Source File: DiffApplyReplaceTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testByteReplace() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	replace(byteApplyCB);
	AddressSet as = new AddressSet(addr("1002b45"), addr("1002b45"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs.subtract(as), diffPlugin.getDiffHighlightSelection());
}
 
Example #23
Source File: ByteViewerPlugin1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessSelectionEvent() throws Exception {
	loadViews("Ascii", "Octal");

	ByteViewerComponent c = panel.getCurrentComponent();

	AddressSet set = new AddressSet();
	set.addRange(addr(0x01004178), addr(0x0100419b));
	set.addRange(addr(0x010041a8), addr(0x010041bc));
	ProgramSelection sel = new ProgramSelection(set);
	Plugin p = env.getPlugin(NavigationHistoryPlugin.class);
	p.firePluginEvent(new ProgramSelectionPluginEvent(p.getName(), sel, program));
	waitForSwing();

	ByteBlockSelection bsel = c.getViewerSelection();

	c = findComponent(panel, "Octal");
	assertTrue(byteBlockSelectionEquals(bsel, c.getViewerSelection()));
	c = findComponent(panel, "Ascii");
	assertTrue(byteBlockSelectionEquals(bsel, c.getViewerSelection()));

	ProgramSelection psel = cbPlugin.getCurrentSelection();

	bsel = panel.getViewerSelection();

	// convert bsel to an address set
	set = ((ProgramByteBlockSet) plugin.getProvider().getByteBlockSet()).getAddressSet(bsel);
	assertTrue(psel.hasSameAddresses(set));
}
 
Example #24
Source File: DiffApplyMergeTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testPlateCommentMerge() {
	openDiff(diffTestP1, diffTestP2);
	showApplySettings();

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	merge(plateCommentApplyCB);
	AddressSet as = new AddressSet(addr("100415a"), addr("100415a"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs.subtract(as), diffPlugin.getDiffHighlightSelection());
	Listing listing = program.getListing();
	CodeUnit cu = listing.getCodeUnitAt(addr("100415a"));
	assertEquals("This is my function for testing diff", cu.getComment(CodeUnit.PLATE_COMMENT));
}
 
Example #25
Source File: DiffApplyIgnoreTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void postCommentIgnore() {
	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	ignore(postCommentApplyCB);
	AddressSet as = new AddressSet(addr("100239d"), addr("100239d"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs, diffPlugin.getDiffHighlightSelection());
}
 
Example #26
Source File: DiffApplyReplaceTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void memRefReplace() {
	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	replace(refApplyCB);
	AddressSet as = new AddressSet(addr("1002a2a"), addr("1002a2a"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs.subtract(as), diffPlugin.getDiffHighlightSelection());
}
 
Example #27
Source File: SearchTextPlugin1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private AddressSet getAddressesFromModel(AddressBasedTableModel<ProgramLocation> model) {
	AddressSet set = new AddressSet();
	int rowCount = model.getRowCount();
	for (int i = 0; i < rowCount; i++) {
		AddressBasedLocation location = (AddressBasedLocation) model.getValueAt(i,
			model.getColumnIndex(AddressTableColumn.class));
		Address addr = location.getAddress();
		set.addRange(addr, addr);
	}
	return set;
}
 
Example #28
Source File: DiffApply2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testUndoRedo() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	List<Equate> eqs = program.getEquateTable().getEquates(addr("1002261"), 0);
	assertEquals(0, eqs.size());

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();

	AddressSet addrSet = new AddressSet(addr("1002261"), addr("1002262"));
	ProgramSelection newDiffs = new ProgramSelection(origDiffs.subtract(addrSet));
	setDiffSelection(addrSet);
	setLocation("1002261"); // has Equate Diff
	apply();

	eqs = program.getEquateTable().getEquates(addr("1002261"), 0);
	assertEquals(1, eqs.size());
	assertEquals(eqs.get(0).getName(), "uno");
	assertEquals(eqs.get(0).getValue(), 1);
	assertEquals(newDiffs, diffPlugin.getDiffHighlightSelection());

	undo(program);

	eqs = program.getEquateTable().getEquates(addr("1002261"), 0);
	assertEquals(0, eqs.size());
	assertEquals(newDiffs, diffPlugin.getDiffHighlightSelection()); // For now we don't try to put diff hilights back.

	redo(program);

	eqs = program.getEquateTable().getEquates(addr("1002261"), 0);
	assertEquals(1, eqs.size());
	assertEquals(eqs.get(0).getName(), "uno");
	assertEquals(eqs.get(0).getValue(), 1);
	assertEquals(newDiffs, diffPlugin.getDiffHighlightSelection());
}
 
Example #29
Source File: DiffApply2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplyDiffsNextActionLast() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	AddressSet addrSet = new AddressSet(addr("1005e4f"), addr("1005e53"));
	setDiffSelection(addrSet);
	setLocation("1005e4f");
	assertTrue(!applyDiffsNext.isEnabled());
}
 
Example #30
Source File: FollowFlowBackwardTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testFollowAllFlowsBackFrom0xbf() {

	AddressSetView flowAddresses = getFlowsTo(0xbf, followAllFlows());

	AddressSet expectedAddresses = new AddressSet();
	expectedAddresses.add(addr(0x0), addr(0x2e));
	expectedAddresses.add(addr(0x30), addr(0x5e));
	expectedAddresses.add(addr(0x90), addr(0xbf));
	expectedAddresses.add(addr(0x5024), addr(0x5027));

	assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses));
}