Java Code Examples for ghidra.program.model.mem.Memory#removeBlock()
The following examples show how to use
ghidra.program.model.mem.Memory#removeBlock() .
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: AddressSetPropertyMapTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testDeleteBlockRange() throws Exception { Memory memory = program.getMemory(); MemoryBlock block = memory.createInitializedBlock(".test", getAddr(5), 0x20, (byte) 0xa, TaskMonitorAdapter.DUMMY_MONITOR, false); AddressSet set = new AddressSet(); set.addRange(getAddr(0), getAddr(0x10)); set.addRange(getAddr(0x20), getAddr(0x25)); set.addRange(getAddr(0x26), getAddr(0x30)); AddressSetPropertyMap pm = program.createAddressSetPropertyMap("MyMap"); pm.add(set); // remove the block memory.removeBlock(block, TaskMonitorAdapter.DUMMY_MONITOR); // [0,4], [25,30] should still exist // [5,24] should have been removed AddressSet s = new AddressSet(); s.addRange(getAddr(0), getAddr(0x4)); s.addRange(getAddr(0x25), getAddr(0x30)); AddressSet pmSet = pm.getAddressSet(); assertEquals(s, pmSet); }
Example 2
Source File: IntRangeMapTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testDeleteBlockRange() throws Exception { Memory memory = program.getMemory(); MemoryBlock block = memory.createInitializedBlock(".test", getAddr(5), 0x20, (byte) 0xa, TaskMonitorAdapter.DUMMY_MONITOR, false); AddressSet set = new AddressSet(); set.addRange(getAddr(0), getAddr(0x10)); set.addRange(getAddr(0x20), getAddr(0x25)); set.addRange(getAddr(0x26), getAddr(0x30)); IntRangeMap map = program.createIntRangeMap("MyMap"); int value = 0x11223344; map.setValue(set, value); // remove the block memory.removeBlock(block, TaskMonitorAdapter.DUMMY_MONITOR); // [0,4], [25,30] should still exist // [5,24] should have been removed AddressSet s = new AddressSet(); s.addRange(getAddr(0), getAddr(0x4)); s.addRange(getAddr(0x25), getAddr(0x30)); AddressSet mapSet = map.getAddressSet(); assertEquals(s, mapSet); }
Example 3
Source File: DeleteBlockCmd.java From ghidra with Apache License 2.0 | 5 votes |
@Override public boolean applyTo(DomainObject obj, TaskMonitor monitor) { Program program = (Program) obj; Memory mem = program.getMemory(); if (!program.hasExclusiveAccess()) { setStatusMsg("Exclusive access required"); return false; } monitor.initialize(blockAddresses.length); for (Address blockAddresse : blockAddresses) { if (monitor.isCancelled()) { break; } MemoryBlock block = mem.getBlock(blockAddresse); monitor.setMessage("Deleting block '" + block.getName() + "'..."); try { mem.removeBlock(block, monitor); } catch (LockException e) { Msg.debug(this, "Unable to delete block--do not have lock: '" + block.getName() + "'", e); } monitor.initialize(block.getSize()); } status = true; return status; }
Example 4
Source File: ProgramTreePlugin1Test.java From ghidra with Apache License 2.0 | 4 votes |
@Test public void testMemoryBlocksAddedRemoved() throws Exception { int transactionID = program.startTransaction("Test"); Memory mem = program.getMemory(); mem.createInitializedBlock(".test", getAddr(0x30), 0x12, (byte) 0, TaskMonitorAdapter.DUMMY_MONITOR, false); program.endTransaction(transactionID, true); program.flushEvents(); setTreeView("Main Tree"); expandRoot(); ProgramNode[] nodes = findNodes(".test"); assertEquals(1, nodes.length); transactionID = program.startTransaction("test"); mem.createInitializedBlock(".test.exp", getAddr(0x42), 4, (byte) 0, TaskMonitorAdapter.DUMMY_MONITOR, false); program.endTransaction(transactionID, true); program.flushEvents(); nodes = findNodes(".test.exp"); assertEquals(1, nodes.length); undo(); nodes = findNodes(".test.exp"); assertEquals(0, nodes.length); redo(); nodes = findNodes(".test.exp"); assertEquals(1, nodes.length); transactionID = program.startTransaction("test"); MemoryBlock block = mem.getBlock(getAddr(0x30)); mem.removeBlock(block, TaskMonitorAdapter.DUMMY_MONITOR); block = mem.getBlock(getAddr(0x42)); mem.removeBlock(block, TaskMonitorAdapter.DUMMY_MONITOR); program.endTransaction(transactionID, true); program.flushEvents(); nodes = findNodes(".test"); assertEquals(0, nodes.length); nodes = findNodes(".test.exp"); assertEquals(0, nodes.length); // test undo/redo undo(); nodes = findNodes(".test"); assertEquals(1, nodes.length); nodes = findNodes(".test.exp"); assertEquals(1, nodes.length); redo(); nodes = findNodes(".test"); assertEquals(0, nodes.length); nodes = findNodes(".test.exp"); assertEquals(0, nodes.length); }