mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-6-5-24--SQUASHED'
This commit is contained in:
commit
4031dca062
9 changed files with 139 additions and 223 deletions
|
@ -140,8 +140,8 @@ public class DebuggerCopyActionsPluginScreenShots extends GhidraScreenShotGenera
|
|||
listingProvider.requestFocus();
|
||||
waitForSwing();
|
||||
|
||||
listingProvider.setSelection(
|
||||
new ProgramSelection(tb.trace.getMemoryManager().getRegionsAddressSet(snap)));
|
||||
runSwing(() -> listingProvider.setSelection(
|
||||
new ProgramSelection(tb.trace.getMemoryManager().getRegionsAddressSet(snap))));
|
||||
|
||||
waitForCondition(() -> copyPlugin.actionCopyIntoCurrentProgram.isEnabled());
|
||||
performAction(copyPlugin.actionCopyIntoCurrentProgram, false);
|
||||
|
|
|
@ -282,9 +282,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
createAndOpenTrace();
|
||||
TraceThread thread1;
|
||||
TraceThread thread2;
|
||||
DebuggerListingProvider extraProvider = SwingExecutorService.LATER
|
||||
.submit(() -> listingPlugin.createListingIfMissing(PCLocationTrackingSpec.INSTANCE,
|
||||
true))
|
||||
DebuggerListingProvider extraProvider = SwingExecutorService.LATER.submit(
|
||||
() -> listingPlugin.createListingIfMissing(PCLocationTrackingSpec.INSTANCE, true))
|
||||
.get();
|
||||
try (Transaction tx = tb.startTransaction()) {
|
||||
DBTraceMemoryManager memory = tb.trace.getMemoryManager();
|
||||
|
@ -754,9 +753,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
waitRecorder(recorder);
|
||||
|
||||
buf.clear();
|
||||
assertEquals(data.length,
|
||||
trace.getMemoryManager()
|
||||
.getBytes(recorder.getSnap(), addr(trace, 0x55550000), buf));
|
||||
assertEquals(data.length, trace.getMemoryManager()
|
||||
.getBytes(recorder.getSnap(), addr(trace, 0x55550000), buf));
|
||||
assertArrayEquals(data, buf.array());
|
||||
}));
|
||||
}
|
||||
|
@ -803,9 +801,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
assertEquals(traceManager.getCurrentView(), listingProvider.getProgram());
|
||||
assertEquals("(nowhere)", listingProvider.locationLabel.getText());
|
||||
|
||||
DebuggerListingProvider extraProvider =
|
||||
runSwing(() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE,
|
||||
false));
|
||||
DebuggerListingProvider extraProvider = runSwing(
|
||||
() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, false));
|
||||
waitForSwing();
|
||||
assertEquals(traceManager.getCurrentView(), extraProvider.getProgram());
|
||||
assertEquals("(nowhere)", extraProvider.locationLabel.getText());
|
||||
|
@ -951,8 +948,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
() -> assertEquals(tb.addr(0x00401234), listingProvider.getLocation().getAddress()));
|
||||
|
||||
setActionStateWithTrigger(listingProvider.actionTrackLocation,
|
||||
SPLocationTrackingSpec.INSTANCE,
|
||||
EventTrigger.GUI_ACTION);
|
||||
SPLocationTrackingSpec.INSTANCE, EventTrigger.GUI_ACTION);
|
||||
waitForSwing();
|
||||
waitForPass(
|
||||
() -> assertEquals(tb.addr(0x1fff8765), listingProvider.getLocation().getAddress()));
|
||||
|
@ -1077,8 +1073,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
|
||||
performAction(listingProvider.actionSyncSelectionFromStaticListing,
|
||||
codeProvider.getActionContext(null), true);
|
||||
assertEquals(tb.set(tb.range(0x00401234, 0x00404321)),
|
||||
listingPlugin.getCurrentSelection());
|
||||
assertEquals(tb.set(tb.range(0x00401234, 0x00404321)), listingPlugin.getCurrentSelection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1104,9 +1099,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
traceManager.activateThread(thread1);
|
||||
|
||||
// NOTE: Action does not exist for main dynamic listing
|
||||
DebuggerListingProvider extraProvider =
|
||||
runSwing(() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE,
|
||||
true));
|
||||
DebuggerListingProvider extraProvider = runSwing(
|
||||
() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, true));
|
||||
waitForSwing();
|
||||
assertTrue(extraProvider.actionFollowsCurrentThread.isEnabled());
|
||||
assertTrue(extraProvider.actionFollowsCurrentThread.isSelected());
|
||||
|
@ -1150,7 +1144,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
// Still
|
||||
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
|
||||
|
||||
listingProvider.setSelection(sel);
|
||||
runSwing(() -> listingProvider.setSelection(sel));
|
||||
waitForSwing();
|
||||
// Still
|
||||
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
|
||||
|
@ -1172,7 +1166,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
// Action is still disabled, because it requires a selection
|
||||
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
|
||||
|
||||
listingProvider.setSelection(sel);
|
||||
runSwing(() -> listingProvider.setSelection(sel));
|
||||
waitForSwing();
|
||||
// Now, it should be enabled
|
||||
assertTrue(listingProvider.actionRefreshSelectedMemory.isEnabled());
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
package ghidra.app.plugin.core.debug.gui.memory;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -384,7 +383,8 @@ public class DebuggerRegionsProviderLegacyTest extends AbstractGhidraHeadedDebug
|
|||
assertEquals(region, row.getRegion());
|
||||
assertFalse(tb.trace.getProgramView().getMemory().isEmpty());
|
||||
|
||||
listing.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321))));
|
||||
runSwing(() -> listing
|
||||
.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321)))));
|
||||
waitForPass(() -> assertEquals(tb.set(tb.range(0x00401234, 0x00404321)),
|
||||
new AddressSet(listing.getSelection())));
|
||||
|
||||
|
|
|
@ -149,14 +149,14 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
assertEquals(size, provider.panel.getAllItems().size());
|
||||
}
|
||||
|
||||
protected void assertRow(int position, Object object, String name, Address start,
|
||||
Address end, long length, String flags) {
|
||||
protected void assertRow(int position, Object object, String name, Address start, Address end,
|
||||
long length, String flags) {
|
||||
ValueRow row = provider.panel.getAllItems().get(position);
|
||||
var tableModel = QueryPanelTestHelper.getTableModel(provider.panel);
|
||||
GhidraTable table = QueryPanelTestHelper.getTable(provider.panel);
|
||||
DynamicTableColumn<ValueRow, ?, Trace> nameCol = QueryPanelTestHelper
|
||||
.getColumnByNameAndType(tableModel, table, "Name", ValueRow.class)
|
||||
.column();
|
||||
DynamicTableColumn<ValueRow, ?, Trace> nameCol =
|
||||
QueryPanelTestHelper.getColumnByNameAndType(tableModel, table, "Name", ValueRow.class)
|
||||
.column();
|
||||
DynamicTableColumn<ValueRow, ?, Trace> startCol = QueryPanelTestHelper
|
||||
.getColumnByNameAndType(tableModel, table, "Start", ValueProperty.class)
|
||||
.column();
|
||||
|
@ -474,8 +474,8 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
|
||||
waitForPass(() -> {
|
||||
assertTableSize(1);
|
||||
assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000),
|
||||
tb.addr(0x0040ffff), 0x10000, "rx");
|
||||
assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), tb.addr(0x0040ffff),
|
||||
0x10000, "rx");
|
||||
});
|
||||
waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty()));
|
||||
|
||||
|
@ -523,12 +523,13 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTes
|
|||
|
||||
waitForPass(() -> {
|
||||
assertTableSize(1);
|
||||
assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000),
|
||||
tb.addr(0x0040ffff), 0x10000, "rx");
|
||||
assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), tb.addr(0x0040ffff),
|
||||
0x10000, "rx");
|
||||
});
|
||||
waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty()));
|
||||
|
||||
listing.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321))));
|
||||
runSwing(() -> listing
|
||||
.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321)))));
|
||||
waitForPass(() -> assertEquals(tb.set(tb.range(0x00401234, 0x00404321)),
|
||||
new AddressSet(listing.getSelection())));
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ public class DebuggerStaticMappingProviderTest extends AbstractGhidraHeadedDebug
|
|||
|
||||
ProgramSelection traceSel =
|
||||
new ProgramSelection(tb.addr(0xdeadbeefL), tb.addr(0xdeadbeefL + 0x0f));
|
||||
listingPlugin.getProvider().setSelection(traceSel);
|
||||
runSwing(() -> listingPlugin.getProvider().setSelection(traceSel));
|
||||
codeViewerPlugin.goTo(new ProgramLocation(program, addr(program, 0xc0de1234L)), true);
|
||||
waitForSwing();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -15,13 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.program.util;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import ghidra.program.model.address.Address;
|
||||
|
||||
/**
|
||||
* Specifies a selection that consists of components inside a structure.
|
||||
* Specifies a selection that consists of components inside a structure.
|
||||
*/
|
||||
public class InteriorSelection {
|
||||
|
||||
|
||||
private ProgramLocation from;
|
||||
private ProgramLocation to;
|
||||
private Address start;
|
||||
|
@ -34,19 +36,21 @@ public class InteriorSelection {
|
|||
* @param start start address
|
||||
* @param end end address
|
||||
*/
|
||||
public InteriorSelection(ProgramLocation from, ProgramLocation to, Address start, Address end) {
|
||||
public InteriorSelection(ProgramLocation from, ProgramLocation to, Address start, Address end) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
/**
|
||||
* Get the start location.
|
||||
* @return ProgramLocation
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start location.
|
||||
* @return ProgramLocation
|
||||
*/
|
||||
public ProgramLocation getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end location.
|
||||
* @return ProgramLocation
|
||||
|
@ -54,6 +58,7 @@ public class InteriorSelection {
|
|||
public ProgramLocation getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start address of this selection.
|
||||
* @return Address
|
||||
|
@ -61,6 +66,7 @@ public class InteriorSelection {
|
|||
public Address getStartAddress() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end address of this selection.
|
||||
* @return Address
|
||||
|
@ -68,41 +74,38 @@ public class InteriorSelection {
|
|||
public Address getEndAddress() {
|
||||
return end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes contained in the selection.
|
||||
* @return int
|
||||
*/
|
||||
public int getByteLength() {
|
||||
long diff = end.subtract(start);
|
||||
return (int) (diff+1);
|
||||
return (int) (diff + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see java.lang.Object#equals(Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InteriorSelection is = (InteriorSelection)obj;
|
||||
|
||||
return from.equals(is.from) && to.equals(is.to);
|
||||
}
|
||||
|
||||
/* (non Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
public int hashCode() {
|
||||
return Objects.hash(from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InteriorSelection is = (InteriorSelection) obj;
|
||||
return from.equals(is.from) && to.equals(is.to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "From = " + from.getAddress() + ", To = " + to.getAddress();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package ghidra.program.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
import ghidra.program.model.address.*;
|
||||
|
||||
|
@ -114,9 +115,11 @@ public class ProgramSelection implements AddressSetView {
|
|||
return interiorSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this ProgramSelection is equal to obj.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(interiorSelection, addressSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
|
@ -135,113 +138,61 @@ public class ProgramSelection implements AddressSetView {
|
|||
return addressSet.hasSameAddresses(ps.addressSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the address exists within this set.
|
||||
* <P>
|
||||
* @param addr address to test.
|
||||
* @return true if addr exists in the set, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Address addr) {
|
||||
return addressSet.contains(addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the given address range is in the set.
|
||||
* <P>
|
||||
* @param start the first address in the range.
|
||||
* @param end the last address in the range.
|
||||
* @return true if entire range is contained within the set,
|
||||
* false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Address start, Address end) {
|
||||
return addressSet.contains(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the given address set is a subset of this set.
|
||||
* <P>
|
||||
* @param rangeSet the set to test.
|
||||
* @return true if the entire set is contained within this set,
|
||||
* false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(AddressSetView rangeSet) {
|
||||
return addressSet.contains(rangeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this program selection intersects with the specified address set.
|
||||
*
|
||||
* @param addrSet address set to check intersection with.
|
||||
*/
|
||||
@Override
|
||||
public boolean intersects(AddressSetView addrSet) {
|
||||
return addressSet != null && addressSet.intersects(addrSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#intersect(ghidra.program.model.address.AddressSetView)
|
||||
*/
|
||||
@Override
|
||||
public AddressSet intersect(AddressSetView view) {
|
||||
return addressSet.intersect(view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#intersectRange(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
|
||||
*/
|
||||
@Override
|
||||
public AddressSet intersectRange(Address start, Address end) {
|
||||
return addressSet.intersectRange(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this set is empty.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return addressSet.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the minimum address for this set.
|
||||
*/
|
||||
@Override
|
||||
public Address getMinAddress() {
|
||||
return addressSet.getMinAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the maximum address for this set.
|
||||
*/
|
||||
@Override
|
||||
public Address getMaxAddress() {
|
||||
return addressSet.getMaxAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of address ranges in this set.
|
||||
*/
|
||||
@Override
|
||||
public int getNumAddressRanges() {
|
||||
return addressSet.getNumAddressRanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the address ranges in this address set.
|
||||
* @param atStart if true, the iterator is positioned at the minimum address.
|
||||
* if false, the iterator is positioned at the maximum address.
|
||||
*/
|
||||
@Override
|
||||
public AddressRangeIterator getAddressRanges(boolean atStart) {
|
||||
return addressSet.getAddressRanges(atStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the address ranges in this address set.
|
||||
*/
|
||||
@Override
|
||||
public AddressRangeIterator getAddressRanges() {
|
||||
return addressSet.getAddressRanges();
|
||||
|
@ -252,25 +203,16 @@ public class ProgramSelection implements AddressSetView {
|
|||
return getAddressRanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of addresses in this set.
|
||||
*/
|
||||
@Override
|
||||
public long getNumAddresses() {
|
||||
return addressSet.getNumAddresses();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#getAddresses(boolean)
|
||||
*/
|
||||
@Override
|
||||
public AddressIterator getAddresses(boolean forward) {
|
||||
return addressSet.getAddresses(forward);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#getAddresses(ghidra.program.model.address.Address, boolean)
|
||||
*/
|
||||
@Override
|
||||
public AddressIterator getAddresses(Address start, boolean forward) {
|
||||
return addressSet.getAddresses(start, forward);
|
||||
|
@ -290,41 +232,26 @@ public class ProgramSelection implements AddressSetView {
|
|||
return addressSet.hasSameAddresses(asv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AddressSetView#intersects(Address, Address)
|
||||
*/
|
||||
@Override
|
||||
public boolean intersects(Address start, Address end) {
|
||||
return addressSet.intersects(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#union(ghidra.program.model.address.AddressSetView)
|
||||
*/
|
||||
@Override
|
||||
public AddressSet union(AddressSetView view) {
|
||||
return addressSet.union(view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#xor(ghidra.program.model.address.AddressSetView)
|
||||
*/
|
||||
@Override
|
||||
public AddressSet xor(AddressSetView view) {
|
||||
return addressSet.xor(view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.address.AddressSetView#subtract(ghidra.program.model.address.AddressSetView)
|
||||
*/
|
||||
@Override
|
||||
public AddressSet subtract(AddressSetView view) {
|
||||
return addressSet.subtract(view);
|
||||
}
|
||||
|
||||
/* (non Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (interiorSelection != null) {
|
||||
|
@ -367,5 +294,4 @@ public class ProgramSelection implements AddressSetView {
|
|||
public Address findFirstAddressInCommon(AddressSetView set) {
|
||||
return addressSet.findFirstAddressInCommon(set);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -431,6 +431,13 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
|
|||
return null;
|
||||
}
|
||||
|
||||
public AddressSet toAddressSet(Program p, String from, String to) {
|
||||
AddressFactory af = p.getAddressFactory();
|
||||
Address a1 = af.getAddress(from);
|
||||
Address a2 = af.getAddress(to);
|
||||
return af.getAddressSet(a1, a2);
|
||||
}
|
||||
|
||||
public AddressSet toAddressSet(List<Address> addrs) {
|
||||
AddressSet set = new AddressSet();
|
||||
for (Address addr : addrs) {
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
*/
|
||||
package ghidra.app.plugin.core.select.reference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
|
@ -70,7 +69,6 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe
|
|||
SelectRefsPlugin plugin = env.getPlugin(SelectRefsPlugin.class);
|
||||
forwardAction = (SelectForwardRefsAction) getInstanceField("forwardAction", plugin);
|
||||
backwardAction = (SelectBackRefsAction) getInstanceField("backwardAction", plugin);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -86,24 +84,21 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe
|
|||
|
||||
@Test
|
||||
public void testForwardLocation() {
|
||||
|
||||
String start = "0020";
|
||||
|
||||
// Selection of address 01001144 gets expanded within code viewer provider
|
||||
// to full code unit
|
||||
CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0010"));
|
||||
|
||||
ProgramLocation location = new AddressFieldLocation(program, addr(start));
|
||||
cb.goTo(location);
|
||||
|
||||
ProgramSelection selection = getCurrentSelection();
|
||||
assertTrue(selection.isEmpty());
|
||||
performAction(forwardAction, cb.getProvider().getActionContext(null), true);
|
||||
selection = getCurrentSelection();
|
||||
assertEquals(selection.getNumAddresses(), cu.getLength());
|
||||
ProgramSelection currentSelection = getCurrentSelection();
|
||||
assertTrue(currentSelection.isEmpty());
|
||||
performAction(forwardAction, cb.getProvider(), true);
|
||||
currentSelection = getCurrentSelection();
|
||||
CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0010"));
|
||||
assertEquals(currentSelection.getNumAddresses(), cu.getLength());
|
||||
|
||||
for (Address addr = cu.getMinAddress(); addr.compareTo(cu.getMaxAddress()) <= 0; addr =
|
||||
addr.add(1)) {
|
||||
assertTrue(selection.contains(addr));
|
||||
assertTrue(currentSelection.contains(addr));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,98 +106,88 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe
|
|||
public void testBackwardLocation() {
|
||||
String start = "0020";
|
||||
|
||||
// Selection of address 010064c0 and 010064fb gets expanded within code viewer provider
|
||||
// to full code unit
|
||||
AddressSet set = new AddressSet();
|
||||
CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0030"));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
cu = program.getListing().getCodeUnitContaining(addr("0040"));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
|
||||
ProgramLocation location = new AddressFieldLocation(program, addr(start));
|
||||
cb.goTo(location);
|
||||
|
||||
ProgramSelection selection = getCurrentSelection();
|
||||
assertTrue(selection.isEmpty());
|
||||
performAction(backwardAction, cb.getProvider().getActionContext(null), true);
|
||||
selection = getCurrentSelection();
|
||||
assertEquals(new AddressSet(selection), set);
|
||||
ProgramSelection currentSelection = getCurrentSelection();
|
||||
assertTrue(currentSelection.isEmpty());
|
||||
performAction(backwardAction, cb.getProvider(), true);
|
||||
|
||||
AddressSet referenceAddrs = getCodeUnitAddrs("0030", "0040");
|
||||
currentSelection = getCurrentSelection();
|
||||
assertEquals(new AddressSet(currentSelection), referenceAddrs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionWithNoReferences() {
|
||||
|
||||
ProgramSelection selection = new ProgramSelection(addr("0050"), addr("0060"));
|
||||
AddressSetView addrs = toAddressSet(program, "0050", "0060");
|
||||
|
||||
CodeViewerProvider provider = cb.getProvider();
|
||||
provider.setSelection(selection);
|
||||
|
||||
performAction(forwardAction, provider.getActionContext(null), true);
|
||||
makeSelection(env.getTool(), program, addrs);
|
||||
performAction(forwardAction, provider, true);
|
||||
|
||||
selection = getCurrentSelection();
|
||||
assertEquals(selection.isEmpty(), true);
|
||||
ProgramSelection currentSelection = getCurrentSelection();
|
||||
assertEquals(currentSelection.isEmpty(), true);
|
||||
|
||||
selection = new ProgramSelection(addr("010049d0"), addr("010049dd"));
|
||||
provider.setSelection(selection);
|
||||
|
||||
performAction(backwardAction, provider.getActionContext(null), true);
|
||||
selection = getCurrentSelection();
|
||||
assertEquals(selection.isEmpty(), true);
|
||||
currentSelection = new ProgramSelection(addr("010049d0"), addr("010049dd"));
|
||||
addrs = toAddressSet(program, "010049d0", "010049dd");
|
||||
makeSelection(env.getTool(), program, addrs);
|
||||
performAction(backwardAction, provider, true);
|
||||
currentSelection = getCurrentSelection();
|
||||
assertEquals(currentSelection.isEmpty(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionForwardReferencesOnly() {
|
||||
String[] start = { "0030", "0050" };
|
||||
ProgramSelection selection = new ProgramSelection(addr(start[0]), addr(start[1]));
|
||||
|
||||
// Selection of address 01005a3c and 01005bff gets expanded within code viewer provider
|
||||
// to full code unit
|
||||
AddressSet set = new AddressSet();
|
||||
Listing listing = program.getListing();
|
||||
CodeUnit cu = listing.getCodeUnitContaining(addr("0014"));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
cu = listing.getCodeUnitContaining(addr("0020"));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
AddressSetView addrs = toAddressSet(program, "0030", "0050");
|
||||
AddressSet referenceAddrs = getCodeUnitAddrs("0014", "0020");
|
||||
|
||||
CodeViewerProvider provider = cb.getProvider();
|
||||
provider.setSelection(selection);
|
||||
|
||||
performAction(backwardAction, provider.getActionContext(null), true);
|
||||
selection = getCurrentSelection();
|
||||
makeSelection(env.getTool(), program, addrs);
|
||||
performAction(backwardAction, provider, true);
|
||||
ProgramSelection selection = getCurrentSelection();
|
||||
assertTrue(selection.isEmpty());
|
||||
|
||||
selection = new ProgramSelection(addr(start[0]), addr(start[1]));
|
||||
provider.setSelection(selection);
|
||||
performAction(forwardAction, provider.getActionContext(null), true);
|
||||
makeSelection(env.getTool(), program, addrs);
|
||||
performAction(forwardAction, provider, true);
|
||||
selection = getCurrentSelection();
|
||||
assertEquals(new AddressSet(selection), set);
|
||||
assertEquals(new AddressSet(selection), referenceAddrs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionBackwardReferencesOnly() {
|
||||
String[] start = { "0000", "0014" };
|
||||
ProgramSelection selection = new ProgramSelection(addr(start[0]), addr(start[1]));
|
||||
|
||||
// Selection of address 01006580, 01006511 and 010065cc gets expanded within code viewer provider
|
||||
// to full code unit
|
||||
AddressSet set = new AddressSet();
|
||||
Listing listing = program.getListing();
|
||||
CodeUnit cu = listing.getCodeUnitContaining(addr("0020"));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
cu = listing.getCodeUnitContaining(addr("0044"));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
AddressSetView addrs = toAddressSet(program, "0000", "0014");
|
||||
AddressSet referenceAddrs = getCodeUnitAddrs("0020", "0044");
|
||||
|
||||
CodeViewerProvider provider = cb.getProvider();
|
||||
provider.setSelection(selection);
|
||||
|
||||
performAction(forwardAction, provider.getActionContext(null), true);
|
||||
selection = getCurrentSelection();
|
||||
assertTrue(selection.isEmpty());
|
||||
makeSelection(env.getTool(), program, addrs);
|
||||
performAction(forwardAction, provider, true);
|
||||
|
||||
selection = new ProgramSelection(addr(start[0]), addr(start[1]));
|
||||
provider.setSelection(selection);
|
||||
performAction(backwardAction, provider.getActionContext(null), true);
|
||||
selection = getCurrentSelection();
|
||||
assertEquals(new AddressSet(selection), set);
|
||||
ProgramSelection curentSelection = getCurrentSelection();
|
||||
assertTrue(curentSelection.isEmpty());
|
||||
|
||||
makeSelection(env.getTool(), program, addrs);
|
||||
performAction(backwardAction, provider, true);
|
||||
curentSelection = getCurrentSelection();
|
||||
assertEquals(new AddressSet(curentSelection), referenceAddrs);
|
||||
}
|
||||
|
||||
private AddressSet getCodeUnitAddrs(String... addrs) {
|
||||
|
||||
// Selection of addresses gets expanded within code viewer provider to full code unit
|
||||
AddressSet set = new AddressSet();
|
||||
Listing listing = program.getListing();
|
||||
for (String addr : addrs) {
|
||||
CodeUnit cu = listing.getCodeUnitContaining(addr(addr));
|
||||
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private Address addr(String address) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue