Merge remote-tracking branch 'origin/GP-6150_ghidra1_BlockCrossAddressUse--SQUASHED'

This commit is contained in:
Ryan Kurtz
2025-12-03 06:22:18 -05:00
18 changed files with 263 additions and 148 deletions

View File

@@ -339,7 +339,7 @@ public abstract class AbstractVTMarkupItemTest extends AbstractGhidraHeadedInteg
// verify we cannot unapply before we have applied
//
List<VTMarkupItem> markupItems = new ArrayList<>();
Address destinationAddress = addr();
Address destinationAddress = addr(session.getDestinationProgram());
markupItem.setDefaultDestinationAddress(destinationAddress, TEST_ADDRESS_SOURCE);
markupItems.add(markupItem);

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,12 +22,19 @@ import java.util.List;
import ghidra.program.database.map.AddressMap;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
public class AddressMapTestDummy implements AddressMap {
private Program program;
public AddressMapTestDummy(Program p) {
program = p;
}
@Override
public Address decodeAddress(long value) {
return addr(value);
return addr(value, program);
}
@Override

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,36 +30,27 @@ public class DummyTestProgramCorrelator extends VTAbstractProgramCorrelator {
private String name = "DummyTestProgramCorrelator";
private int matchCount = 1;
public DummyTestProgramCorrelator() {
this(1);
}
public DummyTestProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
Program destinationProgram, AddressSetView destinationAddressSet, ToolOptions options) {
super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
}
public DummyTestProgramCorrelator(Program sourceProgram, Program destinationProgram) {
super(sourceProgram, createAddressSet(), destinationProgram, createAddressSet(),
createOptions());
super(sourceProgram, createAddressSet(sourceProgram), destinationProgram,
createAddressSet(destinationProgram), createOptions());
}
public DummyTestProgramCorrelator(int matchCount) {
super(null, createAddressSet(), null, createAddressSet(), createOptions());
this.matchCount = matchCount;
}
private static AddressSet createAddressSet() {
private static AddressSet createAddressSet(Program p) {
AddressSet as = new AddressSet();
as.add(getRandomAddressRange());
as.add(getRandomAddressRange());
as.add(getRandomAddressRange());
as.add(getRandomAddressRange(p));
as.add(getRandomAddressRange(p));
as.add(getRandomAddressRange(p));
return as;
}
private static AddressRange getRandomAddressRange() {
Address addr1 = addr();
Address addr2 = addr();
private static AddressRange getRandomAddressRange(Program p) {
Address addr1 = addr(p);
Address addr2 = addr(p);
return new AddressRangeImpl(min(addr1, addr2), max(addr1, addr2));
}

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -789,16 +789,18 @@ public class VTAssociationDBTest extends VTBaseTestCase {
private VTMatchInfo createRandomMatchWithUnrelatedAssociation(VTMatchInfo info) {
Address sourceAddress = info.getSourceAddress();
Address destinationAddress = info.getDestinationAddress();
return createRandomMatch(otherAddr(sourceAddress), otherAddr(destinationAddress), db);
return createRandomMatch(otherAddr(sourceAddress, sourceProgram),
otherAddr(destinationAddress, destinationProgram), db);
}
private VTMatchInfo createRandomMatchWithConflictingDestinationAssociation(VTMatchInfo info) {
Address destinationAddress = info.getDestinationAddress();
return createRandomMatch(info.getSourceAddress(), otherAddr(destinationAddress), db);
return createRandomMatch(info.getSourceAddress(),
otherAddr(destinationAddress, destinationProgram), db);
}
private VTMatchInfo createRandomMatchWithConflictingSourceAssociation(VTMatchInfo mainMatch) {
return createRandomMatch(otherAddr(mainMatch.getSourceAddress()),
return createRandomMatch(otherAddr(mainMatch.getSourceAddress(), sourceProgram),
mainMatch.getDestinationAddress(), db);
}

View File

@@ -50,15 +50,14 @@ public abstract class VTBaseTestCase extends AbstractGenericTest {
}
};
private Program sourceProgram = new VTStubProgram(sourceDomainFile);
private Program destinationProgram = new VTStubProgram(destinationDomainFile);
protected final Program sourceProgram = new VTStubProgram(sourceDomainFile);
protected final Program destinationProgram = new VTStubProgram(destinationDomainFile);
private FunctionManager functionManager = new VTSTubFunctionManager();
private Listing listing = new VTStubListing();
private SymbolTable symbolTable = new VTStubSymbolTable();
private Memory memory = new VTStubMemory();
private AddressMap addressMap = new AddressMapTestDummy();
private static String[] randomTags = { "TAG1", "TAG2", "TAG3" };
private static GenericAddressSpace space =
new GenericAddressSpace("Test", 32, AddressSpace.TYPE_RAM, 3);
@@ -192,7 +191,12 @@ public abstract class VTBaseTestCase extends AbstractGenericTest {
private class VTStubProgram extends StubProgram {
private DomainFile domainFile;
private final DomainFile domainFile;
private final AddressSpace defaultSpace =
new GenericAddressSpace("Test", 32, AddressSpace.TYPE_RAM, 3);
private final AddressFactory addrFactory =
new DefaultAddressFactory(new AddressSpace[] { defaultSpace }, defaultSpace);
private final AddressMap addressMap = new AddressMapTestDummy(this);
VTStubProgram(DomainFile domainFile) {
this.domainFile = domainFile;
@@ -240,7 +244,7 @@ public abstract class VTBaseTestCase extends AbstractGenericTest {
@Override
public AddressFactory getAddressFactory() {
return null;
return addrFactory;
}
@Override

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -95,7 +95,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testEventsForAddingFirstMatchForAssociation() {
VTMatchSet matchSet = createMatchSet();
clearEvents();
VTMatchInfo match = VTTestUtils.createRandomMatch(null);
VTMatchInfo match = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
matchSet.addMatch(match);
@@ -107,7 +107,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
@Test
public void testEventsForAddingAdditionalMatchForAssociation() {
VTMatchSet matchSet = createMatchSet();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
matchSet.addMatch(matchInfo);
clearEvents();
@@ -124,7 +124,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testEventsForRemovingLastMatchForAssociation() {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
clearEvents();
@@ -139,7 +139,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testEventsForDeletingLastMatchForAssociation() {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
clearEvents();
@@ -155,7 +155,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testEventsForRemovingNonLastMatchForAssociation() {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
clearEvents();
@@ -170,7 +170,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testEventsForDeletingNonLastMatchForAssociation() {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
clearEvents();
@@ -184,7 +184,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
@Test
public void testEventsForRejectingMatch() throws VTAssociationStatusException {
VTMatchSet matchSet = createMatchSet();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = matchSet.addMatch(matchInfo);
clearEvents();
match.getAssociation().setRejected();
@@ -197,7 +197,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testAssociationStatusChangedEvent() throws Exception {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
clearEvents();
@@ -214,7 +214,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
Msg.debug(this, "\tcalling clrearEvents()");
clearEvents();
Msg.debug(this, "\tcalling createRandomMatch()");
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
Msg.debug(this, "\tcalling addMatch()");
VTMatch match = manualMatchSet.addMatch(matchInfo);
Msg.debug(this, "\tcalling setAccepted()");
@@ -239,7 +239,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testMarkupStatusChangedEventWhenApplying() throws Exception {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
match.getAssociation().setAccepted();
VTMarkupItem markupItem = VTTestUtils.createRandomMarkupItemStub(match);
@@ -259,7 +259,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testMarkupStatusChangedEventWhenSettingStatus() throws Exception {
VTMatchSet manualMatchSet = db.getManualMatchSet();
clearEvents();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
match.getAssociation().setAccepted();
VTMarkupItem markupItem = VTTestUtils.createRandomMarkupItemStub(match);
@@ -295,7 +295,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
public void testTagAppliedEvent() throws VTAssociationStatusException {
VTMatchTagDB tag = db.createMatchTag("TEST");
VTMatchSet manualMatchSet = db.getManualMatchSet();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
match.getAssociation().setAccepted();
clearEvents();
@@ -313,7 +313,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
@Test
public void testEventsForVotes() {
VTMatchSet manualMatchSet = db.getManualMatchSet();
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(null);
VTMatchInfo matchInfo = VTTestUtils.createRandomMatch(sourceProgram, destinationProgram);
VTMatch match = manualMatchSet.addMatch(matchInfo);
clearEvents();
match.getAssociation().setVoteCount(4);

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,7 +27,8 @@ import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.markupitem.MarkupTypeTestStub;
import ghidra.feature.vt.api.markuptype.VTMarkupType;
import ghidra.feature.vt.api.markuptype.VTMarkupTypeFactory;
import ghidra.program.model.address.*;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.listing.Program;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -35,8 +36,6 @@ import ghidra.util.task.TaskMonitor;
public class VTTestUtils {
private static String[] randomTags = { "TAG1", "TAG2", "TAG3" };
private static GenericAddressSpace space =
new GenericAddressSpace("Test", 32, AddressSpace.TYPE_RAM, 3);
private VTTestUtils() {
// utility class
@@ -75,8 +74,8 @@ public class VTTestUtils {
return getRandomInt(0, Integer.MAX_VALUE);
}
public static Address addr() {
return addr(getRandomInt());
public static Address addr(Program p) {
return addr(getRandomInt(), p);
}
public static Address addr(String offset, Program p) {
@@ -84,14 +83,15 @@ public class VTTestUtils {
return addressFactory.getAddress(offset);
}
public static Address addr(long offset) {
return space.getAddress(offset);
public static Address addr(long offset, Program p) {
return p.getAddressFactory().getDefaultAddressSpace().getAddress(offset);
}
public static Address otherAddr(Address address) {
Address newAddress = addr();
while (newAddress.equals(address)) {
newAddress = addr();
public static Address otherAddr(Address addr, Program p) {
Address newAddress = addr(p);
long offset = addr.getOffset();
while (offset == newAddress.getOffset()) {
newAddress = addr(p);
}
return newAddress;
}
@@ -103,7 +103,19 @@ public class VTTestUtils {
* @return the match
*/
public static VTMatchInfo createRandomMatch(VTSession session) {
return createRandomMatch(addr(), addr(), session);
return createRandomMatch(addr(session.getSourceProgram()),
addr(session.getDestinationProgram()), session);
}
/**
* Create a random dummy match with a null VTSession.
* @param session the match set manager to use when creating a random tag or
* null if you don't want to create a random tag.
* @return the match
*/
public static VTMatchInfo createRandomMatch(Program sourceProgram,
Program destincationProgram) {
return createRandomMatch(addr(sourceProgram), addr(destincationProgram), null);
}
/**
@@ -184,7 +196,8 @@ public class VTTestUtils {
}
public static VTMatch createMatchSetWithOneMatch(VTSessionDB db) throws Exception {
return createMatchSetWithOneMatch(db, addr(), addr());
return createMatchSetWithOneMatch(db, addr(db.getSourceProgram()),
addr(db.getDestinationProgram()));
}
public static VTMatch createMatchSetWithOneMatch(VTSessionDB db, Address sourceAddress,