Java Code Examples for ghidra.program.model.address.AddressSpace#isOverlaySpace()

The following examples show how to use ghidra.program.model.address.AddressSpace#isOverlaySpace() . 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: SymbolEntry.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void buildRangelistXML(StringBuilder res) {
	if (pcaddr == null || pcaddr.isExternalAddress()) {
		res.append("<rangelist/>");
		return;
	}
	res.append("<rangelist>");
	AddressSpace space = pcaddr.getAddressSpace();
	long off;
	if (space.isOverlaySpace()) {
		space = space.getPhysicalSpace();
		off = space.getAddress(pcaddr.getOffset()).getUnsignedOffset();
	}
	else {
		off = pcaddr.getUnsignedOffset();
	}
	res.append("<range");
	SpecXmlUtils.encodeStringAttribute(res, "space", space.getName());
	SpecXmlUtils.encodeUnsignedIntegerAttribute(res, "first", off);
	SpecXmlUtils.encodeUnsignedIntegerAttribute(res, "last", off);
	res.append("/>");
	res.append("</rangelist>\n");
}
 
Example 2
Source File: AddBlockModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateOverlayBlock() throws Exception {

	model.setBlockName(".test");
	model.setStartAddress(getAddr(0x100));
	model.setLength(100);
	model.setBlockType(MemoryBlockType.DEFAULT);
	model.setOverlay(true);
	model.setInitializedType(InitializedType.INITIALIZED_FROM_VALUE);
	model.setInitialValue(0xa);
	assertTrue(model.execute());
	MemoryBlock block = null;
	AddressSpace[] spaces = program.getAddressFactory().getAddressSpaces();
	AddressSpace ovSpace = null;
	for (AddressSpace space : spaces) {
		if (space.isOverlaySpace()) {
			ovSpace = space;
			Address blockAddr = space.getAddress(0x100);
			block = program.getMemory().getBlock(blockAddr);
			break;
		}
	}
	assertNotNull(block);
	assertEquals((byte) 0xa, block.getByte(ovSpace.getAddress(0x100)));
}
 
Example 3
Source File: AddBlockModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateOverlayBlock2() throws Exception {

	model.setBlockName(".test");
	model.setStartAddress(getAddr(0x01001000));
	model.setLength(100);
	model.setBlockType(MemoryBlockType.DEFAULT);
	model.setOverlay(true);
	model.setInitializedType(InitializedType.INITIALIZED_FROM_VALUE);
	model.setInitialValue(0xa);
	assertTrue(model.execute());
	MemoryBlock block = null;
	AddressSpace[] spaces = program.getAddressFactory().getAddressSpaces();
	AddressSpace ovSpace = null;
	for (AddressSpace space : spaces) {
		if (space.isOverlaySpace()) {
			ovSpace = space;
			Address blockAddr = space.getAddress(0x1001000);
			block = program.getMemory().getBlock(blockAddr);
			break;
		}
	}
	assertNotNull(block);
	assertEquals((byte) 0xa, block.getByte(ovSpace.getAddress(0x1001000)));
}
 
Example 4
Source File: MemoryMapProvider2Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddOverlayBlockInitialized() throws Exception {
	DockingActionIf action = getAction(plugin, "Add Block");
	performAction(action, false);

	// find the dialog for the add
	AddBlockDialog d = waitForDialogComponent(tool.getToolFrame(), AddBlockDialog.class, 2000);
	final GhidraComboBox<?> comboBox = findComponent(d.getComponent(), GhidraComboBox.class);

	final JTextField nameField =
		(JTextField) findComponentByName(d.getComponent(), "Block Name");
	final RegisterField lengthField =
		(RegisterField) findComponentByName(d.getComponent(), "Length");
	final JTextField commentField =
		(JTextField) findComponentByName(d.getComponent(), "Comment");
	final JCheckBox readCB = (JCheckBox) findComponentByName(d.getComponent(), "Read");
	final JCheckBox writeCB = (JCheckBox) findComponentByName(d.getComponent(), "Write");
	final JCheckBox executeCB = (JCheckBox) findComponentByName(d.getComponent(), "Execute");
	final JCheckBox overlayCB = (JCheckBox) findComponentByName(d.getComponent(), "Overlay");
	final JRadioButton initializedRB =
		(JRadioButton) findComponentByName(d.getComponent(), "Initialized");
	final RegisterField initialValue =
		(RegisterField) findComponentByName(d.getComponent(), "Initial Value");
	final AddressInput addrField =
		(AddressInput) findComponentByName(d.getComponent(), "Source Addr");
	assertNotNull(addrField);
	assertTrue(!addrField.isShowing());

	final JButton okButton = findButton(d.getComponent(), "OK");

	SwingUtilities.invokeAndWait(() -> {
		comboBox.setSelectedItem(MemoryBlockType.DEFAULT);
		overlayCB.setSelected(true);
		overlayCB.getActionListeners()[0].actionPerformed(null);
		nameField.setText(".test");
		lengthField.setText("0x100");
		commentField.setText("this is a block test");
		initialValue.setText("0xa");
	});

	SwingUtilities.invokeAndWait(() -> {
		pressButton(executeCB);
	});

	int x = 1;
	int y = 1;
	clickMouse(initializedRB, 1, x, y, 1, 0);

	assertTrue(okButton.isEnabled());
	assertTrue(readCB.isSelected());
	assertTrue(writeCB.isSelected());
	assertTrue(executeCB.isSelected());

	SwingUtilities.invokeAndWait(() -> okButton.getActionListeners()[0].actionPerformed(null));
	program.flushEvents();
	waitForPostedSwingRunnables();

	MemoryBlock block = null;
	AddressSpace[] spaces = program.getAddressFactory().getAddressSpaces();
	for (AddressSpace space : spaces) {
		if (space.isOverlaySpace()) {
			Address blockAddr = space.getAddress(0);
			block = memory.getBlock(blockAddr);
			break;
		}
	}

	assertNotNull(block);
	MemoryBlock[] blocks = program.getMemory().getBlocks();
	int row = blocks.length - 1;
	assertEquals(".test", model.getValueAt(row, MemoryMapModel.NAME));
	assertEquals("00000000", model.getValueAt(row, MemoryMapModel.START));
	assertEquals(".test::00000000", block.getStart().toString());
	assertEquals("000000ff", model.getValueAt(row, MemoryMapModel.END));
	assertEquals(".test::000000ff", block.getEnd().toString());
	assertEquals("0x100", model.getValueAt(row, MemoryMapModel.LENGTH));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.READ));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.WRITE));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.EXECUTE));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.OVERLAY));
	assertEquals(
		MemoryBlockType.DEFAULT.toString(),
		model.getValueAt(row, MemoryMapModel.BLOCK_TYPE));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.INIT));
	assertEquals("", model.getValueAt(row, MemoryMapModel.SOURCE));
	assertEquals("this is a block test", model.getValueAt(row, MemoryMapModel.COMMENT));

	assertEquals(0xa, memory.getByte(block.getStart()));
}
 
Example 5
Source File: MemoryMapProvider2Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddOverlayBlockUninitialized() throws Exception {
	DockingActionIf action = getAction(plugin, "Add Block");
	performAction(action, false);

	// find the dialog for the add
	AddBlockDialog d = waitForDialogComponent(tool.getToolFrame(), AddBlockDialog.class, 2000);
	final GhidraComboBox<?> comboBox = findComponent(d.getComponent(), GhidraComboBox.class);

	final JTextField nameField =
		(JTextField) findComponentByName(d.getComponent(), "Block Name");
	final RegisterField lengthField =
		(RegisterField) findComponentByName(d.getComponent(), "Length");
	final JTextField commentField =
		(JTextField) findComponentByName(d.getComponent(), "Comment");
	final JCheckBox readCB = (JCheckBox) findComponentByName(d.getComponent(), "Read");
	final JCheckBox writeCB = (JCheckBox) findComponentByName(d.getComponent(), "Write");
	final JCheckBox executeCB = (JCheckBox) findComponentByName(d.getComponent(), "Execute");
	final JCheckBox overlayCB = (JCheckBox) findComponentByName(d.getComponent(), "Overlay");

	final JRadioButton uninitRB =
		(JRadioButton) findComponentByName(d.getComponent(), "Uninitialized");
	final AddressInput addrField =
		(AddressInput) findComponentByName(d.getComponent(), "Source Addr");
	assertNotNull(addrField);
	assertTrue(!addrField.isShowing());

	final JButton okButton = findButton(d.getComponent(), "OK");

	SwingUtilities.invokeAndWait(() -> {
		comboBox.setSelectedItem(MemoryBlockType.DEFAULT);
		overlayCB.setSelected(true);
		overlayCB.getActionListeners()[0].actionPerformed(null);
		nameField.setText(".test");
		lengthField.setText("0x100");
		commentField.setText("this is a block test");
		pressButton(executeCB);
		uninitRB.setSelected(true);
		uninitRB.getActionListeners()[0].actionPerformed(null);
	});
	assertTrue(okButton.isEnabled());
	assertTrue(readCB.isEnabled());
	assertTrue(writeCB.isEnabled());
	assertTrue(executeCB.isEnabled());

	SwingUtilities.invokeAndWait(() -> okButton.getActionListeners()[0].actionPerformed(null));
	program.flushEvents();
	waitForPostedSwingRunnables();

	MemoryBlock block = null;
	AddressSpace[] spaces = program.getAddressFactory().getAddressSpaces();
	for (AddressSpace space : spaces) {
		if (space.isOverlaySpace()) {
			Address blockAddr = space.getAddress(0);
			block = memory.getBlock(blockAddr);
			break;
		}
	}

	assertNotNull(block);

	MemoryBlock[] blocks = program.getMemory().getBlocks();
	int row = blocks.length - 1;
	assertEquals(".test", model.getValueAt(row, MemoryMapModel.NAME));
	assertEquals("00000000", model.getValueAt(row, MemoryMapModel.START));
	assertEquals(".test::00000000", block.getStart().toString());
	assertEquals("000000ff", model.getValueAt(row, MemoryMapModel.END));
	assertEquals(".test::000000ff", block.getEnd().toString());
	assertEquals("0x100", model.getValueAt(row, MemoryMapModel.LENGTH));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.READ));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.WRITE));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.EXECUTE));
	assertEquals(Boolean.TRUE, model.getValueAt(row, MemoryMapModel.OVERLAY));
	assertEquals(
		MemoryBlockType.DEFAULT.toString(),
		model.getValueAt(row, MemoryMapModel.BLOCK_TYPE));
	assertEquals(Boolean.FALSE, model.getValueAt(row, MemoryMapModel.INIT));
	assertEquals("", model.getValueAt(row, MemoryMapModel.SOURCE));
	assertEquals("this is a block test", model.getValueAt(row, MemoryMapModel.COMMENT));

	try {
		memory.getByte(block.getStart());
		Assert.fail("Should have gotten MemoryAccessException!");
	}
	catch (MemoryAccessException e) {
		// expected
	}
}