Java Code Examples for ghidra.program.model.address.AddressSet#addRange()

The following examples show how to use ghidra.program.model.address.AddressSet#addRange() . 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: 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 2
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 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: 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 5
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Test that ProgramDiff can determine that function default stack params are
 * different.
 */
@Test
public void testFunctionDefaultStackParamDiff() throws Exception {

	// 0x1002cf5: created default stack param in p2.
	int transactionID = p2.startTransaction("Test Transaction");
	Function function = p2.getFunctionManager().getFunctionAt(addr(p2, 0x1002cf5));
	Variable var = new ParameterImpl("variable", DataType.DEFAULT, 0x1c, p2);
	function.addParameter(var, SourceType.USER_DEFINED);
	p2.endTransaction(transactionID, true);

	programDiff = new ProgramDiff(p1, p2);
	programDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.FUNCTION_DIFFS));
	AddressSet diffAs = new AddressSet();
	diffAs.addRange(addr(0x1002cf5), addr(0x1002cf5));
	assertEquals(diffAs, programDiff.getDifferences(programDiff.getFilter(), null));
}
 
Example 6
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Test that ProgramDiff can determine that function parameters are
 * different.
 */
@Test
public void testFunctionParamsDiff() throws Exception {

	// 0x01002cf5: removed parm_2 from p1.
	int transactionID = p1.startTransaction("Test Transaction");
	Function function = p1.getFunctionManager().getFunctionAt(addr(p1, 0x1002cf5));
	function.removeParameter(0);
	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 7
Source File: RegisterPluginScreenShots.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetRegisterValues() {
	goToListing(0x401cbd, OperandFieldFactory.FIELD_NAME, true);

	AddressSet addrs = new AddressSet();
	addrs.addRange(addr(0x401c9c), addr(0x401c9e));
	addrs.addRange(addr(0x401ca8), addr(0x401cab));
	addrs.addRange(addr(0x401cbd), addr(0x401cc1));
	makeSelection(addrs);

	DockingActionIf setAction = getAction(plugin, "Set Register Values");
	performAction(setAction, false);

	captureDialog(700, 300);
}
 
Example 8
Source File: ViewStringsTableModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public ProgramSelection getProgramSelection(int[] rows) {
	AddressSet set = new AddressSet();
	for (int element : rows) {
		ProgramLocation progLoc = filteredData.get(element);
		Data data = getProgram().getListing().getDataContaining(progLoc.getAddress());
		data = data.getComponent(progLoc.getComponentPath());
		set.addRange(data.getMinAddress(), data.getMaxAddress());
	}
	return new ProgramSelection(set);
}
 
Example 9
Source File: AddEditDialoglTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createEntryFunction() throws Exception {
	Symbol s = getUniqueSymbol(program, "entry", null);
	Function f = program.getListing().getFunctionAt(s.getAddress());
	if (f == null) {
		Address addr = s.getAddress();
		AddressSet body = new AddressSet(addr, addr.getNewAddress(0x010065cc));
		body.addRange(addr.getNewAddress(0x10065a4), addr.getNewAddress(0x010065cc));
		CreateFunctionCmd cmd =
			new CreateFunctionCmd(null, addr, body, SourceType.USER_DEFINED);
		assertTrue(tool.execute(cmd, program));
	}
}
 
Example 10
Source File: DoARMDisassemble.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {

	Processor armProcessor = Processor.findOrPossiblyCreateProcessor("ARM");
	if (currentProgram == null ||
		!currentProgram.getLanguage().getProcessor().equals(armProcessor)) {
		Msg.showError(this, null, "Script Error",
			"Script only supports programs with ARM language");
		return;
	}

	RegisterValue armMode = null;
	Register tmodeReg = currentProgram.getProgramContext().getRegister("TMode");
	if (tmodeReg != null) {
		armMode = new RegisterValue(tmodeReg, BigInteger.ZERO);
	}

	AddressSet set = new AddressSet();
	if (currentSelection == null || currentSelection.isEmpty()) {
		set.addRange(currentAddress, currentAddress);
	}
	else {
		set.add(currentSelection);
	}

	DisassembleCommand cmd = new DisassembleCommand(set, null, true);
	cmd.setInitialContext(armMode);
	cmd.applyTo(currentProgram, monitor);
}
 
Example 11
Source File: ProgramDiff3Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Test that ProgramDiff can determine the function names are different.
 */
@Test
public void testFunctionNameDiff() throws Exception {

	// 0x010048a3: function names differ.
	// 0x01002239: function names same.
	int transactionID = p1.startTransaction("Test Transaction");
	FunctionManager functionManager1 = p1.getFunctionManager();
	Function function1 = functionManager1.getFunctionAt(addr(0x010048a3));
	assertNotNull(function1);
	function1.setName("MyFunction48a3", SourceType.USER_DEFINED);
	function1 = functionManager1.getFunctionAt(addr(0x01002239));
	assertNotNull(function1);
	function1.setName("Function2239", SourceType.USER_DEFINED);
	p1.endTransaction(transactionID, true);

	int transactionID2 = p2.startTransaction("Test Transaction");
	FunctionManager functionManager2 = p2.getFunctionManager();
	Function function2 = functionManager2.getFunctionAt(addr(0x010048a3));
	assertNotNull(function2);
	function2.setName("Other48a3", SourceType.USER_DEFINED);
	function2 = functionManager2.getFunctionAt(addr(0x01002239));
	assertNotNull(function2);
	function2.setName("Function2239", SourceType.USER_DEFINED);
	p2.endTransaction(transactionID2, true);

	programDiff = new ProgramDiff(p1, p2);
	programDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.SYMBOL_DIFFS));
	AddressSet diffAs = new AddressSet();
	diffAs.addRange(addr(0x010048a3), addr(0x010048a3));
	assertEquals(diffAs, programDiff.getDifferences(programDiff.getFilter(), null));
}
 
Example 12
Source File: StringTableSearchTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchSelection() throws Exception {
	// select an area known to have some strings
	AddressSet set = new AddressSet();
	set.addRange(addr(0x405d80), addr(0x405dc0));

	// select the address set
	tool.firePluginEvent(
		new ProgramSelectionPluginEvent("Test", new ProgramSelection(set), program));

	waitForPostedSwingRunnables();

	dialog = getDialog();
	Container container = dialog.getComponent();

	// check to make sure the search selection button is checked and enabled
	JRadioButton rb = (JRadioButton) findButton(container, "Search Selection");
	assertTrue(rb.isSelected());
	assertTrue(rb.isEnabled());

	StringTableProvider provider = performSearch();
	StringTableModel model = (StringTableModel) getInstanceField("stringModel", provider);
	toggleDefinedStateButtons(provider, false, true, false, false);
	waitForTableModel(model);

	assertEquals(3, model.getRowCount());

	// test the results size and that the correct strings are found
	int row = findRow(model, addr(0x405d81));
	assertEquals("00405d81", getModelValue(model, row, addressColumnIndex).toString());
	row = findRow(model, addr(0x405d9c));
	assertEquals("00405d9c", getModelValue(model, row, addressColumnIndex).toString());
	row = findRow(model, addr(0x405db4));
	assertEquals("00405db4", getModelValue(model, row, addressColumnIndex).toString());
}
 
Example 13
Source File: StringTableSearchTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testIncludeAlignmentBytes() throws Exception {
	/***************************************************************************/
	/* TEST 6 - test include alignment nulls with various sized alignments */
	/***********************************************************************/
	final AddressSet set = new AddressSet();
	set.addRange(addr(0x404328), addr(0x404375));

	// select the address set
	tool.firePluginEvent(
		new ProgramSelectionPluginEvent("Test", new ProgramSelection(set), program));

	waitForPostedSwingRunnables();

	dialog = getDialog();
	Container container = dialog.getComponent();

	// check to make sure the search selection button is checked and enabled
	JRadioButton rb = (JRadioButton) findButton(container, "Search Selection");
	assertTrue(rb.isSelected());
	assertTrue(rb.isEnabled());

	setMinStringFieldValue(dialog, 2);

	StringTableProvider provider = performSearch();
	StringTableModel model = (StringTableModel) getInstanceField("stringModel", provider);
	GhidraTable table = (GhidraTable) getInstanceField("table", provider);

	toggleDefinedStateButtons(provider, false, true, false, false);
	waitForTableModel(model);

	// verify that rows  points to the correct address
	assertEquals("00404328", getModelValue(model, 0, addressColumnIndex).toString());
	assertEquals("00404350", getModelValue(model, 1, addressColumnIndex).toString());
	assertEquals("00404354", getModelValue(model, 2, addressColumnIndex).toString());
	assertEquals("00404370", getModelValue(model, 3, addressColumnIndex).toString());
	selectRows(table, addr(0x404328), addr(0x404350), addr(0x404354), addr(0x404370));

	// select the Include Alignment Nulls option
	JCheckBox includeAlignNullsCB =
		(JCheckBox) findButton(provider.getComponent(), "Include Alignment Nulls");
	assertTrue(includeAlignNullsCB.isEnabled());
	assertTrue(!includeAlignNullsCB.isSelected());
	includeAlignNullsCB.setSelected(true);

	setAlignmentValue(provider, 4);

	DockingAction makeStringAction =
		(DockingAction) getInstanceField("makeStringAction", provider);

	waitForTableModel(model);

	performAction(makeStringAction, model);

	//Test that the correct amount of bytes get sucked up with the alignment option
	Data d = listing.getDataAt(addr(0x404370));
	assertEquals(4, d.getLength());

	d = listing.getDataAt(addr(0x404328));
	assertEquals(40, d.getLength());

	d = listing.getDataAt(addr(0x404350));
	assertEquals(4, d.getLength());

	d = listing.getDataAt(addr(0x404354));
	assertEquals(28, d.getLength());

}
 
Example 14
Source File: StringTable_BE_Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testSearchSelection() throws Exception {
	final AddressSet set = new AddressSet();
	set.addRange(addr(0x100), addr(0x1000));

	// select the address set
	cbPlugin.firePluginEvent(new ProgramSelectionPluginEvent(cbPlugin.getName(),
		new ProgramSelection(set), program));

	SearchStringDialog dialog = getDialog();

	// turn off null Terminate box
	JCheckBox cb = (JCheckBox) findButton(dialog.getComponent(), "Require Null Termination");
	cb.setSelected(false);

	pressButtonByText(dialog.getComponent(), "Search");

	@SuppressWarnings("unchecked")
	StringTableProvider provider =
		((List<StringTableProvider>) getInstanceField("transientProviders", plugin)).get(0);
	StringTableModel model = (StringTableModel) getInstanceField("stringModel", provider);
	GhidraTable table = (GhidraTable) getInstanceField("table", provider);
	waitForTableModel(model);

	setAutoLabelCheckbox(provider, true);

	// test the results size
	assertEquals(4, model.getRowCount());

	// test the first and last ones
	assertEquals(addr(0x100), addressCell(model, 0));
	assertEquals(addr(0x400), addressCell(model, 3));

	// ********************** test Make Unicode String
	// select row for address 400
	Address address = addr(0x400);
	selectRows(table, address);

	// make string
	DockingAction makeStringAction =
		(DockingAction) getInstanceField("makeStringAction", provider);
	performAction(makeStringAction, true);
	waitForTableModel(model);

	// test that the string was actually made correctly
	// test that the string was actually made correctly
	Data d = program.getListing().getDataAt(addr(0x400));
	assertEquals(12, d.getLength());

	String str = (String) d.getValue();
	assertEquals("abcdef", str);

	DataType dt = d.getBaseDataType();
	assertEquals("unicode", dt.getName());

	// test that the label was made correctly
	Symbol sym = program.getSymbolTable().getPrimarySymbol(addr(0x400));
	assertEquals("u_abcdef@00000400", sym.getName());

	selectRows(table, address);
	int selectedRow = table.getSelectedRow();

	// test that the table was updated with the label and preview
	assertEquals("u_abcdef@00000400", labelCell(model, selectedRow));

	CodeUnitTableCellData value = previewCell(model, selectedRow);
	assertEquals("unicode u\"abcdef\"", value.getDisplayString());

}
 
Example 15
Source File: AbstractScreenShotGenerator.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public void makeSelection(long start, long end) {
	AddressSet addressSet = new AddressSet();
	addressSet.addRange(addr(start), addr(end));
	makeSelection(addressSet);
}
 
Example 16
Source File: DiffTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testEmptyViewDiff() throws Exception {

	programBuilderDiffTest1.createMemory("d4", "0x400", 0x100);
	programBuilderDiffTest2.createMemory("d2", "0x200", 0x100);

	programBuilderDiffTest2.createComment("0x01008000", "My comment", CodeUnit.EOL_COMMENT);
	programBuilderDiffTest2.createComment("0x01008607", "My comment", CodeUnit.EOL_COMMENT);
	programBuilderDiffTest2.createComment("0x01009943", "My comment", CodeUnit.EOL_COMMENT);
	programBuilderDiffTest2.createComment("0x0100a001", "My comment", CodeUnit.EOL_COMMENT);

	openDiff(diffTestP1, diffTestP2);
	JTree tree = getProgramTree();
	selectTreeNodeByText(tree, "DiffTestPgm1");
	performAction(removeView, true);
	AddressSet viewSet = new AddressSet();
	assertEquals(viewSet, cb.getView());
	topOfFile(fp1);
	assertNull(cb.getCurrentAddress());
	bottomOfFile(fp1);
	assertNull(cb.getCurrentAddress());
	fp1.getHeight();
	assertEquals(0, fp1.getLayoutModel().getNumIndexes().intValue());
	assertEquals(0, fp2.getLayoutModel().getNumIndexes().intValue());

	AddressSet diffSet = new AddressSet(getSetupAllDiffsSet());
	diffSet.add(addr("0x01008000"));
	diffSet.add(addr("0x01008607"));
	diffSet.add(addr("0x01009943"));
	diffSet.add(addr("0x0100a001"));
	assertEquals(new ProgramSelection(diffSet), diffPlugin.getDiffHighlightSelection());
	assertEquals(addr("100"), diffPlugin.getCurrentAddress());
	assertEquals(addr("100"), getDiffAddress());

	// Next Diff should add .text to the view
	invokeLater(nextDiff);

	viewSet.addRange(addr("1001000"), addr("10075ff"));
	assertEquals(addr("1001034"), cb.getCurrentAddress());
	assertEquals(addr("1001034"), getDiffAddress());
	assertEquals(cb.getCurrentSelection(),
		new ProgramSelection(addr("1001034"), addr("1001034")));
	assertEquals(viewSet, cb.getView());

	// bottom of View .text
	bottomOfFile(fp1);
	assertEquals(addr("10075ff"), cb.getCurrentAddress());
	assertEquals(addr("10075ff"), getDiffAddress());

	// Next Diff should add .data to the view
	invokeLater(nextDiff);
	waitForSwing();
	viewSet.addRange(addr("1008000"), addr("10085ff"));
	assertEquals(addr("1008000"), cb.getCurrentAddress());
	assertEquals(addr("1008000"), getDiffAddress());
	assertEquals(cb.getCurrentSelection(),
		new ProgramSelection(addr("1008000"), addr("1008000")));
	assertEquals(viewSet, cb.getView());

	// bottom of View .data
	bottomOfFile(fp1);
	assertEquals(addr("10085ff"), cb.getCurrentAddress());
	assertEquals(addr("10085ff"), getDiffAddress());

	// Next Diff should add .datau to the view
	invokeLater(nextDiff);

	viewSet.addRange(addr("1008600"), addr("1009943"));
	assertEquals(addr("1008607"), cb.getCurrentAddress());
	assertEquals(addr("1008607"), getDiffAddress());
	assertEquals(cb.getCurrentSelection(),
		new ProgramSelection(addr("1008607"), addr("1008607")));
	assertEquals(viewSet, cb.getView());

	// bottom of View .datau
	bottomOfFile(fp1);
	assertEquals(addr("1009943"), cb.getCurrentAddress());
	assertEquals(addr("1009943"), getDiffAddress());

	// Next Diff should add .rsrc to the view
	invokeLater(nextDiff);

	viewSet.addRange(addr("100a000"), addr("100f3ff"));
	assertEquals(addr("100a001"), cb.getCurrentAddress());
	assertEquals(addr("100a001"), getDiffAddress());
	assertEquals(cb.getCurrentSelection(),
		new ProgramSelection(addr("100a001"), addr("100a001")));
	assertEquals(viewSet, cb.getView());
}
 
Example 17
Source File: GhidraScriptRealProgramTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testFindBytesAcrossGap() throws Exception {
	GhidraScript script = getScript();

	AddressSet set = new AddressSet();

	//Match charAt 0x010064db, 0x010064df 
	set.addRange(script.toAddr(0x10064d5), script.toAddr(0x010064db));
	set.addRange(script.toAddr(0x010064df), script.toAddr(0x010064e3));

	String byteString = "\\x51\\x52";

	Address[] results = script.findBytes(set, byteString, 20, 1, true);

	assertEquals(1, results.length);
	assertEquals(script.toAddr(0x010064db), results[0]);

}
 
Example 18
Source File: CopyPasteCommentsTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testPasteNonContiguousSelection() throws Exception {
	// in Browser(1) add a pre comment at 331
	CodeUnit cu = programOne.getListing().getCodeUnitAt(addr(programOne, 0x331));
	int transactionID = programOne.startTransaction("test");
	cu.setComment(CodeUnit.PRE_COMMENT, "my pre comment for this test");
	programOne.endTransaction(transactionID, true);
	waitForSwing();

	// in Browser(2) select 031b and 0331
	goTo(toolTwo, 0x031b);

	AddressSet set = new AddressSet();
	set.addRange(addr(programTwo, 0x31b), addr(programTwo, 0x31d));
	set.addRange(addr(programTwo, 0x331), addr(programTwo, 0x333));

	makeSelection(toolTwo, programTwo, set);

	copyToolTwoLabels();

	// in Browser(1) go to 31b
	goTo(toolOne, 0x31b);

	pasteToolOne();

	// verify the labels are copied
	assertNull(
		programOne.getSymbolTable().getSymbol("LAB_0331", addr(programOne, 0x0331), null));
	Symbol symbol = getUniqueSymbol(programOne, "RSTOR()", null);
	assertNotNull(symbol);
	assertEquals(addr(programOne, 0x31b), symbol.getAddress());
	assertNull(
		programOne.getSymbolTable().getSymbol("LAB_0331", addr(programOne, 0x0331), null));
	symbol = getUniqueSymbol(programOne, "RSR10", null);
	assertNotNull(symbol);
	assertEquals(addr(programOne, 0x331), symbol.getAddress());

	// verify pre comment at 331 remains unaffected
	cu = programOne.getListing().getCodeUnitAt(addr(programOne, 0x331));
	assertEquals("my pre comment for this test", cu.getComment(CodeUnit.PRE_COMMENT));

	// verify browser field

	cb.goToField(addr(programOne, 0x0331), LabelFieldFactory.FIELD_NAME, 0, 0);
	ListingTextField f = (ListingTextField) cb.getCurrentField();
	assertEquals("RSR10", f.getText());

	cb.goToField(addr(programOne, 0x031b), LabelFieldFactory.FIELD_NAME, 0, 0);
	f = (ListingTextField) cb.getCurrentField();
	assertEquals("RSTOR()", f.getText());

	cb.goToField(addr(programOne, 0x0331), "Pre-Comment", 0, 0);
	f = (ListingTextField) cb.getCurrentField();
	assertEquals("my pre comment for this test", f.getText());

	undo(programOne);

	cb.goToField(addr(programOne, 0x0331), LabelFieldFactory.FIELD_NAME, 0, 0);
	f = (ListingTextField) cb.getCurrentField();
	assertEquals(programOne.getSymbolTable().getSymbol("LAB_00000331", addr(programOne, 0x0331),
		null).getName(), f.getText());

	cb.goToField(addr(programOne, 0x031b), LabelFieldFactory.FIELD_NAME, 0, 0);
	f = (ListingTextField) cb.getCurrentField();
	assertEquals(programOne.getSymbolTable().getSymbol("LAB_0000031b", addr(programOne, 0x031b),
		null).getName(), f.getText());

	redo(programOne);

	cb.goToField(addr(programOne, 0x0331), LabelFieldFactory.FIELD_NAME, 0, 0);
	f = (ListingTextField) cb.getCurrentField();
	assertEquals("RSR10", f.getText());

	cb.goToField(addr(programOne, 0x031b), LabelFieldFactory.FIELD_NAME, 0, 0);
	f = (ListingTextField) cb.getCurrentField();
	assertEquals("RSTOR()", f.getText());
}
 
Example 19
Source File: StringTableSearchTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testIncludeAlignmentBytesPascal() throws Exception {
	/***************************************************************************/
	/* TEST 6 - test include alignment nulls with various sized alignments */
	/***********************************************************************/
	final AddressSet set = new AddressSet();
	set.addRange(addr(0x405d99), addr(0x405daa));

	// select the address set
	tool.firePluginEvent(
		new ProgramSelectionPluginEvent("Test", new ProgramSelection(set), program));
	waitForPostedSwingRunnables();

	dialog = getDialog();

	// turn on pascal
	JCheckBox cb = (JCheckBox) findButton(dialog.getComponent(), "Pascal Strings");
	cb.setSelected(true);

	StringTableProvider provider = performSearch();
	StringTableModel model = (StringTableModel) getInstanceField("stringModel", provider);
	GhidraTable table = (GhidraTable) getInstanceField("table", provider);
	toggleDefinedStateButtons(provider, false, true, false, false);
	waitForTableModel(model);

	// verify that rows  points to the correct address
	assertEquals("00405d9a", getModelValue(model, 0, addressColumnIndex).toString());

	selectRow(table, 0);

	// select the Include Alignment Nulls option
	JCheckBox includeAlignNullsCB =
		(JCheckBox) getInstanceField("addAlignmentBytesCheckbox", provider);
	includeAlignNullsCB.setSelected(true);
	setAlignmentValue(provider, 2);

	// make string
	DockingAction makeStringAction =
		(DockingAction) getInstanceField("makeStringAction", provider);
	performAction(makeStringAction, model);

	//Test that p_string made with one align byte after it
	Data d = listing.getDataAt(addr(0x405d9a));
	assertEquals(9, d.getLength());
	d = listing.getDataAt(addr(0x405da3));
	assertEquals(1, d.getLength());

}
 
Example 20
Source File: SearchTextPlugin1Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void searchSelectionInFunction(String buttonText) throws Exception {
	// make a selection
	final AddressSet set = new AddressSet();
	set.addRange(getAddr(0x01002cf0), getAddr(0x01002cf8));
	tool.firePluginEvent(new ProgramSelectionPluginEvent(tableServicePlugin.getName(),
		new ProgramSelection(set), program));

	waitForSwing();

	assertTrue(
		cbPlugin.goToField(getAddr(0x1002cf5), VariableTypeFieldFactory.FIELD_NAME, 0, 3));
	SearchTextDialog dialog = getDialog();
	JComponent container = dialog.getComponent();
	JTextField tf = findTextField(container);

	selectRadioButton(container, buttonText);
	selectCheckBox(container, "Functions");
	setText(tf, "param");

	searchOnce(tf);
	waitForSearchTasks(dialog);

	cbPlugin.updateNow();

	ProgramLocation loc = cbPlugin.getCurrentLocation();
	assertEquals(getAddr(0x1002cf5), loc.getAddress());
	assertTrue(loc instanceof VariableNameFieldLocation);
	assertEquals("param_1", ((VariableNameFieldLocation) loc).getName());

	//
	// Search three more times, then go backwards
	//
	JButton searchButton = findButtonByText(container, "Next");
	pressSearchButton(dialog, searchButton);

	loc = cbPlugin.getCurrentLocation();
	assertEquals("param_2", ((VariableNameFieldLocation) loc).getName());

	pressSearchButton(dialog, searchButton);

	loc = cbPlugin.getCurrentLocation();
	assertEquals("param_3", ((VariableNameFieldLocation) loc).getName());

	pressSearchButton(dialog, searchButton);

	loc = cbPlugin.getCurrentLocation();
	assertEquals("param_4", ((VariableNameFieldLocation) loc).getName());

	searchButton = findButtonByText(container, "Previous");
	pressSearchButton(dialog, searchButton);

	// Unusual code alert!  Doing a reverse above triggers an odd condition where the next
	// action in the plugin is actually processed twice--yes twice!...so wait again
	dialog.getTaskScheduler().waitForCurrentTask();
	cbPlugin.updateNow();

	loc = cbPlugin.getCurrentLocation();
	assertEquals("param_3", ((VariableNameFieldLocation) loc).getName());

	pressSearchButton(dialog, searchButton);

	loc = cbPlugin.getCurrentLocation();
	assertEquals("param_2", ((VariableNameFieldLocation) loc).getName());

	pressSearchButton(dialog, searchButton);

	loc = cbPlugin.getCurrentLocation();
	assertEquals("param_1", ((VariableNameFieldLocation) loc).getName());
}