Merge remote-tracking branch 'origin/GP-3814-dragonmacher-vt-api-update--SQUASHED'

This commit is contained in:
Ryan Kurtz 2023-09-13 07:09:08 -04:00
commit a06ccc11ab
68 changed files with 740 additions and 689 deletions

View file

@ -151,7 +151,7 @@ public class GhidraState {
/** /**
* If it differs, set the current location and fire a {@link ProgramLocationPluginEvent}. * If it differs, set the current location and fire a {@link ProgramLocationPluginEvent}.
* *
* @param location * @param location the location
*/ */
public void setCurrentLocation(ProgramLocation location) { public void setCurrentLocation(ProgramLocation location) {
if (SystemUtilities.isEqual(currentLocation, location)) { if (SystemUtilities.isEqual(currentLocation, location)) {

View file

@ -17,15 +17,14 @@
// data and and then save the session. // data and and then save the session.
//@category Examples.Version Tracking //@category Examples.Version Tracking
import java.util.List;
import ghidra.app.script.GhidraScript; import ghidra.app.script.GhidraScript;
import ghidra.feature.vt.api.db.VTSessionDB; import ghidra.feature.vt.api.db.VTSessionDB;
import ghidra.feature.vt.api.main.VTSession; import ghidra.feature.vt.api.main.VTSession;
import ghidra.feature.vt.api.util.VTOptions;
import ghidra.feature.vt.gui.actions.AutoVersionTrackingTask; import ghidra.feature.vt.gui.actions.AutoVersionTrackingTask;
import ghidra.feature.vt.gui.plugin.*; import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.framework.model.DomainFolder; import ghidra.framework.model.DomainFolder;
import ghidra.framework.plugintool.Plugin; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.util.task.TaskLauncher; import ghidra.util.task.TaskLauncher;
@ -77,31 +76,19 @@ public class AutoVersionTrackingScript extends GhidraScript {
folder.createFile(name, session, monitor); folder.createFile(name, session, monitor);
PluginTool tool = state.getTool();
VTPlugin vtPlugin = getPlugin(tool, VTPlugin.class);
if (vtPlugin == null) {
tool.addPlugin(VTPlugin.class.getName());
vtPlugin = getPlugin(tool, VTPlugin.class);
}
VTController controller = new VTControllerImpl(vtPlugin);
//String description = "AutoVTScript";
AutoVersionTrackingTask autoVtTask = AutoVersionTrackingTask autoVtTask =
new AutoVersionTrackingTask(controller, session, 1.0, 10.0); new AutoVersionTrackingTask(session, getOptions(), 1.0, 10.0);
TaskLauncher.launch(autoVtTask); TaskLauncher.launch(autoVtTask);
} }
public static <T extends Plugin> T getPlugin(PluginTool tool, Class<T> c) { private ToolOptions getOptions() {
List<Plugin> list = tool.getManagedPlugins(); ToolOptions vtOptions = new VTOptions("Dummy");
for (Plugin p : list) { PluginTool tool = state.getTool();
if (p.getClass() == c) { if (tool != null) {
return c.cast(p); vtOptions = tool.getOptions(VTController.VERSION_TRACKING_OPTIONS_NAME);
} }
} return vtOptions;
return null;
} }
} }

View file

@ -28,7 +28,6 @@ import ghidra.feature.vt.api.markuptype.*;
import ghidra.feature.vt.api.util.*; import ghidra.feature.vt.api.util.*;
import ghidra.framework.model.DomainFolder; import ghidra.framework.model.DomainFolder;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.AddressSet; import ghidra.program.model.address.AddressSet;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -74,7 +73,6 @@ public class CreateAppliedExactMatchingSessionScript extends GhidraScript {
int sessionTransaction = session.startTransaction(description); int sessionTransaction = session.startTransaction(description);
try { try {
PluginTool serviceProvider = state.getTool();
VTAssociationManager manager = session.getAssociationManager(); VTAssociationManager manager = session.getAssociationManager();
// should we have convenience methods in VTCorrelator that don't // should we have convenience methods in VTCorrelator that don't
@ -87,16 +85,16 @@ public class CreateAppliedExactMatchingSessionScript extends GhidraScript {
VTProgramCorrelatorFactory factory; VTProgramCorrelatorFactory factory;
factory = new ExactDataMatchProgramCorrelatorFactory(); factory = new ExactDataMatchProgramCorrelatorFactory();
correlateAndPossiblyApply(sourceProgram, destinationProgram, session, serviceProvider, correlateAndPossiblyApply(session, manager, sourceAddressSet, destinationAddressSet,
manager, sourceAddressSet, destinationAddressSet, factory); factory);
factory = new ExactMatchBytesProgramCorrelatorFactory(); factory = new ExactMatchBytesProgramCorrelatorFactory();
correlateAndPossiblyApply(sourceProgram, destinationProgram, session, serviceProvider, correlateAndPossiblyApply(session, manager, sourceAddressSet, destinationAddressSet,
manager, sourceAddressSet, destinationAddressSet, factory); factory);
factory = new ExactMatchInstructionsProgramCorrelatorFactory(); factory = new ExactMatchInstructionsProgramCorrelatorFactory();
correlateAndPossiblyApply(sourceProgram, destinationProgram, session, serviceProvider, correlateAndPossiblyApply(session, manager, sourceAddressSet, destinationAddressSet,
manager, sourceAddressSet, destinationAddressSet, factory); factory);
} }
finally { finally {
try { try {
@ -110,8 +108,7 @@ public class CreateAppliedExactMatchingSessionScript extends GhidraScript {
} }
} }
private void correlateAndPossiblyApply(Program sourceProgram, Program destinationProgram, private void correlateAndPossiblyApply(VTSession session, VTAssociationManager manager,
VTSession session, PluginTool serviceProvider, VTAssociationManager manager,
AddressSetView sourceAddressSet, AddressSetView destinationAddressSet, AddressSetView sourceAddressSet, AddressSetView destinationAddressSet,
VTProgramCorrelatorFactory factory) VTProgramCorrelatorFactory factory)
throws CancelledException, VTAssociationStatusException { throws CancelledException, VTAssociationStatusException {
@ -121,7 +118,7 @@ public class CreateAppliedExactMatchingSessionScript extends GhidraScript {
AddressSetView restrictedDestinationAddresses = AddressSetView restrictedDestinationAddresses =
excludeAcceptedMatches(session, destinationAddressSet, false); excludeAcceptedMatches(session, destinationAddressSet, false);
VTOptions options = factory.createDefaultOptions(); VTOptions options = factory.createDefaultOptions();
VTProgramCorrelator correlator = factory.createCorrelator(serviceProvider, sourceProgram, VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram,
restrictedSourceAddresses, destinationProgram, restrictedDestinationAddresses, options); restrictedSourceAddresses, destinationProgram, restrictedDestinationAddresses, options);
VTMatchSet results = correlator.correlate(session, monitor); VTMatchSet results = correlator.correlate(session, monitor);

View file

@ -64,9 +64,9 @@ public class FindChangedFunctionsScript extends GhidraVersionTrackingScript {
// Make sure the selected programs are not open and locked by Ghidra. If so, // Make sure the selected programs are not open and locked by Ghidra. If so,
// warn the user. // warn the user.
if (areProgramsLocked(p1, p2)) { if (areProgramsLocked()) {
Msg.showError(this, null, "Program is locked!", Msg.showError(this, null, "Program is locked!", "One of the programs you selected is " +
"One of the programs you selected is locked by Ghidra. Please correct and try again."); "locked by Ghidra. Please correct and try again.");
return; return;
} }
@ -95,11 +95,9 @@ public class FindChangedFunctionsScript extends GhidraVersionTrackingScript {
* Note: calling {@link Program#isLocked()} does not work here; we must * Note: calling {@link Program#isLocked()} does not work here; we must
* check to see if one of the programs is the currently-open program. * check to see if one of the programs is the currently-open program.
* *
* @param p1 the first program
* @param p2 the second program
* @return true if either program is locked * @return true if either program is locked
*/ */
private boolean areProgramsLocked(Program p1, Program p2) { private boolean areProgramsLocked() {
return p1 == currentProgram || p2 == currentProgram; return p1 == currentProgram || p2 == currentProgram;
} }
} }

View file

@ -36,8 +36,8 @@ public abstract class GhidraVersionTrackingScript extends GhidraScript {
private int transactionID; private int transactionID;
public void createVersionTrackingSession(String sourceProgramPath, String destinationProgramPath) public void createVersionTrackingSession(String sourceProgramPath,
throws Exception { String destinationProgramPath) throws Exception {
if (vtSession != null) { if (vtSession != null) {
throw new RuntimeException("Attempted to open a new session with one already open!"); throw new RuntimeException("Attempted to open a new session with one already open!");
@ -123,8 +123,8 @@ public abstract class GhidraVersionTrackingScript extends GhidraScript {
} }
public Program openProgram(String path) throws VersionException, CancelledException, public Program openProgram(String path)
IOException { throws VersionException, CancelledException, IOException {
if (state.getProject() == null) { if (state.getProject() == null) {
throw new RuntimeException("No project open."); throw new RuntimeException("No project open.");
} }
@ -174,10 +174,10 @@ public abstract class GhidraVersionTrackingScript extends GhidraScript {
throw new RuntimeException("You must have an open vt session to run a correlator"); throw new RuntimeException("You must have an open vt session to run a correlator");
} }
VTProgramCorrelatorFactory correlatorFactory = getCorrelatorFactory(name); VTProgramCorrelatorFactory correlatorFactory = getCorrelatorFactory(name);
VTProgramCorrelator correlator = VTProgramCorrelator correlator = correlatorFactory.createCorrelator(sourceProgram,
correlatorFactory.createCorrelator(null, sourceProgram,
sourceProgram.getMemory().getLoadedAndInitializedAddressSet(), destinationProgram, sourceProgram.getMemory().getLoadedAndInitializedAddressSet(), destinationProgram,
destinationProgram.getMemory().getLoadedAndInitializedAddressSet(), new VTOptions("dummy")); destinationProgram.getMemory().getLoadedAndInitializedAddressSet(),
new VTOptions("dummy"));
correlator.correlate(vtSession, monitor); correlator.correlate(vtSession, monitor);
} }

View file

@ -20,7 +20,7 @@ import java.util.List;
import ghidra.feature.vt.api.correlator.program.*; import ghidra.feature.vt.api.correlator.program.*;
import ghidra.feature.vt.api.impl.VTProgramCorrelatorInfo; import ghidra.feature.vt.api.impl.VTProgramCorrelatorInfo;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.gui.plugin.VTController; import ghidra.feature.vt.gui.plugin.VTSessionSupplier;
import ghidra.framework.options.Options; import ghidra.framework.options.Options;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.program.model.listing.Data; import ghidra.program.model.listing.Data;
@ -32,26 +32,25 @@ public class ExactMatchAddressCorrelator implements AddressCorrelator {
private static final String CORRELATOR_NAME = "ExactMatchAddressCorrelator"; private static final String CORRELATOR_NAME = "ExactMatchAddressCorrelator";
private ToolOptions options = new ToolOptions(CORRELATOR_NAME); private ToolOptions options = new ToolOptions(CORRELATOR_NAME);
private VTController controller; private VTSessionSupplier sessionSupplier;
public ExactMatchAddressCorrelator(VTController controller) { public ExactMatchAddressCorrelator(VTSessionSupplier sessionSupplier) {
this.controller = controller; this.sessionSupplier = sessionSupplier;
} }
@Override @Override
public synchronized AddressCorrelation correlate(Function sourceFunction, public synchronized AddressCorrelation correlate(Function sourceFunction,
Function destinationFunction) { Function destinationFunction) {
VTSession session = controller.getSession(); VTSession session = sessionSupplier.getSession();
VTAssociationManager associationManager = session.getAssociationManager(); VTAssociationManager associationManager = session.getAssociationManager();
VTAssociation association = VTAssociation association = associationManager.getAssociation(
associationManager.getAssociation(sourceFunction.getEntryPoint(), sourceFunction.getEntryPoint(), destinationFunction.getEntryPoint());
destinationFunction.getEntryPoint());
List<VTMatch> matches = session.getMatches(association); List<VTMatch> matches = session.getMatches(association);
for (VTMatch match : matches) { for (VTMatch match : matches) {
VTMatchSet matchSet = match.getMatchSet(); VTMatchSet matchSet = match.getMatchSet();
VTProgramCorrelatorInfo info = matchSet.getProgramCorrelatorInfo(); VTProgramCorrelatorInfo info = matchSet.getProgramCorrelatorInfo();
final String correlatorName = info.getName(); String correlatorName = info.getName();
if (correlatorName.equals(ExactMatchBytesProgramCorrelatorFactory.EXACT_MATCH) || if (correlatorName.equals(ExactMatchBytesProgramCorrelatorFactory.EXACT_MATCH) ||
correlatorName.equals(ExactMatchInstructionsProgramCorrelatorFactory.EXACT_MATCH) || correlatorName.equals(ExactMatchInstructionsProgramCorrelatorFactory.EXACT_MATCH) ||
correlatorName.equals(ExactMatchMnemonicsProgramCorrelatorFactory.EXACT_MATCH)) { correlatorName.equals(ExactMatchMnemonicsProgramCorrelatorFactory.EXACT_MATCH)) {

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTAssociationType; import ghidra.feature.vt.api.main.VTAssociationType;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.RefType; import ghidra.program.model.symbol.RefType;
@ -26,12 +25,11 @@ import ghidra.program.model.symbol.Reference;
/** /**
* Correlates functions based on previously accepted data and function matches. * Correlates functions based on previously accepted data and function matches.
*/ */
public class CombinedFunctionAndDataReferenceProgramCorrelator extends public class CombinedFunctionAndDataReferenceProgramCorrelator
VTAbstractReferenceProgramCorrelator { extends VTAbstractReferenceProgramCorrelator {
/** /**
* Combined Function and Data Reference Correlator class constructor. * Combined Function and Data Reference Correlator class constructor.
* @param serviceProvider The {@code ServiceProvider}.
* @param sourceProgram The source {@code Program}. * @param sourceProgram The source {@code Program}.
* @param sourceAddressSet The {@code AddressSetView} for the source program. * @param sourceAddressSet The {@code AddressSetView} for the source program.
* @param destinationProgram The destination {@code Program}. * @param destinationProgram The destination {@code Program}.
@ -39,11 +37,11 @@ public class CombinedFunctionAndDataReferenceProgramCorrelator extends
* @param correlatorName The correlator name string passed from the factory. * @param correlatorName The correlator name string passed from the factory.
* @param options {@code ToolOptions} * @param options {@code ToolOptions}
*/ */
public CombinedFunctionAndDataReferenceProgramCorrelator(ServiceProvider serviceProvider, public CombinedFunctionAndDataReferenceProgramCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) { AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) {
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram, super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet,
destinationAddressSet, correlatorName, options); correlatorName, options);
} }
@Override @Override

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -28,7 +27,6 @@ public class CombinedFunctionAndDataReferenceProgramCorrelatorFactory
extends VTAbstractReferenceProgramCorrelatorFactory { extends VTAbstractReferenceProgramCorrelatorFactory {
public CombinedFunctionAndDataReferenceProgramCorrelatorFactory() { public CombinedFunctionAndDataReferenceProgramCorrelatorFactory() {
super();
setName("Combined Function and Data Reference Match"); setName("Combined Function and Data Reference Match");
correlatorDescription = correlatorDescription =
"Matches functions based on the accepted data and function matches they have in common."; "Matches functions based on the accepted data and function matches they have in common.";
@ -38,10 +36,10 @@ public class CombinedFunctionAndDataReferenceProgramCorrelatorFactory
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new CombinedFunctionAndDataReferenceProgramCorrelator(serviceProvider, sourceProgram, return new CombinedFunctionAndDataReferenceProgramCorrelator(sourceProgram,
sourceAddressSet, destinationProgram, destinationAddressSet, correlatorName, options); sourceAddressSet, destinationProgram, destinationAddressSet, correlatorName, options);
} }
} }

View file

@ -15,12 +15,13 @@
*/ */
package ghidra.feature.vt.api.correlator.program; package ghidra.feature.vt.api.correlator.program;
import java.util.List;
import ghidra.app.plugin.match.MatchData; import ghidra.app.plugin.match.MatchData;
import ghidra.app.plugin.match.MatchedData; import ghidra.app.plugin.match.MatchedData;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Data; import ghidra.program.model.listing.Data;
@ -28,18 +29,15 @@ import ghidra.program.model.listing.Program;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.util.List;
public class DataMatchProgramCorrelator extends VTAbstractProgramCorrelator { public class DataMatchProgramCorrelator extends VTAbstractProgramCorrelator {
private final String name; private final String name;
private final boolean oneToOne; private final boolean oneToOne;
public DataMatchProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public DataMatchProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet, ToolOptions options,
AddressSetView destinationAddressSet, ToolOptions options, String name, boolean oneToOne) { String name, boolean oneToOne) {
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram, super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
destinationAddressSet, options);
this.name = name; this.name = name;
this.oneToOne = oneToOne; this.oneToOne = oneToOne;
} }

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTAssociationType; import ghidra.feature.vt.api.main.VTAssociationType;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.RefType; import ghidra.program.model.symbol.RefType;
@ -30,7 +29,6 @@ public class DataReferenceProgramCorrelator extends VTAbstractReferenceProgramCo
/** /**
* Data Reference Correlator class constructor. * Data Reference Correlator class constructor.
* @param serviceProvider The {@code ServiceProvider}.
* @param sourceProgram The source {@code Program}. * @param sourceProgram The source {@code Program}.
* @param sourceAddressSet The {@code AddressSetView} for the source program. * @param sourceAddressSet The {@code AddressSetView} for the source program.
* @param destinationProgram The destination {@code Program}. * @param destinationProgram The destination {@code Program}.
@ -38,11 +36,11 @@ public class DataReferenceProgramCorrelator extends VTAbstractReferenceProgramCo
* @param correlatorName The correlator name string passed from the factory. * @param correlatorName The correlator name string passed from the factory.
* @param options {@code ToolOptions} * @param options {@code ToolOptions}
*/ */
public DataReferenceProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public DataReferenceProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet, String correlatorName,
AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) { ToolOptions options) {
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram, super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet,
destinationAddressSet, correlatorName, options); correlatorName, options);
} }
@Override @Override

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -28,7 +27,6 @@ public class DataReferenceProgramCorrelatorFactory
extends VTAbstractReferenceProgramCorrelatorFactory { extends VTAbstractReferenceProgramCorrelatorFactory {
public DataReferenceProgramCorrelatorFactory() { public DataReferenceProgramCorrelatorFactory() {
super();
setName("Data Reference Match"); setName("Data Reference Match");
correlatorDescription = correlatorDescription =
"Matches functions by the accepted data matches they have in common."; "Matches functions by the accepted data matches they have in common.";
@ -38,10 +36,10 @@ public class DataReferenceProgramCorrelatorFactory
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new DataReferenceProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new DataReferenceProgramCorrelator(sourceProgram, sourceAddressSet,
destinationProgram, destinationAddressSet, correlatorName, options); destinationProgram, destinationAddressSet, correlatorName, options);
} }

View file

@ -18,7 +18,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -36,11 +35,11 @@ public class DuplicateDataMatchProgramCorrelatorFactory extends VTAbstractProgra
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new DataMatchProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new DataMatchProgramCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, options, DUPLICATE_MATCH, false); destinationAddressSet, options, DUPLICATE_MATCH, false);
} }
@Override @Override

View file

@ -19,7 +19,6 @@ import ghidra.app.plugin.match.ExactInstructionsFunctionHasher;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -38,10 +37,10 @@ public class DuplicateFunctionMatchProgramCorrelatorFactory
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new FunctionMatchProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new FunctionMatchProgramCorrelator(sourceProgram, sourceAddressSet,
destinationProgram, destinationAddressSet, options, DUPLICATE_MATCH, false, destinationProgram, destinationAddressSet, options, DUPLICATE_MATCH, false,
ExactInstructionsFunctionHasher.INSTANCE); ExactInstructionsFunctionHasher.INSTANCE);
} }

View file

@ -18,7 +18,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -42,16 +41,15 @@ public class DuplicateSymbolNameProgramCorrelatorFactory
@Override @Override
public int getPriority() { public int getPriority() {
// TODO Auto-generated method stub
return 90; return 90;
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new SymbolNameProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new SymbolNameProgramCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, options, DUP_SYMBOL_MATCH, false); destinationAddressSet, options, DUP_SYMBOL_MATCH, false);
} }
@Override @Override

View file

@ -18,7 +18,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -48,11 +47,11 @@ public class ExactDataMatchProgramCorrelatorFactory extends VTAbstractProgramCor
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new DataMatchProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new DataMatchProgramCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, options, EXACT_MATCH, true); destinationAddressSet, options, EXACT_MATCH, true);
} }
@Override @Override

View file

@ -19,7 +19,6 @@ import ghidra.app.plugin.match.ExactBytesFunctionHasher;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -38,10 +37,10 @@ public class ExactMatchBytesProgramCorrelatorFactory extends VTAbstractProgramCo
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new FunctionMatchProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new FunctionMatchProgramCorrelator(sourceProgram, sourceAddressSet,
destinationProgram, destinationAddressSet, options, EXACT_MATCH, true, destinationProgram, destinationAddressSet, options, EXACT_MATCH, true,
ExactBytesFunctionHasher.INSTANCE); ExactBytesFunctionHasher.INSTANCE);
} }

View file

@ -19,12 +19,11 @@ import ghidra.app.plugin.match.ExactInstructionsFunctionHasher;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
public class ExactMatchInstructionsProgramCorrelatorFactory extends public class ExactMatchInstructionsProgramCorrelatorFactory
VTAbstractProgramCorrelatorFactory { extends VTAbstractProgramCorrelatorFactory {
static final String DESC = static final String DESC =
"Compares code by hashing instructions, looking for identical functions. It reports back any that have ONLY ONE identical match."; "Compares code by hashing instructions, looking for identical functions. It reports back any that have ONLY ONE identical match.";
@ -39,10 +38,10 @@ public class ExactMatchInstructionsProgramCorrelatorFactory extends
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new FunctionMatchProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new FunctionMatchProgramCorrelator(sourceProgram, sourceAddressSet,
destinationProgram, destinationAddressSet, options, EXACT_MATCH, true, destinationProgram, destinationAddressSet, options, EXACT_MATCH, true,
ExactInstructionsFunctionHasher.INSTANCE); ExactInstructionsFunctionHasher.INSTANCE);
} }

View file

@ -19,11 +19,11 @@ import ghidra.app.plugin.match.ExactMnemonicsFunctionHasher;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
public class ExactMatchMnemonicsProgramCorrelatorFactory extends VTAbstractProgramCorrelatorFactory { public class ExactMatchMnemonicsProgramCorrelatorFactory
extends VTAbstractProgramCorrelatorFactory {
static final String DESC = static final String DESC =
"Compares code by hashing instructions mnemonics, looking for identical functions. It reports back any that have ONLY ONE identical match."; "Compares code by hashing instructions mnemonics, looking for identical functions. It reports back any that have ONLY ONE identical match.";
@ -38,10 +38,10 @@ public class ExactMatchMnemonicsProgramCorrelatorFactory extends VTAbstractProgr
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new FunctionMatchProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new FunctionMatchProgramCorrelator(sourceProgram, sourceAddressSet,
destinationProgram, destinationAddressSet, options, EXACT_MATCH, true, destinationProgram, destinationAddressSet, options, EXACT_MATCH, true,
ExactMnemonicsFunctionHasher.INSTANCE); ExactMnemonicsFunctionHasher.INSTANCE);
} }

View file

@ -24,7 +24,6 @@ import ghidra.app.plugin.match.MatchFunctions.MatchedFunctions;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
@ -38,12 +37,10 @@ public class FunctionMatchProgramCorrelator extends VTAbstractProgramCorrelator
private final boolean oneToOne; private final boolean oneToOne;
private final FunctionHasher hasher; private final FunctionHasher hasher;
public FunctionMatchProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public FunctionMatchProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet, ToolOptions options,
AddressSetView destinationAddressSet, ToolOptions options, String name, String name, boolean oneToOne, FunctionHasher hasher) {
boolean oneToOne, FunctionHasher hasher) { super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram,
destinationAddressSet, options);
this.name = name; this.name = name;
this.oneToOne = oneToOne; this.oneToOne = oneToOne;
this.hasher = hasher; this.hasher = hasher;

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTAssociationType; import ghidra.feature.vt.api.main.VTAssociationType;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.Reference; import ghidra.program.model.symbol.Reference;
@ -29,7 +28,6 @@ public class FunctionReferenceProgramCorrelator extends VTAbstractReferenceProgr
/** /**
* Function Reference Correlator class constructor. * Function Reference Correlator class constructor.
* @param serviceProvider The {@code ServiceProvider}.
* @param sourceProgram The source {@code Program}. * @param sourceProgram The source {@code Program}.
* @param sourceAddressSet The {@code AddressSetView} for the source program. * @param sourceAddressSet The {@code AddressSetView} for the source program.
* @param destinationProgram The destination {@code Program}. * @param destinationProgram The destination {@code Program}.
@ -37,12 +35,11 @@ public class FunctionReferenceProgramCorrelator extends VTAbstractReferenceProgr
* @param correlatorName The correlator name string passed from the factory. * @param correlatorName The correlator name string passed from the factory.
* @param options {@code ToolOptions} * @param options {@code ToolOptions}
*/ */
public FunctionReferenceProgramCorrelator(ServiceProvider serviceProvider, public FunctionReferenceProgramCorrelator(Program sourceProgram,
Program sourceProgram,
AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) { AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) {
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram, super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet,
destinationAddressSet, correlatorName, options); correlatorName, options);
} }
@Override @Override

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -27,7 +26,6 @@ import ghidra.program.model.listing.Program;
public class FunctionReferenceProgramCorrelatorFactory public class FunctionReferenceProgramCorrelatorFactory
extends VTAbstractReferenceProgramCorrelatorFactory { extends VTAbstractReferenceProgramCorrelatorFactory {
public FunctionReferenceProgramCorrelatorFactory() { public FunctionReferenceProgramCorrelatorFactory() {
super();
setName("Function Reference Match"); setName("Function Reference Match");
correlatorDescription = correlatorDescription =
"Matches functions by the accepted function matches they have in common."; "Matches functions by the accepted function matches they have in common.";
@ -37,10 +35,10 @@ public class FunctionReferenceProgramCorrelatorFactory
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new FunctionReferenceProgramCorrelator(serviceProvider, sourceProgram, return new FunctionReferenceProgramCorrelator(sourceProgram, sourceAddressSet,
sourceAddressSet, destinationProgram, destinationAddressSet, correlatorName, options); destinationProgram, destinationAddressSet, correlatorName, options);
} }
} }

View file

@ -29,8 +29,8 @@ public class ImpliedMatchProgramCorrelator extends VTAbstractProgramCorrelator {
public static final String NAME = "Implied Match"; public static final String NAME = "Implied Match";
public ImpliedMatchProgramCorrelator(Program sourceProgram, Program destinationProgram) { public ImpliedMatchProgramCorrelator(Program sourceProgram, Program destinationProgram) {
super(null, sourceProgram, sourceProgram.getMemory(), destinationProgram, super(sourceProgram, sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(),
destinationProgram.getMemory(), new ToolOptions(NAME)); new ToolOptions(NAME));
} }
@Override @Override

View file

@ -29,8 +29,8 @@ public class ManualMatchProgramCorrelator extends VTAbstractProgramCorrelator {
public static final String NAME = "Manual Match"; public static final String NAME = "Manual Match";
public ManualMatchProgramCorrelator(Program sourceProgram, Program destinationProgram) { public ManualMatchProgramCorrelator(Program sourceProgram, Program destinationProgram) {
super(null, sourceProgram, sourceProgram.getMemory(), destinationProgram, super(sourceProgram, sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(),
destinationProgram.getMemory(), new ToolOptions(NAME)); new ToolOptions(NAME));
} }
@Override @Override

View file

@ -28,7 +28,6 @@ import generic.lsh.vector.VectorCompare;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -48,17 +47,14 @@ public class SimilarDataProgramCorrelator extends VTAbstractProgramCorrelator {
int featureID = 0; int featureID = 0;
int minDataLength; int minDataLength;
public SimilarDataProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public SimilarDataProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet, ToolOptions options) {
AddressSetView destinationAddressSet, ToolOptions options) { super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram,
destinationAddressSet, options);
} }
@Override @Override
protected void doCorrelate(VTMatchSet matchSet, TaskMonitor monitor) throws CancelledException { protected void doCorrelate(VTMatchSet matchSet, TaskMonitor monitor) throws CancelledException {
minDataLength = minDataLength = getOptions().getInt(SimilarDataProgramCorrelatorFactory.MIN_NAME_LENGTH,
getOptions().getInt(SimilarDataProgramCorrelatorFactory.MIN_NAME_LENGTH,
SimilarDataProgramCorrelatorFactory.MIN_NAME_LENGTH_DEFAULT); SimilarDataProgramCorrelatorFactory.MIN_NAME_LENGTH_DEFAULT);
boolean skipHomogenousData = boolean skipHomogenousData =
getOptions().getBoolean(SimilarDataProgramCorrelatorFactory.SKIP_HOMOGENOUS_DATA, getOptions().getBoolean(SimilarDataProgramCorrelatorFactory.SKIP_HOMOGENOUS_DATA,

View file

@ -19,7 +19,6 @@ import generic.lsh.LSHMemoryModel;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -41,11 +40,11 @@ public class SimilarDataProgramCorrelatorFactory extends VTAbstractProgramCorrel
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new SimilarDataProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new SimilarDataProgramCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, options); destinationAddressSet, options);
} }
@Override @Override

View file

@ -26,7 +26,6 @@ import generic.lsh.vector.VectorCompare;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -46,11 +45,10 @@ public class SimilarSymbolNameProgramCorrelator extends VTAbstractProgramCorrela
int featureID = 0; int featureID = 0;
int minNameLength; int minNameLength;
public SimilarSymbolNameProgramCorrelator(ServiceProvider serviceProvider, public SimilarSymbolNameProgramCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, ToolOptions options) { AddressSetView destinationAddressSet, ToolOptions options) {
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram, super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
destinationAddressSet, options);
} }
@Override @Override

View file

@ -19,7 +19,6 @@ import generic.lsh.LSHMemoryModel;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -37,11 +36,11 @@ public class SimilarSymbolNameProgramCorrelatorFactory extends VTAbstractProgram
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new SimilarSymbolNameProgramCorrelator(serviceProvider, sourceProgram, return new SimilarSymbolNameProgramCorrelator(sourceProgram, sourceAddressSet,
sourceAddressSet, destinationProgram, destinationAddressSet, options); destinationProgram, destinationAddressSet, options);
} }
@Override @Override

View file

@ -22,7 +22,6 @@ import ghidra.app.plugin.match.MatchSymbol.MatchedSymbol;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -36,12 +35,10 @@ public class SymbolNameProgramCorrelator extends VTAbstractProgramCorrelator {
private final boolean oneToOne; private final boolean oneToOne;
public SymbolNameProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public SymbolNameProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet, ToolOptions options,
AddressSetView destinationAddressSet, ToolOptions options, String name, String name, boolean oneToOne) {
boolean oneToOne) { super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram,
destinationAddressSet, options);
this.name = name; this.name = name;
this.oneToOne = oneToOne; this.oneToOne = oneToOne;
@ -125,8 +122,9 @@ public class SymbolNameProgramCorrelator extends VTAbstractProgramCorrelator {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
}
if (!(obj instanceof AddressMatch)) { if (!(obj instanceof AddressMatch)) {
return false; return false;
} }

View file

@ -18,7 +18,6 @@ package ghidra.feature.vt.api.correlator.program;
import ghidra.feature.vt.api.main.VTProgramCorrelator; import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelatorFactory;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -43,11 +42,11 @@ public class SymbolNameProgramCorrelatorFactory extends VTAbstractProgramCorrela
} }
@Override @Override
protected VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return new SymbolNameProgramCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return new SymbolNameProgramCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, options, EXACT_SYMBOL_MATCH, true); destinationAddressSet, options, EXACT_SYMBOL_MATCH, true);
} }
@Override @Override

View file

@ -28,7 +28,6 @@ import generic.lsh.vector.VectorCompare;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -62,7 +61,6 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
/** /**
* Correlator class constructor. * Correlator class constructor.
* @param serviceProvider the service provider
* @param sourceProgram the source program * @param sourceProgram the source program
* @param sourceAddressSet the source addresses to correlate * @param sourceAddressSet the source addresses to correlate
* @param destinationProgram the destination program * @param destinationProgram the destination program
@ -70,13 +68,11 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
* @param correlatorName the correlator name * @param correlatorName the correlator name
* @param options the tool options * @param options the tool options
*/ */
public VTAbstractReferenceProgramCorrelator(ServiceProvider serviceProvider, public VTAbstractReferenceProgramCorrelator(Program sourceProgram,
Program sourceProgram,
AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) { AddressSetView destinationAddressSet, String correlatorName, ToolOptions options) {
// Call the constructor for the parent class. // Call the constructor for the parent class.
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram, super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
destinationAddressSet, options);
this.correlatorName = correlatorName; this.correlatorName = correlatorName;
this.sourceProgram = sourceProgram; this.sourceProgram = sourceProgram;
@ -126,8 +122,7 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
throws CancelledException { throws CancelledException {
monitor.initialize(destVectorsByAddress.size()); monitor.initialize(destVectorsByAddress.size());
Set<Entry<Address, LSHCosineVectorAccum>> destEntries = Set<Entry<Address, LSHCosineVectorAccum>> destEntries = destVectorsByAddress.entrySet();
destVectorsByAddress.entrySet();
for (Entry<Address, LSHCosineVectorAccum> destEntry : destEntries) { for (Entry<Address, LSHCosineVectorAccum> destEntry : destEntries) {
monitor.checkCancelled(); monitor.checkCancelled();
@ -140,8 +135,7 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
// Get the set of possible matches, neighbors, in the SourceProgram // Get the set of possible matches, neighbors, in the SourceProgram
Map<Address, DominantPair<Double, VectorCompare>> srcNeighbors = new HashMap<>(); Map<Address, DominantPair<Double, VectorCompare>> srcNeighbors = new HashMap<>();
Set<Entry<Address, LSHCosineVectorAccum>> srcEntries = Set<Entry<Address, LSHCosineVectorAccum>> srcEntries = srcVectorsByAddress.entrySet();
srcVectorsByAddress.entrySet();
for (Entry<Address, LSHCosineVectorAccum> srcEntry : srcEntries) { for (Entry<Address, LSHCosineVectorAccum> srcEntry : srcEntries) {
Address srcAddr = srcEntry.getKey(); Address srcAddr = srcEntry.getKey();
LSHCosineVectorAccum srcVector = srcEntry.getValue(); LSHCosineVectorAccum srcVector = srcEntry.getValue();
@ -156,8 +150,8 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
} }
} }
List<VTMatchInfo> members = transform(matchSet, destFunc, dstVector, srcNeighbors, List<VTMatchInfo> members =
monitor); transform(matchSet, destFunc, dstVector, srcNeighbors, monitor);
for (VTMatchInfo member : members) { for (VTMatchInfo member : members) {
if (member != null) { if (member != null) {
@ -294,8 +288,8 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
* @param program the program * @param program the program
* @param address an address represents a location in a program * @param address an address represents a location in a program
*/ */
private void accumulateFunctionReferences(int depth, Set<Function> list, private void accumulateFunctionReferences(int depth, Set<Function> list, Program program,
Program program, Address address) { Address address) {
if (depth >= MAX_DEPTH) { if (depth >= MAX_DEPTH) {
return; return;
@ -389,10 +383,8 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
private void extractReferenceFeatures(VTMatchSet matchSet, TaskMonitor monitor) private void extractReferenceFeatures(VTMatchSet matchSet, TaskMonitor monitor)
throws CancelledException { throws CancelledException {
srcVectorsByAddress = srcVectorsByAddress = LazyMap.lazyMap(new HashMap<>(), addr -> new LSHCosineVectorAccum());
LazyMap.lazyMap(new HashMap<>(), addr -> new LSHCosineVectorAccum()); destVectorsByAddress = LazyMap.lazyMap(new HashMap<>(), addr -> new LSHCosineVectorAccum());
destVectorsByAddress =
LazyMap.lazyMap(new HashMap<>(), addr -> new LSHCosineVectorAccum());
FunctionManager srcFuncManager = sourceProgram.getFunctionManager(); FunctionManager srcFuncManager = sourceProgram.getFunctionManager();
FunctionManager destFuncManager = destinationProgram.getFunctionManager(); FunctionManager destFuncManager = destinationProgram.getFunctionManager();
@ -449,14 +441,12 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
// By the construction above, there may be duplicate functions in the RefMaps // By the construction above, there may be duplicate functions in the RefMaps
for (Function function : sourceRefMap.get(match)) { for (Function function : sourceRefMap.get(match)) {
LSHCosineVectorAccum vector = LSHCosineVectorAccum vector = srcVectorsByAddress.get(function.getEntryPoint());
srcVectorsByAddress.get(function.getEntryPoint());
vector.addHash(featureID, weight); vector.addHash(featureID, weight);
} }
for (Function function : destinationRefMap.get(match)) { for (Function function : destinationRefMap.get(match)) {
LSHCosineVectorAccum vector = LSHCosineVectorAccum vector = destVectorsByAddress.get(function.getEntryPoint());
destVectorsByAddress.get(function.getEntryPoint());
vector.addHash(featureID, weight); vector.addHash(featureID, weight);
} }
@ -475,8 +465,7 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
// odd checks here: 1) assuming we do not want to include our own results when checking // odd checks here: 1) assuming we do not want to include our own results when checking
// matches; 2) why keep only the newest match set data? seems like we should take all // matches; 2) why keep only the newest match set data? seems like we should take all
// matches and dedup the matches, not the match sets // matches and dedup the matches, not the match sets
if (name.equals(correlatorName) || if (name.equals(correlatorName) || (dedupedMatchSets.containsKey(name) &&
(dedupedMatchSets.containsKey(name) &&
ms.getID() < dedupedMatchSets.get(name).getID())) { ms.getID() < dedupedMatchSets.get(name).getID())) {
continue; continue;
} }
@ -489,8 +478,7 @@ public abstract class VTAbstractReferenceProgramCorrelator extends VTAbstractPro
} }
private void accumulateMatchFunctionReferences( private void accumulateMatchFunctionReferences(Map<VTMatch, Set<Function>> sourceRefMap,
Map<VTMatch, Set<Function>> sourceRefMap,
Map<VTMatch, Set<Function>> destinationRefMap, VTMatch match) { Map<VTMatch, Set<Function>> destinationRefMap, VTMatch match) {
// check match association type and status // check match association type and status

View file

@ -43,6 +43,7 @@ public interface VTProgramCorrelator {
/** /**
* Returns a options object populated with the options for this correlator instance. * Returns a options object populated with the options for this correlator instance.
* @return the options
*/ */
public ToolOptions getOptions(); public ToolOptions getOptions();

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,7 +57,6 @@ public interface VTProgramCorrelatorFactory extends ExtensionPoint {
/** /**
* Returns a VTProgramCorrelator instance created specifically for the given parameters. * Returns a VTProgramCorrelator instance created specifically for the given parameters.
* @param serviceProvider a service provider to access tool services.
* @param sourceProgram the source program for this correlation. * @param sourceProgram the source program for this correlation.
* @param sourceAddressSet the set of addresses in the source program to consider in this correlation. * @param sourceAddressSet the set of addresses in the source program to consider in this correlation.
* @param destinationProgram the destination program for this correlation. * @param destinationProgram the destination program for this correlation.
@ -67,7 +65,29 @@ public interface VTProgramCorrelatorFactory extends ExtensionPoint {
* @param options the options to use for this correlation. * @param options the options to use for this correlation.
* @return a new VTProgramCorrelator instance created specifically for this set of given parameters. * @return a new VTProgramCorrelator instance created specifically for this set of given parameters.
*/ */
public VTProgramCorrelator createCorrelator(Program sourceProgram,
AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options);
/**
* Deprecated. Use {@link #createCorrelator(Program, AddressSetView, Program, AddressSetView, VTOptions)}
* instead.
*
*
* @param serviceProvider a service provider to access tool services.
* @param sourceProgram the source program for this correlation.
* @param sourceAddressSet the set of addresses in the source program to consider in this correlation.
* @param destinationProgram the destination program for this correlation.
* @param destinationAddressSet the set of addresses in the destination program to consider in
* this correlation.
* @param options the options to use for this correlation.
* @return a new VTProgramCorrelator instance created specifically for this set of given parameters.
* @deprecated Use {@link #createCorrelator(Program, AddressSetView, Program, AddressSetView, VTOptions)}
* instead.
*/
@Deprecated
public VTProgramCorrelator createCorrelator(ServiceProvider serviceProvider, public VTProgramCorrelator createCorrelator(ServiceProvider serviceProvider,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options); AddressSetView destinationAddressSet, VTOptions options);
} }

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,15 +15,14 @@
*/ */
package ghidra.feature.vt.api.main; package ghidra.feature.vt.api.main;
import ghidra.framework.model.DomainObjectListener;
import ghidra.framework.model.UndoableDomainObject;
import ghidra.program.model.listing.Program;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import db.util.ErrorHandler; import db.util.ErrorHandler;
import ghidra.framework.model.DomainObjectListener;
import ghidra.framework.model.UndoableDomainObject;
import ghidra.program.model.listing.Program;
/** /**
* Main interface for a Version Tracking Session * Main interface for a Version Tracking Session
@ -69,11 +67,12 @@ public interface VTSession extends ErrorHandler, UndoableDomainObject {
* Returns the name of this VTSession * Returns the name of this VTSession
* @return the name of this VTSession * @return the name of this VTSession
*/ */
@Override
public String getName(); public String getName();
/** /**
* Saves this VTSession. * Saves this VTSession.
* @throws IOException * @throws IOException if there is an exception saving
*/ */
public void save() throws IOException; public void save() throws IOException;
@ -81,12 +80,14 @@ public interface VTSession extends ErrorHandler, UndoableDomainObject {
* Adds a DomainObjectListener to this VTSession. * Adds a DomainObjectListener to this VTSession.
* @param domainObjectListener the listener to add. * @param domainObjectListener the listener to add.
*/ */
@Override
public void addListener(DomainObjectListener domainObjectListener); public void addListener(DomainObjectListener domainObjectListener);
/** /**
* Removes a DomainObjectListener from this VTSession. * Removes a DomainObjectListener from this VTSession.
* @param domainObjectListener the listener to remove. * @param domainObjectListener the listener to remove.
*/ */
@Override
public void removeListener(DomainObjectListener domainObjectListener); public void removeListener(DomainObjectListener domainObjectListener);
/** /**

View file

@ -17,7 +17,6 @@ package ghidra.feature.vt.api.util;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.util.SystemUtilities; import ghidra.util.SystemUtilities;
@ -37,8 +36,6 @@ public abstract class VTAbstractProgramCorrelator implements VTProgramCorrelator
private final AddressSetView destinationAddressSet; private final AddressSetView destinationAddressSet;
private final ToolOptions options; private final ToolOptions options;
protected final ServiceProvider serviceProvider;
/** /**
* Constructor * Constructor
* @param sourceProgram The program that contains functions that are to be looked for in the * @param sourceProgram The program that contains functions that are to be looked for in the
@ -51,10 +48,9 @@ public abstract class VTAbstractProgramCorrelator implements VTProgramCorrelator
* @param options An Options object that contains the set of options to be used by the * @param options An Options object that contains the set of options to be used by the
* correlating algorithm. * correlating algorithm.
*/ */
public VTAbstractProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public VTAbstractProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet,
AddressSetView destinationAddressSet, ToolOptions options) { ToolOptions options) {
this.serviceProvider = serviceProvider;
this.sourceProgram = sourceProgram; this.sourceProgram = sourceProgram;
this.sourceAddressSet = sourceAddressSet; this.sourceAddressSet = sourceAddressSet;
this.destinationProgram = destinationProgram; this.destinationProgram = destinationProgram;

View file

@ -68,21 +68,57 @@ public abstract class VTAbstractProgramCorrelatorFactory implements VTProgramCor
} }
@Override @Override
public final VTProgramCorrelator createCorrelator(ServiceProvider serviceProvider, public final VTProgramCorrelator createCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) { AddressSetView destinationAddressSet, VTOptions options) {
return doCreateCorrelator(serviceProvider, sourceProgram, sourceAddressSet, return doCreateCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, options == null ? createDefaultOptions() destinationAddressSet,
: (VTOptions) options.copy()); options == null ? createDefaultOptions() : (VTOptions) options.copy());
} }
/** /**
* This method is added to the interface to enforce the fact that we want options passed into * This method is added to the interface to enforce the fact that we want options passed into
* this method to be copies so that changes during correlation do not spoil the options * this method to be copies so that changes during correlation do not spoil the options
* of others. * of others.
* @param sourceProgram the source program for this correlation.
* @param sourceAddressSet the set of addresses in the source program to consider in this
* correlation.
* @param destinationProgram the destination program for this correlation.
* @param destinationAddressSet the set of addresses in the destination program to consider in
* this correlation.
* @param options the options to use for this correlation.
* @return a new VTProgramCorrelator instance created specifically for this set of given
* parameters.
*/ */
protected abstract VTProgramCorrelator doCreateCorrelator(ServiceProvider serviceProvider, protected abstract VTProgramCorrelator doCreateCorrelator(Program sourceProgram,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options); AddressSetView destinationAddressSet, VTOptions options);
/**
* Deprecated. Use {@link #createCorrelator(Program, AddressSetView, Program, AddressSetView, VTOptions)}
* instead.
*
*
* @param sourceProgram the source program for this correlation.
* @param sourceAddressSet the set of addresses in the source program to consider in this
* correlation.
* @param destinationProgram the destination program for this correlation.
* @param destinationAddressSet the set of addresses in the destination program to consider in
* this correlation.
* @param options the options to use for this correlation.
* @return a new VTProgramCorrelator instance created specifically for this set of given
* parameters.
* @deprecated Use {@link #createCorrelator(Program, AddressSetView, Program, AddressSetView, VTOptions)}
* instead.
*/
@Override
@Deprecated
public VTProgramCorrelator createCorrelator(ServiceProvider serviceProvider,
Program sourceProgram, AddressSetView sourceAddressSet, Program destinationProgram,
AddressSetView destinationAddressSet, VTOptions options) {
return doCreateCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationAddressSet, options);
}
} }

View file

@ -15,10 +15,10 @@
*/ */
package ghidra.feature.vt.api.util; package ghidra.feature.vt.api.util;
import ghidra.framework.options.ToolOptions;
import org.jdom.Element; import org.jdom.Element;
import ghidra.framework.options.ToolOptions;
public class VTOptions extends ToolOptions { public class VTOptions extends ToolOptions {
private VTOptions(Element root) { private VTOptions(Element root) {
@ -37,6 +37,7 @@ public class VTOptions extends ToolOptions {
/** /**
* A method that allows subclasses to tell the world where their options contain acceptable * A method that allows subclasses to tell the world where their options contain acceptable
* values * values
* @return true if valid
*/ */
public boolean validate() { public boolean validate() {
return true; return true;

View file

@ -24,9 +24,10 @@ import generic.theme.GIcon;
import ghidra.feature.vt.api.main.VTSession; import ghidra.feature.vt.api.main.VTSession;
import ghidra.feature.vt.gui.plugin.VTController; import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.feature.vt.gui.plugin.VTPlugin; import ghidra.feature.vt.gui.plugin.VTPlugin;
import ghidra.framework.options.ToolOptions;
import ghidra.util.HTMLUtilities; import ghidra.util.HTMLUtilities;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
import ghidra.util.task.TaskLauncher; import ghidra.util.task.*;
/** /**
* This action runs the {@link AutoVersionTrackingTask} * This action runs the {@link AutoVersionTrackingTask}
@ -59,6 +60,7 @@ public class AutoVersionTrackingAction extends DockingAction {
public void actionPerformed(ActionContext context) { public void actionPerformed(ActionContext context) {
VTSession session = controller.getSession(); VTSession session = controller.getSession();
ToolOptions options = controller.getOptions();
// In the future we might want to make these user options so the user can change them. // In the future we might want to make these user options so the user can change them.
// We don't want to make this change until the confidence option in the reference // We don't want to make this change until the confidence option in the reference
@ -68,7 +70,25 @@ public class AutoVersionTrackingAction extends DockingAction {
// The current passed values for score and confidence (.95 and 10.0) // The current passed values for score and confidence (.95 and 10.0)
// get you accepted matches with similarity scores >= .95 and // get you accepted matches with similarity scores >= .95 and
// confidence (log 10) scores 2.0 and up // confidence (log 10) scores 2.0 and up
AutoVersionTrackingTask task = new AutoVersionTrackingTask(controller, session, 0.95, 10.0); AutoVersionTrackingTask task = new AutoVersionTrackingTask(session, options, 0.95, 10.0);
task.addTaskListener(new TaskListener() {
@Override
public void taskCompleted(Task t) {
String message = task.getStatusMsg();
if (message != null) {
controller.getTool().setStatusInfo(message);
}
}
@Override
public void taskCancelled(Task t) {
String message = task.getStatusMsg();
if (message != null) {
controller.getTool().setStatusInfo(message);
}
}
});
TaskLauncher.launch(task); TaskLauncher.launch(task);
} }

View file

@ -23,11 +23,11 @@ import ghidra.feature.vt.api.correlator.program.*;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAssociationStatusException; import ghidra.feature.vt.api.util.VTAssociationStatusException;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.feature.vt.gui.plugin.VTController; import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager;
import ghidra.feature.vt.gui.task.ApplyMarkupItemTask; import ghidra.feature.vt.gui.task.ApplyMarkupItemTask;
import ghidra.feature.vt.gui.util.MatchInfo; import ghidra.feature.vt.gui.util.MatchInfo;
import ghidra.feature.vt.gui.util.MatchInfoFactory;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.lang.OperandType; import ghidra.program.model.lang.OperandType;
@ -69,43 +69,42 @@ public class AutoVersionTrackingTask extends Task {
private static final String NAME = "Auto Version Tracking Command"; private static final String NAME = "Auto Version Tracking Command";
private VTSession session; private VTSession session;
private MatchInfoFactory matchInfoFactory;
private AddressCorrelatorManager addressCorrelator;
private Program sourceProgram; private Program sourceProgram;
private Program destinationProgram; private Program destinationProgram;
private PluginTool serviceProvider;
private AddressSetView sourceAddressSet; private AddressSetView sourceAddressSet;
private AddressSetView destinationAddressSet; private AddressSetView destinationAddressSet;
private VTController controller;
private double minCombinedReferenceCorrelatorScore; private double minCombinedReferenceCorrelatorScore;
private double minCombinedReferenceCorrelatorConfidence; private double minCombinedReferenceCorrelatorConfidence;
private final ToolOptions applyOptions; private ToolOptions applyOptions;
private String statusMsg = null; private String statusMsg = null;
private static int NUM_CORRELATORS = 8; private static int NUM_CORRELATORS = 8;
/** /**
* Constructor for a modal/blocking AutoVersionTrackingTask * Constructor for a modal/blocking AutoVersionTrackingTask
* *
* @param controller The Version Tracking controller for this session containing option and
* tool information needed for this command.
* @param session The Version Tracking session containing the source, destination, correlator * @param session The Version Tracking session containing the source, destination, correlator
* and match information needed for this command. * and match information needed for this command.
* @param options the options used when applying matches
* @param minCombinedReferenceCorrelatorScore The minimum score used to limit matches created by * @param minCombinedReferenceCorrelatorScore The minimum score used to limit matches created by
* the Combined Reference Correlator. * the Combined Reference Correlator.
* @param minCombinedReferenceCorrelatorConfidence The minimum confidence used to limit matches * @param minCombinedReferenceCorrelatorConfidence The minimum confidence used to limit matches
* created by the Combined Reference Correlator. * created by the Combined Reference Correlator.
*/ */
public AutoVersionTrackingTask(VTController controller, VTSession session, public AutoVersionTrackingTask(VTSession session, ToolOptions options,
double minCombinedReferenceCorrelatorScore, double minCombinedReferenceCorrelatorScore,
double minCombinedReferenceCorrelatorConfidence) { double minCombinedReferenceCorrelatorConfidence) {
super(NAME, true, true, true); super(NAME, true, true, true);
this.session = session; this.session = session;
this.matchInfoFactory = new MatchInfoFactory();
this.addressCorrelator = new AddressCorrelatorManager(() -> session);
this.sourceProgram = session.getSourceProgram(); this.sourceProgram = session.getSourceProgram();
this.destinationProgram = session.getDestinationProgram(); this.destinationProgram = session.getDestinationProgram();
this.serviceProvider = controller.getTool();
this.controller = controller;
this.minCombinedReferenceCorrelatorScore = minCombinedReferenceCorrelatorScore; this.minCombinedReferenceCorrelatorScore = minCombinedReferenceCorrelatorScore;
this.minCombinedReferenceCorrelatorConfidence = minCombinedReferenceCorrelatorConfidence; this.minCombinedReferenceCorrelatorConfidence = minCombinedReferenceCorrelatorConfidence;
this.applyOptions = controller.getOptions(); this.applyOptions = options;
} }
@Override @Override
@ -267,8 +266,6 @@ public class AutoVersionTrackingTask extends Task {
" with some apply markup errors. See the log or the markup table for more details"; " with some apply markup errors. See the log or the markup table for more details";
} }
statusMsg = NAME + " completed successfully" + applyMarkupStatus; statusMsg = NAME + " completed successfully" + applyMarkupStatus;
controller.getTool().setStatusInfo(statusMsg);
} }
private int getNumberOfDataMatches(TaskMonitor monitor) throws CancelledException { private int getNumberOfDataMatches(TaskMonitor monitor) throws CancelledException {
@ -323,8 +320,8 @@ public class AutoVersionTrackingTask extends Task {
monitor.setMessage( monitor.setMessage(
"Finding and applying good " + factory.getName() + " matches and markup."); "Finding and applying good " + factory.getName() + " matches and markup.");
VTProgramCorrelator correlator = factory.createCorrelator(serviceProvider, sourceProgram, VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram, sourceAddressSet,
sourceAddressSet, destinationProgram, destinationAddressSet, options); destinationProgram, destinationAddressSet, options);
VTMatchSet results = correlator.correlate(session, monitor); VTMatchSet results = correlator.correlate(session, monitor);
monitor.initialize(results.getMatchCount()); monitor.initialize(results.getMatchCount());
@ -353,8 +350,8 @@ public class AutoVersionTrackingTask extends Task {
monitor.setMessage( monitor.setMessage(
"Finding and applying good " + factory.getName() + " matches and markup."); "Finding and applying good " + factory.getName() + " matches and markup.");
VTProgramCorrelator correlator = factory.createCorrelator(serviceProvider, sourceProgram, VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram, sourceAddressSet,
sourceAddressSet, destinationProgram, destinationAddressSet, options); destinationProgram, destinationAddressSet, options);
VTMatchSet results = correlator.correlate(session, monitor); VTMatchSet results = correlator.correlate(session, monitor);
monitor.initialize(results.getMatchCount()); monitor.initialize(results.getMatchCount());
@ -395,14 +392,14 @@ public class AutoVersionTrackingTask extends Task {
continue; continue;
} }
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = matchInfoFactory.getMatchInfo(match, addressCorrelator);
Collection<VTMarkupItem> markupItems = matchInfo.getAppliableMarkupItems(monitor); Collection<VTMarkupItem> markupItems = matchInfo.getAppliableMarkupItems(monitor);
if (markupItems == null || markupItems.size() == 0) { if (markupItems == null || markupItems.size() == 0) {
continue; continue;
} }
ApplyMarkupItemTask markupTask = ApplyMarkupItemTask markupTask =
new ApplyMarkupItemTask(controller.getSession(), markupItems, applyOptions); new ApplyMarkupItemTask(session, markupItems, applyOptions);
markupTask.run(monitor); markupTask.run(monitor);
boolean currentMatchHasErrors = markupTask.hasErrors(); boolean currentMatchHasErrors = markupTask.hasErrors();
@ -538,12 +535,12 @@ public class AutoVersionTrackingTask extends Task {
if (tryToSetAccepted(association)) { if (tryToSetAccepted(association)) {
// If accept match succeeds apply the markup for the match // If accept match succeeds apply the markup for the match
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = matchInfoFactory.getMatchInfo(match, addressCorrelator);
Collection<VTMarkupItem> markupItems = matchInfo.getAppliableMarkupItems(monitor); Collection<VTMarkupItem> markupItems = matchInfo.getAppliableMarkupItems(monitor);
if (markupItems != null && markupItems.size() != 0) { if (markupItems != null && markupItems.size() != 0) {
ApplyMarkupItemTask markupTask = ApplyMarkupItemTask markupTask =
new ApplyMarkupItemTask(controller.getSession(), markupItems, applyOptions); new ApplyMarkupItemTask(session, markupItems, applyOptions);
markupTask.run(monitor); markupTask.run(monitor);
boolean currentMatchHasErrors = markupTask.hasErrors(); boolean currentMatchHasErrors = markupTask.hasErrors();
if (currentMatchHasErrors) { if (currentMatchHasErrors) {

View file

@ -48,15 +48,13 @@ public class AddressCorrelatorManager {
new FixedSizeMRUCachingFactory<Pair<Data, Data>, AddressCorrelation>( new FixedSizeMRUCachingFactory<Pair<Data, Data>, AddressCorrelation>(
key -> getDataCorrelator(key.first, key.second), DATA_CORRELATION_CACHE_SIZE); key -> getDataCorrelator(key.first, key.second), DATA_CORRELATION_CACHE_SIZE);
public AddressCorrelatorManager(VTController controller) { public AddressCorrelatorManager(VTSessionSupplier sessionSupplier) {
correlatorList = new ArrayList<AddressCorrelator>(); correlatorList = new ArrayList<AddressCorrelator>();
initializeAddressCorrelators(controller); initializeAddressCorrelators(sessionSupplier);
} }
private void initializeAddressCorrelators(VTController controller) { private void initializeAddressCorrelators(VTSessionSupplier sessionSupplier) {
// Put the CodeCompare address correlator that uses match info to handle exact matches correlatorList.add(new ExactMatchAddressCorrelator(sessionSupplier));
// so it is first in the list.
correlatorList.add(new ExactMatchAddressCorrelator(controller));
correlatorList.addAll(initializeAddressCorrelators()); correlatorList.addAll(initializeAddressCorrelators());
} }

View file

@ -35,7 +35,7 @@ import ghidra.program.model.symbol.Symbol;
import ghidra.program.util.AddressCorrelation; import ghidra.program.util.AddressCorrelation;
import ghidra.program.util.ProgramLocation; import ghidra.program.util.ProgramLocation;
public interface VTController { public interface VTController extends VTSessionSupplier {
public static final String VERSION_TRACKING_OPTIONS_NAME = "Version Tracking"; public static final String VERSION_TRACKING_OPTIONS_NAME = "Version Tracking";
@ -43,8 +43,7 @@ public interface VTController {
public void removeListener(VTControllerListener listener); public void removeListener(VTControllerListener listener);
// public VTSessionState getSessionState(); @Override
public VTSession getSession(); public VTSession getSession();
public void openVersionTrackingSession(DomainFile domainFile); public void openVersionTrackingSession(DomainFile domainFile);
@ -110,6 +109,7 @@ public interface VTController {
/** /**
* Runs VT tasks, listening for destination program changes and updates undo/redo state * Runs VT tasks, listening for destination program changes and updates undo/redo state
* accordingly. * accordingly.
* @param task the task
*/ */
public void runVTTask(VtTask task); public void runVTTask(VtTask task);

View file

@ -329,8 +329,8 @@ public class VTControllerImpl
return; return;
} }
currentMatchInfo = (match == null) ? null currentMatchInfo =
: matchInfoFactory.getMatchInfo(this, match, addressCorrelatorManager); (match == null) ? null : matchInfoFactory.getMatchInfo(match, addressCorrelatorManager);
fireMatchChanged(currentMatchInfo); fireMatchChanged(currentMatchInfo);
} }
@ -338,7 +338,7 @@ public class VTControllerImpl
@Override @Override
public MatchInfo getMatchInfo(VTMatch match) { public MatchInfo getMatchInfo(VTMatch match) {
return (match == null) ? null return (match == null) ? null
: matchInfoFactory.getMatchInfo(this, match, addressCorrelatorManager); : matchInfoFactory.getMatchInfo(match, addressCorrelatorManager);
} }
private void fireSessionChanged() { private void fireSessionChanged() {

View file

@ -0,0 +1,25 @@
/* ###
* IP: GHIDRA
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.feature.vt.gui.plugin;
import ghidra.feature.vt.api.main.VTSession;
/**
* A simple interface that provides a session.
*/
public interface VTSessionSupplier {
public VTSession getSession();
}

View file

@ -15,15 +15,11 @@
*/ */
package ghidra.feature.vt.gui.provider.impliedmatches; package ghidra.feature.vt.gui.provider.impliedmatches;
import java.util.List;
import java.util.Set;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.gui.plugin.*; import ghidra.feature.vt.gui.plugin.*;
import ghidra.feature.vt.gui.util.*; import ghidra.feature.vt.gui.util.*;
import ghidra.framework.model.DomainObjectChangedEvent; import ghidra.framework.model.DomainObjectChangedEvent;
import ghidra.framework.options.Options; import ghidra.framework.options.Options;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
@ -40,6 +36,7 @@ public class ImpliedMatchAssociationHook implements AssociationHook, VTControlle
Options options = controller.getOptions(); Options options = controller.getOptions();
autoCreateImpliedMatches = autoCreateImpliedMatches =
options.getBoolean(VTOptionDefines.AUTO_CREATE_IMPLIED_MATCH, false); options.getBoolean(VTOptionDefines.AUTO_CREATE_IMPLIED_MATCH, false);
setSession(controller.getSession()); setSession(controller.getSession());
controller.addListener(this); controller.addListener(this);
} }
@ -74,39 +71,14 @@ public class ImpliedMatchAssociationHook implements AssociationHook, VTControlle
try { try {
TaskMonitor monitor = VTTaskMonitor.getTaskMonitor(); TaskMonitor monitor = VTTaskMonitor.getTaskMonitor();
Set<VTImpliedMatchInfo> impliedMatches = ImpliedMatchUtils.findImpliedMatches( ImpliedMatchUtils.updateImpliedMatchForAcceptedAssocation(source, destination, session,
controller, source, destination, session, correlator, monitor); correlator, monitor);
processAssociationAccepted(impliedMatches);
} }
catch (CancelledException e) { catch (CancelledException e) {
Msg.info(this, "User cancelled finding implied matches when accepting an assocation"); Msg.info(this, "User cancelled finding implied matches when accepting an assocation");
} }
} }
/**
* When a match is accepted either create associated implied matches or if a match already
* exists, increase the vote count
* @param impliedMatches The implied matches set to either create or increase vote count
*/
private void processAssociationAccepted(Set<VTImpliedMatchInfo> impliedMatches) {
for (VTImpliedMatchInfo impliedMatch : impliedMatches) {
Address sourceAddress = impliedMatch.getSourceAddress();
Address destinationAddress = impliedMatch.getDestinationAddress();
VTAssociation existingAssociation =
session.getAssociationManager().getAssociation(sourceAddress, destinationAddress);
if (existingAssociation == null) {
VTMatchSet impliedMatchSet = session.getImpliedMatchSet();
VTMatch match = impliedMatchSet.addMatch(impliedMatch);
existingAssociation = match.getAssociation();
}
if (existingAssociation != null) {
existingAssociation.setVoteCount(existingAssociation.getVoteCount() + 1);
}
}
}
@Override @Override
public void associationCleared(VTAssociation association) { public void associationCleared(VTAssociation association) {
Function source = ImpliedMatchUtils.getSourceFunction(session, association); Function source = ImpliedMatchUtils.getSourceFunction(session, association);
@ -122,44 +94,14 @@ public class ImpliedMatchAssociationHook implements AssociationHook, VTControlle
AddressCorrelatorManager correlator = controller.getCorrelator(); AddressCorrelatorManager correlator = controller.getCorrelator();
try { try {
TaskMonitor monitor = VTTaskMonitor.getTaskMonitor(); TaskMonitor monitor = VTTaskMonitor.getTaskMonitor();
Set<VTImpliedMatchInfo> impliedMatches = ImpliedMatchUtils.findImpliedMatches( ImpliedMatchUtils.updateImpliedMatchForClearedAssocation(source, destination, session,
controller, source, destination, session, correlator, monitor); correlator, monitor);
processAssociationCleared(impliedMatches);
} }
catch (CancelledException e) { catch (CancelledException e) {
Msg.info(this, "User cancelled finding implied matches when clearing an assocation"); Msg.info(this, "User cancelled finding implied matches when clearing an assocation");
} }
} }
private void processAssociationCleared(Set<VTImpliedMatchInfo> impliedMatches) {
for (VTImpliedMatchInfo impliedMatch : impliedMatches) {
Address sourceAddress = impliedMatch.getSourceAddress();
Address destinationAddress = impliedMatch.getDestinationAddress();
VTAssociation existingAssociation =
session.getAssociationManager().getAssociation(sourceAddress, destinationAddress);
if (existingAssociation != null) {
int newVoteCount = Math.max(0, existingAssociation.getVoteCount() - 1);
existingAssociation.setVoteCount(newVoteCount);
if (autoCreateImpliedMatches && newVoteCount == 0) {
removeImpliedMatch(existingAssociation);
}
}
}
}
private void removeImpliedMatch(VTAssociation existingAssociation) {
List<VTMatch> matches = session.getMatches(existingAssociation);
VTMatchSet impliedMatchSet = session.getImpliedMatchSet();
for (VTMatch vtMatch : matches) {
if (vtMatch.getMatchSet() == impliedMatchSet) {
impliedMatchSet.removeMatch(vtMatch);
}
}
}
@Override @Override
public void optionsChanged(Options options) { public void optionsChanged(Options options) {
autoCreateImpliedMatches = autoCreateImpliedMatches =

View file

@ -15,6 +15,10 @@
*/ */
package ghidra.feature.vt.gui.provider.impliedmatches; package ghidra.feature.vt.gui.provider.impliedmatches;
import java.util.Set;
import docking.widgets.table.DiscoverableTableUtils;
import docking.widgets.table.TableColumnDescriptor;
import ghidra.docking.settings.Settings; import ghidra.docking.settings.Settings;
import ghidra.feature.vt.api.db.DeletedMatch; import ghidra.feature.vt.api.db.DeletedMatch;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
@ -22,7 +26,8 @@ import ghidra.feature.vt.api.util.EmptyVTSession;
import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager; import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager;
import ghidra.feature.vt.gui.plugin.VTController; import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.feature.vt.gui.util.AbstractVTMatchTableModel.*; import ghidra.feature.vt.gui.util.AbstractVTMatchTableModel.*;
import ghidra.feature.vt.gui.util.*; import ghidra.feature.vt.gui.util.ImpliedMatchUtils;
import ghidra.feature.vt.gui.util.MatchInfo;
import ghidra.framework.plugintool.ServiceProvider; import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -32,13 +37,8 @@ import ghidra.util.table.AddressBasedTableModel;
import ghidra.util.table.field.AbstractProgramBasedDynamicTableColumn; import ghidra.util.table.field.AbstractProgramBasedDynamicTableColumn;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.util.Set; public class VTImpliedMatchesTableModel
extends AddressBasedTableModel<ImpliedMatchWrapperRowObject> {
import docking.widgets.table.DiscoverableTableUtils;
import docking.widgets.table.TableColumnDescriptor;
public class VTImpliedMatchesTableModel extends
AddressBasedTableModel<ImpliedMatchWrapperRowObject> {
private static final String TITLE = "Implied Match Table Model"; private static final String TITLE = "Implied Match Table Model";
protected VTSession session; protected VTSession session;
@ -114,42 +114,42 @@ public class VTImpliedMatchesTableModel extends
descriptor.addVisibleColumn(new SourceReferenceAddressTableColumn()); descriptor.addVisibleColumn(new SourceReferenceAddressTableColumn());
descriptor.addVisibleColumn(new DestinationReferenceAddressTableColumn()); descriptor.addVisibleColumn(new DestinationReferenceAddressTableColumn());
descriptor.addHiddenColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addHiddenColumn(
new SessionNumberTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new SessionNumberTableColumn()));
descriptor.addVisibleColumn( descriptor.addVisibleColumn(
DiscoverableTableUtils.adaptColumForModel(this, new StatusTableColumn()), 1, true); DiscoverableTableUtils.adaptColumForModel(this, new StatusTableColumn()), 1, true);
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new MatchTypeTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new MatchTypeTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new ScoreTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new ScoreTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new ConfidenceScoreTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new ConfidenceScoreTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new ImpliedMatchCountColumn())); DiscoverableTableUtils.adaptColumForModel(this, new ImpliedMatchCountColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new RelatedMatchCountColumn())); DiscoverableTableUtils.adaptColumForModel(this, new RelatedMatchCountColumn()));
descriptor.addHiddenColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addHiddenColumn(
new MultipleSourceLabelsTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new MultipleSourceLabelsTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new SourceLabelTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new SourceLabelTableColumn()));
descriptor.addVisibleColumn( descriptor.addVisibleColumn(
DiscoverableTableUtils.adaptColumForModel(this, new SourceAddressTableColumn()), 2, DiscoverableTableUtils.adaptColumForModel(this, new SourceAddressTableColumn()), 2,
true); true);
descriptor.addHiddenColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addHiddenColumn(DiscoverableTableUtils.adaptColumForModel(this,
new MultipleDestinationLabelsTableColumn())); new MultipleDestinationLabelsTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new DestinationLabelTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new DestinationLabelTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new DestinationAddressTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new DestinationAddressTableColumn()));
descriptor.addVisibleColumn(DiscoverableTableUtils.adaptColumForModel(this, descriptor.addVisibleColumn(
new AlgorithmTableColumn())); DiscoverableTableUtils.adaptColumForModel(this, new AlgorithmTableColumn()));
return descriptor; return descriptor;
} }
@Override @Override
protected void doLoad(Accumulator<ImpliedMatchWrapperRowObject> accumulator, TaskMonitor monitor) protected void doLoad(Accumulator<ImpliedMatchWrapperRowObject> accumulator,
throws CancelledException { TaskMonitor monitor) throws CancelledException {
MatchInfo matchInfo = controller.getMatchInfo(); MatchInfo matchInfo = controller.getMatchInfo();
if (matchInfo == null) { if (matchInfo == null) {
return; // no match selected return; // no match selected
@ -165,9 +165,8 @@ public class VTImpliedMatchesTableModel extends
} }
AddressCorrelatorManager correlator = controller.getCorrelator(); AddressCorrelatorManager correlator = controller.getCorrelator();
Set<VTImpliedMatchInfo> matches = Set<VTImpliedMatchInfo> matches = ImpliedMatchUtils.findImpliedMatches(sourceFunction,
ImpliedMatchUtils.findImpliedMatches(controller, sourceFunction, destinationFunction, destinationFunction, session, correlator, monitor);
session, correlator, monitor);
monitor.setMessage("Searching for existing matches..."); monitor.setMessage("Searching for existing matches...");
monitor.initialize(matches.size()); monitor.initialize(matches.size());
@ -203,8 +202,8 @@ public class VTImpliedMatchesTableModel extends
//================================================================================================== //==================================================================================================
// Source Ref Address // Source Ref Address
public static class SourceReferenceAddressTableColumn extends public static class SourceReferenceAddressTableColumn
AbstractProgramBasedDynamicTableColumn<ImpliedMatchWrapperRowObject, String> { extends AbstractProgramBasedDynamicTableColumn<ImpliedMatchWrapperRowObject, String> {
@Override @Override
public String getColumnName() { public String getColumnName() {
@ -224,8 +223,8 @@ public class VTImpliedMatchesTableModel extends
} }
// Destination Ref Address // Destination Ref Address
public static class DestinationReferenceAddressTableColumn extends public static class DestinationReferenceAddressTableColumn
AbstractProgramBasedDynamicTableColumn<ImpliedMatchWrapperRowObject, String> { extends AbstractProgramBasedDynamicTableColumn<ImpliedMatchWrapperRowObject, String> {
@Override @Override
public String getColumnName() { public String getColumnName() {

View file

@ -158,8 +158,8 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
ListingCodeComparisonPanel dualListingPanel = functionComparisonPanel.getDualListingPanel(); ListingCodeComparisonPanel dualListingPanel = functionComparisonPanel.getDualListingPanel();
if (dualListingPanel != null) { if (dualListingPanel != null) {
dualListingPanel.setLeftProgramLocationListener(new SourceProgramLocationListener()); dualListingPanel.setLeftProgramLocationListener(new SourceProgramLocationListener());
dualListingPanel.setRightProgramLocationListener( dualListingPanel
new DestinationProgramLocationListener()); .setRightProgramLocationListener(new DestinationProgramLocationListener());
sourceHighlightProvider = new VTDualListingHighlightProvider(controller, true); sourceHighlightProvider = new VTDualListingHighlightProvider(controller, true);
destinationHighlightProvider = new VTDualListingHighlightProvider(controller, false); destinationHighlightProvider = new VTDualListingHighlightProvider(controller, false);
@ -329,8 +329,7 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
if (filteredCount != unfilteredCount) { if (filteredCount != unfilteredCount) {
buffy.append(" (of ") buffy.append(" (of ")
.append(markupItemsTableModel.getUnfilteredRowCount()) .append(markupItemsTableModel.getUnfilteredRowCount())
.append( .append(')');
')');
} }
setSubTitle(buffy.toString()); setSubTitle(buffy.toString());
@ -359,8 +358,8 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
splitPane.add(functionComparisonPanel); splitPane.add(functionComparisonPanel);
markupPanel.add(splitPane, BorderLayout.CENTER); markupPanel.add(splitPane, BorderLayout.CENTER);
if (dualListingPanel != null) { if (dualListingPanel != null) {
dualListingPanel.setLeftProgramLocationListener( dualListingPanel
new SourceProgramLocationListener()); .setLeftProgramLocationListener(new SourceProgramLocationListener());
dualListingPanel.setRightProgramLocationListener( dualListingPanel.setRightProgramLocationListener(
new DestinationProgramLocationListener()); new DestinationProgramLocationListener());
} }
@ -402,8 +401,8 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
parentPanel.add(nameFilterPanel, BorderLayout.CENTER); parentPanel.add(nameFilterPanel, BorderLayout.CENTER);
ancillaryFilterButton = new JButton(FILTER_ICON); ancillaryFilterButton = new JButton(FILTER_ICON);
ancillaryFilterButton.addActionListener( ancillaryFilterButton
e -> tool.showDialog(ancillaryFilterDialog, component)); .addActionListener(e -> tool.showDialog(ancillaryFilterDialog, component));
ancillaryFilterButton.setToolTipText("Filters Dialog"); ancillaryFilterButton.setToolTipText("Filters Dialog");
parentPanel.add(ancillaryFilterButton, BorderLayout.EAST); parentPanel.add(ancillaryFilterButton, BorderLayout.EAST);
@ -453,7 +452,7 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
} }
@Override @Override
public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool t, ActionContext context) {
ListingCodeComparisonPanel dualListingPanel = functionComparisonPanel.getDualListingPanel(); ListingCodeComparisonPanel dualListingPanel = functionComparisonPanel.getDualListingPanel();
if (context.getComponentProvider() == this && dualListingPanel != null) { if (context.getComponentProvider() == this && dualListingPanel != null) {
ListingPanel sourcePanel = dualListingPanel.getLeftPanel(); ListingPanel sourcePanel = dualListingPanel.getLeftPanel();
@ -853,8 +852,8 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
int filteredCount = markupItemsTableModel.getRowCount(); int filteredCount = markupItemsTableModel.getRowCount();
int unfilteredCount = markupItemsTableModel.getUnfilteredRowCount(); int unfilteredCount = markupItemsTableModel.getUnfilteredRowCount();
int filteredOutCount = unfilteredCount - filteredCount; int filteredOutCount = unfilteredCount - filteredCount;
ancillaryFilterButton.setToolTipText( ancillaryFilterButton
"More Filters - " + filteredOutCount + " item(s) hidden"); .setToolTipText("More Filters - " + filteredOutCount + " item(s) hidden");
} }
else { else {
ancillaryFilterButton.setToolTipText("More Filters - no active filters"); ancillaryFilterButton.setToolTipText("More Filters - no active filters");

View file

@ -47,12 +47,7 @@ public class ApplyMarkupItemTask extends VtTask {
return markupItems.size() > 20; return markupItems.size() > 20;
} }
/** // Template Method pattern to allow subclasses to plug-in to this task.
* Template Method pattern to allow subclasses to plug-in to this task.
* @param markupItem the markup
* @param markupItemOptions
* @return
*/
protected VTMarkupItemApplyActionType getApplyActionType(VTMarkupItem markupItem, protected VTMarkupItemApplyActionType getApplyActionType(VTMarkupItem markupItem,
ToolOptions markupItemOptions) { ToolOptions markupItemOptions) {
VTMarkupType markupType = markupItem.getMarkupType(); VTMarkupType markupType = markupItem.getMarkupType();

View file

@ -43,13 +43,10 @@ public class ClearMatchTask extends VtTask {
this.controller = controller; this.controller = controller;
this.matches = matches; this.matches = matches;
VTSession session = controller.getSession();
if (!(session instanceof VTSessionDB)) { if (!(session instanceof VTSessionDB)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Unexpected condition - VTSession is not a DB object!"); "Unexpected condition - VTSession is not a DB object!");
} }
} }
@Override @Override

View file

@ -22,7 +22,6 @@ import java.util.*;
import ghidra.feature.vt.api.impl.MatchSetImpl; import ghidra.feature.vt.api.impl.MatchSetImpl;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager; import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager;
import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.feature.vt.gui.provider.impliedmatches.VTImpliedMatchInfo; import ghidra.feature.vt.gui.provider.impliedmatches.VTImpliedMatchInfo;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -38,23 +37,106 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class ImpliedMatchUtils { public class ImpliedMatchUtils {
/**
* Called when a {@link VTAssociation} is accepted. This method will create implied matches in
* the current session based on the association.
* @param sourceFunction The matched function from the source program
* @param destinationFunction The matched function from the destination program
* @param session The Version Tracking session
* @param correlatorManager Keeps track of which section of the source function corresponds to
* the which section of the destination function
* @param monitor Handles user cancellations
* @throws CancelledException if cancelled
*/
public static void updateImpliedMatchForAcceptedAssocation(Function sourceFunction,
Function destinationFunction, VTSession session,
AddressCorrelatorManager correlatorManager, TaskMonitor monitor)
throws CancelledException {
Set<VTImpliedMatchInfo> impliedMatches = findImpliedMatches(sourceFunction,
destinationFunction, session, correlatorManager, monitor);
for (VTImpliedMatchInfo impliedMatch : impliedMatches) {
Address sourceAddress = impliedMatch.getSourceAddress();
Address destinationAddress = impliedMatch.getDestinationAddress();
VTAssociation existingAssociation =
session.getAssociationManager().getAssociation(sourceAddress, destinationAddress);
if (existingAssociation == null) {
VTMatchSet impliedMatchSet = session.getImpliedMatchSet();
VTMatch match = impliedMatchSet.addMatch(impliedMatch);
existingAssociation = match.getAssociation();
}
if (existingAssociation != null) {
existingAssociation.setVoteCount(existingAssociation.getVoteCount() + 1);
}
}
}
/**
* Called when a {@link VTAssociation} is cleared. This method will create implied matches in
* the current session based on the association.
* @param sourceFunction The matched function from the source program
* @param destinationFunction The matched function from the destination program
* @param session The Version Tracking session
* @param correlatorManager Keeps track of which section of the source function corresponds to
* the which section of the destination function
* @param monitor Handles user cancellations
* @throws CancelledException if cancelled
*/
public static void updateImpliedMatchForClearedAssocation(Function sourceFunction,
Function destinationFunction, VTSession session,
AddressCorrelatorManager correlatorManager, TaskMonitor monitor)
throws CancelledException {
Set<VTImpliedMatchInfo> impliedMatches = ImpliedMatchUtils.findImpliedMatches(
sourceFunction, destinationFunction, session, correlatorManager, monitor);
for (VTImpliedMatchInfo impliedMatch : impliedMatches) {
Address sourceAddress = impliedMatch.getSourceAddress();
Address destinationAddress = impliedMatch.getDestinationAddress();
VTAssociation existingAssociation =
session.getAssociationManager().getAssociation(sourceAddress, destinationAddress);
if (existingAssociation != null) {
int newVoteCount = Math.max(0, existingAssociation.getVoteCount() - 1);
existingAssociation.setVoteCount(newVoteCount);
if (newVoteCount == 0) {
removeImpliedMatch(existingAssociation);
}
}
}
}
private static void removeImpliedMatch(VTAssociation existingAssociation) {
VTSession session = existingAssociation.getSession();
List<VTMatch> matches = session.getMatches(existingAssociation);
VTMatchSet impliedMatchSet = session.getImpliedMatchSet();
for (VTMatch vtMatch : matches) {
if (vtMatch.getMatchSet() == impliedMatchSet) {
impliedMatchSet.removeMatch(vtMatch);
}
}
}
/** /**
* Method for finding version tracking implied matches given an accepted matched * Method for finding version tracking implied matches given an accepted matched
* function. Each referenced data and function that exist in equivalent sections * function. Each referenced data and function that exist in equivalent sections
* of the matched source and destination functions will added to the current * of the matched source and destination functions will added to the current
* version tracking session as an implied match. * version tracking session as an implied match.
* *
* @param controller Version Tracking controller for the current VT tool
* @param sourceFunction The matched function from the source program * @param sourceFunction The matched function from the source program
* @param destinationFunction The matched function from the destination program * @param destinationFunction The matched function from the destination program
* @param session The Version Tracking session * @param session The Version Tracking session
* @param correlationManager Keeps track of which section of the source function corresponds to * @param correlatorManager Keeps track of which section of the source function corresponds to
* the which section of the destination function * the which section of the destination function
* @param monitor Handles user cancellations * @param monitor Handles user cancellations
* @return a set of VTImpliedMatchInfo objects * @return a set of VTImpliedMatchInfo objects
* @throws CancelledException if cancelled
*/ */
public static Set<VTImpliedMatchInfo> findImpliedMatches(VTController controller, public static Set<VTImpliedMatchInfo> findImpliedMatches(Function sourceFunction,
Function sourceFunction, Function destinationFunction, VTSession session, Function destinationFunction, VTSession session,
AddressCorrelatorManager correlatorManager, TaskMonitor monitor) AddressCorrelatorManager correlatorManager, TaskMonitor monitor)
throws CancelledException { throws CancelledException {
Set<VTImpliedMatchInfo> set = new HashSet<>(); Set<VTImpliedMatchInfo> set = new HashSet<>();
@ -141,8 +223,9 @@ public class ImpliedMatchUtils {
if (refType.isData()) { if (refType.isData()) {
type = DATA; type = DATA;
if (sourceFunction.getProgram().getListing().getInstructionAt( if (sourceFunction.getProgram()
srcRefToAddress) != null) { .getListing()
.getInstructionAt(srcRefToAddress) != null) {
if (refType != RefType.DATA) { if (refType != RefType.DATA) {
return null; // read/write reference to instruction - not sure what this is return null; // read/write reference to instruction - not sure what this is
} }
@ -155,8 +238,9 @@ public class ImpliedMatchUtils {
} }
if (type == FUNCTION) { if (type == FUNCTION) {
if (sourceFunction.getProgram().getFunctionManager().getFunctionAt( if (sourceFunction.getProgram()
srcRefToAddress) == null) { .getFunctionManager()
.getFunctionAt(srcRefToAddress) == null) {
return null; // function may not have been created here. return null; // function may not have been created here.
} }
} }
@ -175,7 +259,7 @@ public class ImpliedMatchUtils {
/** /**
* This method checks to see if the given reference is a thunk function and if so returns * This method checks to see if the given reference is a thunk function and if so returns
* the address of the thunked function instead of thunk function * the address of the thunked function instead of thunk function
* @param program * @param program the program
* @param refToAddress The address of the interesting reference * @param refToAddress The address of the interesting reference
* @return Returns either the same address passed in or the address of the thunked function if * @return Returns either the same address passed in or the address of the thunked function if
* the original address refers to a thunk * the original address refers to a thunk
@ -196,7 +280,8 @@ public class ImpliedMatchUtils {
} }
/** /**
* Updates the length values for the source and dest functions or data in the VTMatchInfo object * Updates the length values for the source and destination functions or data in the
* VTMatchInfo object
*/ */
private static void updateVTSourceAndDestinationLengths(VTMatchInfo matchInfo) { private static void updateVTSourceAndDestinationLengths(VTMatchInfo matchInfo) {
VTSession session = matchInfo.getMatchSet().getSession(); VTSession session = matchInfo.getMatchSet().getSession();

View file

@ -15,17 +15,17 @@
*/ */
package ghidra.feature.vt.gui.util; package ghidra.feature.vt.gui.util;
import java.util.*;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.markuptype.*; import ghidra.feature.vt.api.markuptype.*;
import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager; import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager;
import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.program.util.*; import ghidra.program.util.*;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.*; import ghidra.util.task.CachingSwingWorker;
import ghidra.util.task.TaskMonitor;
import java.util.*;
public class MatchInfo { public class MatchInfo {
@ -43,7 +43,7 @@ public class MatchInfo {
private boolean initCorrelationCache = true; private boolean initCorrelationCache = true;
private final AddressCorrelatorManager correlator; private final AddressCorrelatorManager correlator;
MatchInfo(VTController controller, VTMatch match, AddressCorrelatorManager correlator) { MatchInfo(VTMatch match, AddressCorrelatorManager correlator) {
this.match = match; this.match = match;
this.correlator = correlator; this.correlator = correlator;
VTAssociation association = match.getAssociation(); VTAssociation association = match.getAssociation();
@ -54,9 +54,9 @@ public class MatchInfo {
VTAssociationType type = association.getType(); VTAssociationType type = association.getType();
Address sourceAddress = association.getSourceAddress(); Address sourceAddress = association.getSourceAddress();
sourceFunction = sourceFunction = (sourceProgram != null)
(sourceProgram != null) ? sourceProgram.getFunctionManager().getFunctionAt( ? sourceProgram.getFunctionManager().getFunctionAt(sourceAddress)
sourceAddress) : null; : null;
if (type == VTAssociationType.FUNCTION && sourceFunction != null) { if (type == VTAssociationType.FUNCTION && sourceFunction != null) {
sourceData = null; sourceData = null;
sourceAddressSet = sourceFunction.getBody(); sourceAddressSet = sourceFunction.getBody();
@ -75,9 +75,9 @@ public class MatchInfo {
} }
Address destinationAddress = association.getDestinationAddress(); Address destinationAddress = association.getDestinationAddress();
destinationFunction = destinationFunction = (destinationProgram != null)
(destinationProgram != null) ? destinationProgram.getFunctionManager().getFunctionAt( ? destinationProgram.getFunctionManager().getFunctionAt(destinationAddress)
destinationAddress) : null; : null;
if (type == VTAssociationType.FUNCTION && destinationFunction != null) { if (type == VTAssociationType.FUNCTION && destinationFunction != null) {
destinationData = null; destinationData = null;
destinationAddressSet = destinationFunction.getBody(); destinationAddressSet = destinationFunction.getBody();
@ -211,8 +211,7 @@ public class MatchInfo {
AddressRange correlatedDestinationRange = null; AddressRange correlatedDestinationRange = null;
try { try {
correlatedDestinationRange = correlatedDestinationRange =
addressTranslator.getCorrelatedDestinationRange(sourceAddress, addressTranslator.getCorrelatedDestinationRange(sourceAddress, TaskMonitor.DUMMY);
TaskMonitor.DUMMY);
} }
catch (CancelledException e) { catch (CancelledException e) {
// check for null below // check for null below
@ -223,7 +222,8 @@ public class MatchInfo {
return correlatedDestinationRange.getMinAddress(); return correlatedDestinationRange.getMinAddress();
} }
public VTMarkupItem getCurrentMarkupForLocation(ProgramLocation programLocation, Program program) { public VTMarkupItem getCurrentMarkupForLocation(ProgramLocation programLocation,
Program program) {
VTMarkupType markupType = getMarkupTypeForLocation(programLocation, program); VTMarkupType markupType = getMarkupTypeForLocation(programLocation, program);
if (markupType == null) { if (markupType == null) {
@ -248,15 +248,13 @@ public class MatchInfo {
} }
for (VTMarkupItem markupItem : list) { for (VTMarkupItem markupItem : list) {
ProgramLocation location = ProgramLocation location = isSourceAddress ? markupItem.getSourceLocation()
isSourceAddress ? markupItem.getSourceLocation()
: markupItem.getDestinationLocation(); : markupItem.getDestinationLocation();
if (location == null) { if (location == null) {
continue; continue;
} }
Address markupItemAddress = Address markupItemAddress = MatchInfo.getMarkupAddressForLocation(location,
MatchInfo.getMarkupAddressForLocation(location, (isSourceAddress ? sourceProgram (isSourceAddress ? sourceProgram : destinationProgram));
: destinationProgram));
if (address.equals(markupItemAddress) && (markupItem.getMarkupType() == markupType)) { if (address.equals(markupItemAddress) && (markupItem.getMarkupType() == markupType)) {
return markupItem; return markupItem;
} }

View file

@ -21,7 +21,6 @@ import java.util.Set;
import ghidra.feature.vt.api.main.VTAssociation; import ghidra.feature.vt.api.main.VTAssociation;
import ghidra.feature.vt.api.main.VTMatch; import ghidra.feature.vt.api.main.VTMatch;
import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager; import ghidra.feature.vt.gui.plugin.AddressCorrelatorManager;
import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.util.datastruct.WeakValueHashMap; import ghidra.util.datastruct.WeakValueHashMap;
public class MatchInfoFactory { public class MatchInfoFactory {
@ -32,11 +31,10 @@ public class MatchInfoFactory {
*/ */
private WeakValueHashMap<VTMatch, MatchInfo> weakMap = new WeakValueHashMap<>(); private WeakValueHashMap<VTMatch, MatchInfo> weakMap = new WeakValueHashMap<>();
public synchronized MatchInfo getMatchInfo(VTController controller, VTMatch match, public synchronized MatchInfo getMatchInfo(VTMatch match, AddressCorrelatorManager correlator) {
AddressCorrelatorManager correlator) {
MatchInfo matchInfo = weakMap.get(match); MatchInfo matchInfo = weakMap.get(match);
if (matchInfo == null) { if (matchInfo == null) {
matchInfo = new MatchInfo(controller, match, correlator); matchInfo = new MatchInfo(match, correlator);
weakMap.put(match, matchInfo); weakMap.put(match, matchInfo);
} }
return matchInfo; return matchInfo;
@ -57,6 +55,7 @@ public class MatchInfoFactory {
/** /**
* Clear the cached match info for the given association. This will clear the cache for * Clear the cached match info for the given association. This will clear the cache for
* multiple matches, if multiple matches exit for the given association. * multiple matches, if multiple matches exit for the given association.
* @param association the association
*/ */
public synchronized void clearCacheForAssociation(VTAssociation association) { public synchronized void clearCacheForAssociation(VTAssociation association) {
Set<Entry<VTMatch, MatchInfo>> entrySet = weakMap.entrySet(); Set<Entry<VTMatch, MatchInfo>> entrySet = weakMap.entrySet();

View file

@ -24,7 +24,6 @@ import ghidra.feature.vt.api.util.VTOptions;
import ghidra.feature.vt.gui.plugin.VTController; import ghidra.feature.vt.gui.plugin.VTController;
import ghidra.feature.vt.gui.wizard.ChooseAddressSetEditorPanel.AddressSetChoice; import ghidra.feature.vt.gui.wizard.ChooseAddressSetEditorPanel.AddressSetChoice;
import ghidra.framework.data.DomainObjectAdapterDB; import ghidra.framework.data.DomainObjectAdapterDB;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.AddressSet; import ghidra.program.model.address.AddressSet;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -101,8 +100,6 @@ public class AddToSessionTask extends Task {
destinationAddressSet = excludeAcceptedMatches(destinationAddressSet, false); destinationAddressSet = excludeAcceptedMatches(destinationAddressSet, false);
} }
ServiceProvider serviceProvider = controller.getTool();
int transactionID = startTransaction(session); int transactionID = startTransaction(session);
boolean completedSucessfully = false; boolean completedSucessfully = false;
try { try {
@ -113,8 +110,8 @@ public class AddToSessionTask extends Task {
for (int i = 0; i < correlatorFactories.size(); i++) { for (int i = 0; i < correlatorFactories.size(); i++) {
VTProgramCorrelatorFactory factory = correlatorFactories.get(i); VTProgramCorrelatorFactory factory = correlatorFactories.get(i);
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
factory.createCorrelator(serviceProvider, sourceProgram, sourceAddressSet, factory.createCorrelator(sourceProgram, sourceAddressSet, destinationProgram,
destinationProgram, destinationAddressSet, correlatorOptions.get(i)); destinationAddressSet, correlatorOptions.get(i));
VTMatchSet resultSet = correlator.correlate(session, monitor); VTMatchSet resultSet = correlator.correlate(session, monitor);
if (resultSet.getMatchCount() == 0) { if (resultSet.getMatchCount() == 0) {
@ -134,13 +131,15 @@ public class AddToSessionTask extends Task {
} }
catch (CancelledException e) { catch (CancelledException e) {
Throwable cause = e.getCause(); // CancelledException may hide more serious error Throwable cause = e.getCause(); // CancelledException may hide more serious error
if (cause == null) if (cause == null) {
Msg.showWarn(this, null, "Add to Session Cancelled", Msg.showWarn(this, null, "Add to Session Cancelled",
"Correlation canceled by user."); "Correlation canceled by user.");
else }
else {
Msg.showError(this, null, "Add to Session Cancelled - Unexpected Exception", Msg.showError(this, null, "Add to Session Cancelled - Unexpected Exception",
"Correlation cancelled due to exception: " + cause.getMessage(), e); "Correlation cancelled due to exception: " + cause.getMessage(), e);
} }
}
catch (Exception e) { catch (Exception e) {
Msg.showError(this, null, "Add to Session Cancelled - Unexpected Exception", Msg.showError(this, null, "Add to Session Cancelled - Unexpected Exception",
"Correlation cancelled due to exception: " + e.getMessage(), e); "Correlation cancelled due to exception: " + e.getMessage(), e);

View file

@ -781,7 +781,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
private VTMatch createMatch(Address sourceAddress, Address destinationAddress, private VTMatch createMatch(Address sourceAddress, Address destinationAddress,
boolean setAccepted) throws VTAssociationStatusException { boolean setAccepted) throws VTAssociationStatusException {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
VTTestUtils.createProgramCorrelator(null, sourceProgram, destinationProgram); VTTestUtils.createProgramCorrelator(sourceProgram, destinationProgram);
String transactionName = "Blocked Test"; String transactionName = "Blocked Test";
int startTransaction = session.startTransaction(transactionName); int startTransaction = session.startTransaction(transactionName);
@ -826,7 +826,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
private void runAutoVTCommand(double minReferenceCorrelatorScore, private void runAutoVTCommand(double minReferenceCorrelatorScore,
double minReferenceCorrelatorConfidence) { double minReferenceCorrelatorConfidence) {
AutoVersionTrackingTask task = new AutoVersionTrackingTask(controller, session, AutoVersionTrackingTask task = new AutoVersionTrackingTask(session, controller.getOptions(),
minReferenceCorrelatorScore, minReferenceCorrelatorConfidence); minReferenceCorrelatorScore, minReferenceCorrelatorConfidence);
TaskLauncher.launch(task); TaskLauncher.launch(task);
waitForSession(); waitForSession();

View file

@ -52,7 +52,8 @@ import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.test.*; import ghidra.test.*;
import ghidra.util.SystemUtilities; import ghidra.util.SystemUtilities;
import ghidra.util.exception.*; import ghidra.util.exception.*;
import ghidra.util.task.*; import ghidra.util.task.Task;
import ghidra.util.task.TaskMonitor;
public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest { public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
@ -540,8 +541,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choices // data type choices
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
ReplaceDataChoices.EXCLUDE); .setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, ReplaceDataChoices.EXCLUDE);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -573,7 +574,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choice // data type choice
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
.setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE,
ReplaceDataChoices.REPLACE_UNDEFINED_DATA_ONLY); ReplaceDataChoices.REPLACE_UNDEFINED_DATA_ONLY);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
@ -602,7 +604,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choice // data type choice
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
.setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE,
ReplaceDataChoices.REPLACE_UNDEFINED_DATA_ONLY); ReplaceDataChoices.REPLACE_UNDEFINED_DATA_ONLY);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
@ -644,7 +647,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choice // data type choice
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
.setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE,
ReplaceDataChoices.REPLACE_FIRST_DATA_ONLY); ReplaceDataChoices.REPLACE_FIRST_DATA_ONLY);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
@ -675,7 +679,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choice // data type choice
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
.setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE,
ReplaceDataChoices.REPLACE_FIRST_DATA_ONLY); ReplaceDataChoices.REPLACE_FIRST_DATA_ONLY);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
@ -716,8 +721,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choice // data type choice
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
ReplaceDataChoices.REPLACE_ALL_DATA); .setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, ReplaceDataChoices.REPLACE_ALL_DATA);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -761,8 +766,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress); VTMatch match = createMatchSetWithOneDataMatch(session, sourceAddress, destinationAddress);
// data type choice // data type choice
controller.getOptions().setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, controller.getOptions()
ReplaceDataChoices.REPLACE_ALL_DATA); .setEnum(VTOptionDefines.DATA_MATCH_DATA_TYPE, ReplaceDataChoices.REPLACE_ALL_DATA);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -830,8 +835,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("FUN_01003f9e", destinationFunction.getName()); assertEquals("FUN_01003f9e", destinationFunction.getName());
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_NAME, controller.getOptions()
FunctionNameChoices.REPLACE_DEFAULT_ONLY); .setEnum(VTOptionDefines.FUNCTION_NAME, FunctionNameChoices.REPLACE_DEFAULT_ONLY);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -868,8 +873,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("Bar", destinationFunction.getName()); assertEquals("Bar", destinationFunction.getName());
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_NAME, controller.getOptions()
FunctionNameChoices.REPLACE_DEFAULT_ONLY); .setEnum(VTOptionDefines.FUNCTION_NAME, FunctionNameChoices.REPLACE_DEFAULT_ONLY);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -897,8 +902,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("FUN_01003f9e", destinationFunction.getName()); assertEquals("FUN_01003f9e", destinationFunction.getName());
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_NAME, controller.getOptions()
FunctionNameChoices.REPLACE_ALWAYS); .setEnum(VTOptionDefines.FUNCTION_NAME, FunctionNameChoices.REPLACE_ALWAYS);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -935,8 +940,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("Bar", destinationFunction.getName()); assertEquals("Bar", destinationFunction.getName());
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_NAME, controller.getOptions()
FunctionNameChoices.REPLACE_ALWAYS); .setEnum(VTOptionDefines.FUNCTION_NAME, FunctionNameChoices.REPLACE_ALWAYS);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -1063,8 +1068,7 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
setComment(destinationProgram, commentAddress, CodeUnit.EOL_COMMENT, destinationComment); setComment(destinationProgram, commentAddress, CodeUnit.EOL_COMMENT, destinationComment);
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> markupItems = Collection<VTMarkupItem> markupItems = matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
List<VTMarkupItem> itemsToApply = new ArrayList<>(); List<VTMarkupItem> itemsToApply = new ArrayList<>();
for (VTMarkupItem item : markupItems) { for (VTMarkupItem item : markupItems) {
@ -1142,8 +1146,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
checkReturnType(dWordDataType, destinationFunction); checkReturnType(dWordDataType, destinationFunction);
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_SIGNATURE, controller.getOptions()
FunctionSignatureChoices.EXCLUDE); .setEnum(VTOptionDefines.FUNCTION_SIGNATURE, FunctionSignatureChoices.EXCLUDE);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -1173,10 +1177,10 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
checkReturnType(dWordDataType, destinationFunction); checkReturnType(dWordDataType, destinationFunction);
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_SIGNATURE, controller.getOptions()
FunctionSignatureChoices.REPLACE); .setEnum(VTOptionDefines.FUNCTION_SIGNATURE, FunctionSignatureChoices.REPLACE);
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_RETURN_TYPE, controller.getOptions()
ParameterDataTypeChoices.REPLACE); .setEnum(VTOptionDefines.FUNCTION_RETURN_TYPE, ParameterDataTypeChoices.REPLACE);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
matches.add(match); matches.add(match);
@ -1211,10 +1215,10 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
setupParameters(sourceFunction, destinationFunction); setupParameters(sourceFunction, destinationFunction);
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_SIGNATURE, controller.getOptions()
FunctionSignatureChoices.EXCLUDE); .setEnum(VTOptionDefines.FUNCTION_SIGNATURE, FunctionSignatureChoices.EXCLUDE);
controller.getOptions().setEnum(VTOptionDefines.PARAMETER_NAMES, controller.getOptions()
SourcePriorityChoices.EXCLUDE); .setEnum(VTOptionDefines.PARAMETER_NAMES, SourcePriorityChoices.EXCLUDE);
controller.getOptions().setEnum(VTOptionDefines.PARAMETER_COMMENTS, CommentChoices.EXCLUDE); controller.getOptions().setEnum(VTOptionDefines.PARAMETER_COMMENTS, CommentChoices.EXCLUDE);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
@ -1266,14 +1270,14 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
setupParameters(sourceFunction, destinationFunction); setupParameters(sourceFunction, destinationFunction);
// function name choices // function name choices
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_SIGNATURE, controller.getOptions()
FunctionSignatureChoices.REPLACE); .setEnum(VTOptionDefines.FUNCTION_SIGNATURE, FunctionSignatureChoices.REPLACE);
controller.getOptions().setEnum(VTOptionDefines.FUNCTION_RETURN_TYPE, controller.getOptions()
ParameterDataTypeChoices.REPLACE); .setEnum(VTOptionDefines.FUNCTION_RETURN_TYPE, ParameterDataTypeChoices.REPLACE);
controller.getOptions().setEnum(VTOptionDefines.PARAMETER_DATA_TYPES, controller.getOptions()
ParameterDataTypeChoices.REPLACE); .setEnum(VTOptionDefines.PARAMETER_DATA_TYPES, ParameterDataTypeChoices.REPLACE);
controller.getOptions().setEnum(VTOptionDefines.PARAMETER_NAMES, controller.getOptions()
SourcePriorityChoices.EXCLUDE); .setEnum(VTOptionDefines.PARAMETER_NAMES, SourcePriorityChoices.EXCLUDE);
controller.getOptions().setEnum(VTOptionDefines.PARAMETER_COMMENTS, CommentChoices.EXCLUDE); controller.getOptions().setEnum(VTOptionDefines.PARAMETER_COMMENTS, CommentChoices.EXCLUDE);
List<VTMatch> matches = new ArrayList<>(); List<VTMatch> matches = new ArrayList<>();
@ -2102,7 +2106,7 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
try { try {
testTransactionID = db.startTransaction("Test Match Set Setup"); testTransactionID = db.startTransaction("Test Match Set Setup");
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
for (AssociationPair associationPair : list) { for (AssociationPair associationPair : list) {
VTMatchInfo info = createRandomMatch(associationPair.getSourceAddress(), VTMatchInfo info = createRandomMatch(associationPair.getSourceAddress(),
associationPair.getDestinationAddress(), db); associationPair.getDestinationAddress(), db);

View file

@ -253,7 +253,7 @@ public abstract class AbstractVTCorrelatorTest extends AbstractGhidraHeadedInteg
try { try {
testTransactionID = db.startTransaction("Test Match Set Setup"); testTransactionID = db.startTransaction("Test Match Set Setup");
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
for (VTAssociationPair associationPair : list) { for (VTAssociationPair associationPair : list) {
VTMatchInfo info = createRandomMatch(associationPair.getSource(), VTMatchInfo info = createRandomMatch(associationPair.getSource(),
associationPair.getDestination(), db); associationPair.getDestination(), db);

View file

@ -201,20 +201,34 @@ public class VTImpliedMatchCorrelatorTest extends AbstractVTCorrelatorTest {
VTAssociationManager associationManager = session.getAssociationManager(); VTAssociationManager associationManager = session.getAssociationManager();
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x00411860"), assertEquals(1,
addr(destProg, "0x00411830")).getVoteCount()); // addPerson associationManager
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x004168a0"), .getAssociation(addr(srcProg, "0x00411860"), addr(destProg, "0x00411830"))
addr(destProg, "0x004168a0")).getVoteCount()); // s_Lord_Victor_Quartermaine .getVoteCount()); // addPerson
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x0041688c"), assertEquals(1,
addr(destProg, "0x00041688c")).getVoteCount()); // s_Lady_Tottington associationManager
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x004168a0"), .getAssociation(addr(srcProg, "0x004168a0"), addr(destProg, "0x004168a0"))
addr(destProg, "0x004168a0")).getVoteCount()); // s_Were_Rabbit .getVoteCount()); // s_Lord_Victor_Quartermaine
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x0041687c"), assertEquals(1,
addr(destProg, "0x0041687c")).getVoteCount()); // s_Rabbit associationManager
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x00416874"), .getAssociation(addr(srcProg, "0x0041688c"), addr(destProg, "0x00041688c"))
addr(destProg, "0x00416874")).getVoteCount()); // s_Wallace .getVoteCount()); // s_Lady_Tottington
assertEquals(1, associationManager.getAssociation(addr(srcProg, "0x00411b80"), assertEquals(1,
addr(destProg, "0x00411b60")).getVoteCount()); // __RTC_CheckEsp associationManager
.getAssociation(addr(srcProg, "0x004168a0"), addr(destProg, "0x004168a0"))
.getVoteCount()); // s_Were_Rabbit
assertEquals(1,
associationManager
.getAssociation(addr(srcProg, "0x0041687c"), addr(destProg, "0x0041687c"))
.getVoteCount()); // s_Rabbit
assertEquals(1,
associationManager
.getAssociation(addr(srcProg, "0x00416874"), addr(destProg, "0x00416874"))
.getVoteCount()); // s_Wallace
assertEquals(1,
associationManager
.getAssociation(addr(srcProg, "0x00411b80"), addr(destProg, "0x00411b60"))
.getVoteCount()); // __RTC_CheckEsp
} }
@ -222,7 +236,7 @@ public class VTImpliedMatchCorrelatorTest extends AbstractVTCorrelatorTest {
Program sourceProgram, Program destinationProgram, boolean setAccepted) Program sourceProgram, Program destinationProgram, boolean setAccepted)
throws VTAssociationStatusException { throws VTAssociationStatusException {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
VTTestUtils.createProgramCorrelator(null, sourceProgram, destinationProgram); VTTestUtils.createProgramCorrelator(sourceProgram, destinationProgram);
String transactionName = "Blocked Test"; String transactionName = "Blocked Test";
int startTransaction = session.startTransaction(transactionName); int startTransaction = session.startTransaction(transactionName);
@ -237,10 +251,14 @@ public class VTImpliedMatchCorrelatorTest extends AbstractVTCorrelatorTest {
info.setConfidenceScore(confidence); info.setConfidenceScore(confidence);
VTScore score = new VTScore(1.0); VTScore score = new VTScore(1.0);
info.setSimilarityScore(score); info.setSimilarityScore(score);
long sourceLen = sourceProgram.getFunctionManager().getFunctionAt( long sourceLen = sourceProgram.getFunctionManager()
sourceAddress).getBody().getNumAddresses(); .getFunctionAt(sourceAddress)
long destLen = destinationProgram.getFunctionManager().getFunctionAt( .getBody()
destinationAddress).getBody().getNumAddresses(); .getNumAddresses();
long destLen = destinationProgram.getFunctionManager()
.getFunctionAt(destinationAddress)
.getBody()
.getNumAddresses();
info.setSourceLength((int) sourceLen); info.setSourceLength((int) sourceLen);
info.setDestinationLength((int) destLen); info.setDestinationLength((int) destLen);
matchSet.addMatch(info); matchSet.addMatch(info);

View file

@ -24,7 +24,6 @@ import ghidra.feature.vt.api.correlator.program.ExactMatchBytesProgramCorrelator
import ghidra.feature.vt.api.db.VTSessionDB; import ghidra.feature.vt.api.db.VTSessionDB;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTOptions; import ghidra.feature.vt.api.util.VTOptions;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView; import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
@ -41,7 +40,6 @@ public abstract class AbstractCorrelatorTest extends AbstractGhidraHeadedIntegra
protected ArrayList<String> errors; protected ArrayList<String> errors;
public AbstractCorrelatorTest() { public AbstractCorrelatorTest() {
super();
} }
protected abstract Program getSourceProgram(); protected abstract Program getSourceProgram();
@ -87,7 +85,6 @@ public abstract class AbstractCorrelatorTest extends AbstractGhidraHeadedIntegra
try { try {
int sessionTransaction = session.startTransaction(name); int sessionTransaction = session.startTransaction(name);
try { try {
PluginTool serviceProvider = env.getTool();
VTAssociationManager manager = session.getAssociationManager(); VTAssociationManager manager = session.getAssociationManager();
AddressSetView sourceAddressSet = AddressSetView sourceAddressSet =
@ -98,8 +95,8 @@ public abstract class AbstractCorrelatorTest extends AbstractGhidraHeadedIntegra
VTOptions options; VTOptions options;
VTProgramCorrelator correlator; VTProgramCorrelator correlator;
options = factory.createDefaultOptions(); options = factory.createDefaultOptions();
correlator = factory.createCorrelator(serviceProvider, sourceProgram, correlator = factory.createCorrelator(sourceProgram, sourceAddressSet,
sourceAddressSet, destinationProgram, destinationAddressSet, options); destinationProgram, destinationAddressSet, options);
correlator.correlate(session, TaskMonitor.DUMMY); correlator.correlate(session, TaskMonitor.DUMMY);
FunctionManager functionManager = sourceProgram.getFunctionManager(); FunctionManager functionManager = sourceProgram.getFunctionManager();
@ -154,7 +151,6 @@ public abstract class AbstractCorrelatorTest extends AbstractGhidraHeadedIntegra
try { try {
int sessionTransaction = session.startTransaction(name); int sessionTransaction = session.startTransaction(name);
try { try {
PluginTool serviceProvider = env.getTool();
VTAssociationManager manager = session.getAssociationManager(); VTAssociationManager manager = session.getAssociationManager();
AddressSetView sourceAddressSet = AddressSetView sourceAddressSet =
@ -165,8 +161,8 @@ public abstract class AbstractCorrelatorTest extends AbstractGhidraHeadedIntegra
VTOptions options; VTOptions options;
VTProgramCorrelator correlator; VTProgramCorrelator correlator;
options = factory.createDefaultOptions(); options = factory.createDefaultOptions();
correlator = factory.createCorrelator(serviceProvider, sourceProgram, correlator = factory.createCorrelator(sourceProgram, sourceAddressSet,
sourceAddressSet, destinationProgram, destinationAddressSet, options); destinationProgram, destinationAddressSet, options);
correlator.correlate(session, TaskMonitor.DUMMY); correlator.correlate(session, TaskMonitor.DUMMY);
HashMap<Address, Address> mapCopy = new HashMap<>(map); HashMap<Address, Address> mapCopy = new HashMap<>(map);

View file

@ -17,8 +17,7 @@ package ghidra.feature.vt.api.markupitem;
import static ghidra.feature.vt.db.VTTestUtils.*; import static ghidra.feature.vt.db.VTTestUtils.*;
import static ghidra.feature.vt.gui.util.VTOptionDefines.*; import static ghidra.feature.vt.gui.util.VTOptionDefines.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -37,7 +36,6 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet; import ghidra.program.model.address.AddressSet;
import ghidra.test.*; import ghidra.test.*;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import ghidra.util.task.TaskMonitorAdapter;
public abstract class AbstractVTMarkupItemTest extends AbstractGhidraHeadedIntegrationTest { public abstract class AbstractVTMarkupItemTest extends AbstractGhidraHeadedIntegrationTest {
@ -361,7 +359,7 @@ public abstract class AbstractVTMarkupItemTest extends AbstractGhidraHeadedInteg
testTransactionID = db.startTransaction("Test Match Set Setup"); testTransactionID = db.startTransaction("Test Match Set Setup");
VTMatchInfo matchInfo = createRandomMatch(sourceAddress, destinationAddress, db); VTMatchInfo matchInfo = createRandomMatch(sourceAddress, destinationAddress, db);
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch addedMatch = matchSet.addMatch(matchInfo); VTMatch addedMatch = matchSet.addMatch(matchInfo);
// Association markupItemManger expects all markups to be generated though it. // Association markupItemManger expects all markups to be generated though it.

View file

@ -55,7 +55,7 @@ public class VTMarkupItemResetTest extends VTBaseTestCase {
// destination address is cleared *and not other user-defined values are set*. // destination address is cleared *and not other user-defined values are set*.
// //
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch match = matchSet.addMatch(createRandomMatch(db)); VTMatch match = matchSet.addMatch(createRandomMatch(db));
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);
@ -80,7 +80,7 @@ public class VTMarkupItemResetTest extends VTBaseTestCase {
// user's considered state is cleared *and not other user-defined values are set*. // user's considered state is cleared *and not other user-defined values are set*.
// //
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch match = matchSet.addMatch(createRandomMatch(db)); VTMatch match = matchSet.addMatch(createRandomMatch(db));
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);
@ -104,7 +104,7 @@ public class VTMarkupItemResetTest extends VTBaseTestCase {
// markup item is unapplied *and not other user-defined values are set*. // markup item is unapplied *and not other user-defined values are set*.
// //
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch match = matchSet.addMatch(createRandomMatch(db)); VTMatch match = matchSet.addMatch(createRandomMatch(db));
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);
@ -146,7 +146,7 @@ public class VTMarkupItemResetTest extends VTBaseTestCase {
// is set by the user. // is set by the user.
// //
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch match = matchSet.addMatch(createRandomMatch(db)); VTMatch match = matchSet.addMatch(createRandomMatch(db));
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);
@ -186,7 +186,7 @@ public class VTMarkupItemResetTest extends VTBaseTestCase {
// the the destination address is set by the user. // the the destination address is set by the user.
// //
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch match = matchSet.addMatch(createRandomMatch(db)); VTMatch match = matchSet.addMatch(createRandomMatch(db));
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);
@ -216,7 +216,7 @@ public class VTMarkupItemResetTest extends VTBaseTestCase {
// cleared, but the considered status was set. // cleared, but the considered status was set.
// //
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatch match = matchSet.addMatch(createRandomMatch(db)); VTMatch match = matchSet.addMatch(createRandomMatch(db));
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);

View file

@ -20,7 +20,6 @@ import static ghidra.feature.vt.db.VTTestUtils.*;
import ghidra.feature.vt.api.main.VTMatchSet; import ghidra.feature.vt.api.main.VTMatchSet;
import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator; import ghidra.feature.vt.api.util.VTAbstractProgramCorrelator;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
@ -34,21 +33,18 @@ public class DummyTestProgramCorrelator extends VTAbstractProgramCorrelator {
this(1); this(1);
} }
public DummyTestProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public DummyTestProgramCorrelator(Program sourceProgram, AddressSetView sourceAddressSet,
AddressSetView sourceAddressSet, Program destinationProgram, Program destinationProgram, AddressSetView destinationAddressSet, ToolOptions options) {
AddressSetView destinationAddressSet, ToolOptions options) { super(sourceProgram, sourceAddressSet, destinationProgram, destinationAddressSet, options);
super(serviceProvider, sourceProgram, sourceAddressSet, destinationProgram,
destinationAddressSet, options);
} }
public DummyTestProgramCorrelator(ServiceProvider serviceProvider, Program sourceProgram, public DummyTestProgramCorrelator(Program sourceProgram, Program destinationProgram) {
Program destinationProgram) { super(sourceProgram, createAddressSet(), destinationProgram, createAddressSet(),
super(serviceProvider, sourceProgram, createAddressSet(), destinationProgram, createOptions());
createAddressSet(), createOptions());
} }
public DummyTestProgramCorrelator(int matchCount) { public DummyTestProgramCorrelator(int matchCount) {
super(null, null, createAddressSet(), null, createAddressSet(), createOptions()); super(null, createAddressSet(), null, createAddressSet(), createOptions());
this.matchCount = matchCount; this.matchCount = matchCount;
} }

View file

@ -235,8 +235,7 @@ public class UnappliedMarkupItemStorageDBTest extends VTBaseTestCase {
unappliedMarkupItem.setDestinationAddress(destinationAddress); unappliedMarkupItem.setDestinationAddress(destinationAddress);
VTAssociationDB association = (VTAssociationDB) match.getAssociation(); VTAssociationDB association = (VTAssociationDB) match.getAssociation();
Collection<VTMarkupItem> markupItems = Collection<VTMarkupItem> markupItems = association.getMarkupItems(TaskMonitor.DUMMY);
association.getMarkupItems(TaskMonitor.DUMMY);
assertEquals(1, markupItems.size()); assertEquals(1, markupItems.size());
VTMarkupItem foundItem = markupItems.iterator().next(); VTMarkupItem foundItem = markupItems.iterator().next();
Object storage = getInstanceField("markupItemStorage", foundItem); Object storage = getInstanceField("markupItemStorage", foundItem);
@ -256,8 +255,7 @@ public class UnappliedMarkupItemStorageDBTest extends VTBaseTestCase {
VTMarkupItem markupItem = createRandomMarkupItemStub(match); VTMarkupItem markupItem = createRandomMarkupItemStub(match);
VTAssociationDB association = (VTAssociationDB) match.getAssociation(); VTAssociationDB association = (VTAssociationDB) match.getAssociation();
Collection<VTMarkupItem> markupItems = Collection<VTMarkupItem> markupItems = association.getMarkupItems(TaskMonitor.DUMMY);
association.getMarkupItems(TaskMonitor.DUMMY);
assertEquals(1, markupItems.size()); assertEquals(1, markupItems.size());
VTMarkupItem foundItem = markupItems.iterator().next(); VTMarkupItem foundItem = markupItems.iterator().next();
Object storage = getInstanceField("markupItemStorage", foundItem); Object storage = getInstanceField("markupItemStorage", foundItem);
@ -268,7 +266,7 @@ public class UnappliedMarkupItemStorageDBTest extends VTBaseTestCase {
private VTMatch createMatchSetWithOneMatch() { private VTMatch createMatchSetWithOneMatch() {
VTMatchInfo matchInfo = createRandomMatch(db); VTMatchInfo matchInfo = createRandomMatch(db);
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
return matchSet.addMatch(matchInfo); return matchSet.addMatch(matchInfo);
} }

View file

@ -140,7 +140,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testAssociationLocking() { public void testAssociationLocking() {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// To create our locking scenario we will create associations that are related and // To create our locking scenario we will create associations that are related and
@ -235,7 +235,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testAddNewCompetingAssociationIsLockedOut() throws Exception { public void testAddNewCompetingAssociationIsLockedOut() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// To create our locking scenario we will create associations that are competing. First // To create our locking scenario we will create associations that are competing. First
@ -274,7 +274,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testAddNewRelatedAssociationIsAccepted() throws Exception { public void testAddNewRelatedAssociationIsAccepted() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// To create our locking scenario we will create associations that are related. First // To create our locking scenario we will create associations that are related. First
@ -311,7 +311,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testGetRelatedAssociations() { public void testGetRelatedAssociations() {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// Exercise the lookup routines for finding related matches // Exercise the lookup routines for finding related matches
@ -371,7 +371,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testSetAcceptedFailsWhenNotAccepted() throws Exception { public void testSetAcceptedFailsWhenNotAccepted() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// To create our locking scenario we will create associations that are related. First // To create our locking scenario we will create associations that are related. First
@ -418,7 +418,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testSetAssocaiationAccepted_WithNoCompetingAssociations() throws Exception { public void testSetAssocaiationAccepted_WithNoCompetingAssociations() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// The accepted association // The accepted association
@ -435,7 +435,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testSetAssocaiationAccepted_WithCompetingAssociations() throws Exception { public void testSetAssocaiationAccepted_WithCompetingAssociations() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// The accepted association // The accepted association
@ -462,7 +462,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testClearAccepted_WithNoCompetingAssociations() throws Exception { public void testClearAccepted_WithNoCompetingAssociations() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// The accepted association // The accepted association
@ -482,7 +482,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testClearAccepted_WithCompetingAssociations() throws Exception { public void testClearAccepted_WithCompetingAssociations() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// The accepted association // The accepted association
@ -513,7 +513,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testClearAcceptedFailsWithAppliedMatches() throws Exception { public void testClearAcceptedFailsWithAppliedMatches() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
// //
// The accepted association // The accepted association
@ -561,7 +561,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testAcceptingAnEmptyAssociationSetsTheFullyAppliedStatus() throws Exception { public void testAcceptingAnEmptyAssociationSetsTheFullyAppliedStatus() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatchInfo mainMatchInfo = createRandomMatch(db); VTMatchInfo mainMatchInfo = createRandomMatch(db);
VTMatch mainMatch = addMatch(matchSet, mainMatchInfo); VTMatch mainMatch = addMatch(matchSet, mainMatchInfo);
@ -679,7 +679,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testVotes() throws Exception { public void testVotes() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatchInfo mainMatchInfo = createRandomMatch(db); VTMatchInfo mainMatchInfo = createRandomMatch(db);
VTMatch mainMatch = addMatch(matchSet, mainMatchInfo); VTMatch mainMatch = addMatch(matchSet, mainMatchInfo);
@ -698,7 +698,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
public void testAssociationHook() throws Exception { public void testAssociationHook() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatchInfo mainMatchInfo = createRandomMatch(db); VTMatchInfo mainMatchInfo = createRandomMatch(db);
VTMatch mainMatch = addMatch(matchSet, mainMatchInfo); VTMatch mainMatch = addMatch(matchSet, mainMatchInfo);
SpyAssociationHook spyHook = new SpyAssociationHook(); SpyAssociationHook spyHook = new SpyAssociationHook();
@ -715,7 +715,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
public void testRejectingAssociation() throws Exception { public void testRejectingAssociation() throws Exception {
// reject // reject
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatchInfo mainMatchInfo = createRandomMatch(db); VTMatchInfo mainMatchInfo = createRandomMatch(db);
VTMatch mainMatch = addMatch(matchSet, mainMatchInfo); VTMatch mainMatch = addMatch(matchSet, mainMatchInfo);
@ -734,7 +734,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
@Test @Test
public void testRejectingAssociation_CannotApplyMarkupItems() throws Exception { public void testRejectingAssociation_CannotApplyMarkupItems() throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatchInfo mainMatchInfo = createRandomMatch(db); VTMatchInfo mainMatchInfo = createRandomMatch(db);
VTMatch mainMatch = addMatch(matchSet, mainMatchInfo); VTMatch mainMatch = addMatch(matchSet, mainMatchInfo);
@ -761,7 +761,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
public void testRejectingAssocation_CannotRejectAssociationWithAppliedMarkupItems() public void testRejectingAssocation_CannotRejectAssociationWithAppliedMarkupItems()
throws Exception { throws Exception {
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
VTMatchInfo mainMatchInfo = createRandomMatch(db); VTMatchInfo mainMatchInfo = createRandomMatch(db);
VTMatch mainMatch = addMatch(matchSet, mainMatchInfo); VTMatch mainMatch = addMatch(matchSet, mainMatchInfo);
@ -823,7 +823,7 @@ public class VTAssociationDBTest extends VTBaseTestCase {
private VTMatch createMatchSetWithOneMatch() { private VTMatch createMatchSetWithOneMatch() {
VTMatchInfo match = createRandomMatch(db); VTMatchInfo match = createRandomMatch(db);
VTMatchSet matchSet = db.createMatchSet( VTMatchSet matchSet = db.createMatchSet(
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram())); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
return addMatch(matchSet, match); return addMatch(matchSet, match);
} }

View file

@ -314,7 +314,7 @@ public class VTDomainObjectEventsTest extends VTBaseTestCase {
private VTMatchSet createMatchSet() { private VTMatchSet createMatchSet() {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram()); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram());
return db.createMatchSet(correlator); return db.createMatchSet(correlator);
} }
} }

View file

@ -15,7 +15,7 @@
*/ */
package ghidra.feature.vt.db; package ghidra.feature.vt.db;
import static ghidra.feature.vt.db.VTTestUtils.createProgramCorrelator; import static ghidra.feature.vt.db.VTTestUtils.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.Collection; import java.util.Collection;
@ -51,7 +51,7 @@ public class VTMatchSetDBTest extends VTBaseTestCase {
@Test @Test
public void testAddMatch() throws Exception { public void testAddMatch() throws Exception {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram()); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram());
VTMatchSet matchSet = db.createMatchSet(correlator); VTMatchSet matchSet = db.createMatchSet(correlator);
assertNotNull(matchSet); assertNotNull(matchSet);
@ -70,7 +70,7 @@ public class VTMatchSetDBTest extends VTBaseTestCase {
@Test @Test
public void testRejectAvailableMatch() throws Exception { public void testRejectAvailableMatch() throws Exception {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram()); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram());
VTMatchSet matchSet = db.createMatchSet(correlator); VTMatchSet matchSet = db.createMatchSet(correlator);
assertNotNull(matchSet); assertNotNull(matchSet);
@ -100,7 +100,7 @@ public class VTMatchSetDBTest extends VTBaseTestCase {
@Test @Test
public void testRejectAcceptedMatchFailure() throws Exception { public void testRejectAcceptedMatchFailure() throws Exception {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram()); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram());
VTMatchSet matchSet = db.createMatchSet(correlator); VTMatchSet matchSet = db.createMatchSet(correlator);
assertNotNull(matchSet); assertNotNull(matchSet);
@ -144,7 +144,7 @@ public class VTMatchSetDBTest extends VTBaseTestCase {
@Test @Test
public void testRejectBlockedMatch() throws Exception { public void testRejectBlockedMatch() throws Exception {
VTProgramCorrelator correlator = VTProgramCorrelator correlator =
createProgramCorrelator(null, db.getSourceProgram(), db.getDestinationProgram()); createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram());
VTMatchSet matchSet = db.createMatchSet(correlator); VTMatchSet matchSet = db.createMatchSet(correlator);
assertNotNull(matchSet); assertNotNull(matchSet);

View file

@ -15,8 +15,7 @@
*/ */
package ghidra.feature.vt.db; package ghidra.feature.vt.db;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import java.util.List; import java.util.List;
@ -45,8 +44,8 @@ public class VTSessionDBTest extends VTBaseTestCase {
@Test @Test
public void testCreateAndGetMatchSet() throws Exception { public void testCreateAndGetMatchSet() throws Exception {
VTProgramCorrelator correlator = VTTestUtils.createProgramCorrelator(null, VTProgramCorrelator correlator =
db.getSourceProgram(), db.getDestinationProgram()); VTTestUtils.createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram());
VTMatchSet matchSet = db.createMatchSet(correlator); VTMatchSet matchSet = db.createMatchSet(correlator);
assertNotNull(matchSet); assertNotNull(matchSet);

View file

@ -15,6 +15,8 @@
*/ */
package ghidra.feature.vt.db; package ghidra.feature.vt.db;
import java.util.*;
//import generic.test.GenericTestCase; //import generic.test.GenericTestCase;
import generic.test.AbstractGenericTest; import generic.test.AbstractGenericTest;
import ghidra.feature.vt.api.db.VTAssociationDB; import ghidra.feature.vt.api.db.VTAssociationDB;
@ -25,27 +27,24 @@ import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.markupitem.MarkupTypeTestStub; import ghidra.feature.vt.api.markupitem.MarkupTypeTestStub;
import ghidra.feature.vt.api.markuptype.VTMarkupType; import ghidra.feature.vt.api.markuptype.VTMarkupType;
import ghidra.feature.vt.api.markuptype.VTMarkupTypeFactory; import ghidra.feature.vt.api.markuptype.VTMarkupTypeFactory;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.util.*;
public class VTTestUtils { public class VTTestUtils {
private static String[] randomTags = { "TAG1", "TAG2", "TAG3" }; private static String[] randomTags = { "TAG1", "TAG2", "TAG3" };
private static GenericAddressSpace space = new GenericAddressSpace("Test", 32, private static GenericAddressSpace space =
AddressSpace.TYPE_RAM, 3); new GenericAddressSpace("Test", 32, AddressSpace.TYPE_RAM, 3);
private VTTestUtils() { private VTTestUtils() {
// utility class // utility class
} }
public static VTProgramCorrelator createProgramCorrelator(ServiceProvider serviceProvider, public static VTProgramCorrelator createProgramCorrelator(Program sourceProgram,
Program sourceProgram, Program destinationProgram) { Program destinationProgram) {
return new DummyTestProgramCorrelator(serviceProvider, sourceProgram, destinationProgram); return new DummyTestProgramCorrelator(sourceProgram, destinationProgram);
} }
/** /**
@ -149,7 +148,8 @@ public class VTTestUtils {
VTMarkupItem markupItem = new MarkupItemImpl(associationDB, markupType, sourceAddress); VTMarkupItem markupItem = new MarkupItemImpl(associationDB, markupType, sourceAddress);
Object markupItemManager = AbstractGenericTest.getInstanceField("markupManager", associationDB); Object markupItemManager =
AbstractGenericTest.getInstanceField("markupManager", associationDB);
if (!(markupItemManager instanceof MarkupItemManagerImplDummy)) { if (!(markupItemManager instanceof MarkupItemManagerImplDummy)) {
// Odd Code Alert: we don't want the MarkupItemManager actually looking for markup items // Odd Code Alert: we don't want the MarkupItemManager actually looking for markup items
@ -193,9 +193,8 @@ public class VTTestUtils {
try { try {
testTransactionID = db.startTransaction("Test Match Set Setup"); testTransactionID = db.startTransaction("Test Match Set Setup");
VTMatchInfo info = createRandomMatch(sourceAddress, destinationAddress, db); VTMatchInfo info = createRandomMatch(sourceAddress, destinationAddress, db);
VTMatchSet matchSet = VTMatchSet matchSet = db.createMatchSet(
db.createMatchSet(createProgramCorrelator(null, db.getSourceProgram(), createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
db.getDestinationProgram()));
return matchSet.addMatch(info); return matchSet.addMatch(info);
} }
finally { finally {
@ -210,9 +209,8 @@ public class VTTestUtils {
testTransactionID = db.startTransaction("Test Create Data Match Set"); testTransactionID = db.startTransaction("Test Create Data Match Set");
VTMatchInfo info = createRandomMatch(sourceAddress, destinationAddress, db); VTMatchInfo info = createRandomMatch(sourceAddress, destinationAddress, db);
info.setAssociationType(VTAssociationType.DATA); info.setAssociationType(VTAssociationType.DATA);
VTMatchSet matchSet = VTMatchSet matchSet = db.createMatchSet(
db.createMatchSet(createProgramCorrelator(null, db.getSourceProgram(), createProgramCorrelator(db.getSourceProgram(), db.getDestinationProgram()));
db.getDestinationProgram()));
return matchSet.addMatch(info); return matchSet.addMatch(info);
} }
finally { finally {
@ -243,8 +241,8 @@ public class VTTestUtils {
VTMarkupItemStatus.values()[getRandomInt(1, VTMarkupItemStatus.values().length - 1)]; VTMarkupItemStatus.values()[getRandomInt(1, VTMarkupItemStatus.values().length - 1)];
while (status == statusSeed) { while (status == statusSeed) {
status = status = VTMarkupItemStatus.values()[getRandomInt(1,
VTMarkupItemStatus.values()[getRandomInt(1, VTMarkupItemStatus.values().length - 1)]; VTMarkupItemStatus.values().length - 1)];
} }
return status; return status;

View file

@ -16,6 +16,8 @@
package ghidra.feature.vt.gui; package ghidra.feature.vt.gui;
import static docking.test.AbstractDockingTest.*; import static docking.test.AbstractDockingTest.*;
import static generic.test.AbstractGenericTest.*;
import static generic.test.AbstractGuiTest.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -69,7 +71,7 @@ public class VTTestEnv extends TestEnv {
session = VTSessionDB.createVTSession("Test", sourceProgram, destinationProgram, getTool()); session = VTSessionDB.createVTSession("Test", sourceProgram, destinationProgram, getTool());
VTProgramCorrelator correlator = factory.createCorrelator(getTool(), sourceProgram, VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram,
sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), null); sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), null);
int id = session.startTransaction("Correlate"); int id = session.startTransaction("Correlate");
@ -85,7 +87,7 @@ public class VTTestEnv extends TestEnv {
throw new AssertionFailedError("You must create the session before you can add items"); throw new AssertionFailedError("You must create the session before you can add items");
} }
VTProgramCorrelator correlator = factory.createCorrelator(getTool(), sourceProgram, VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram,
sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), null); sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), null);
int id = session.startTransaction("Correlate"); int id = session.startTransaction("Correlate");
@ -120,7 +122,7 @@ public class VTTestEnv extends TestEnv {
public VTProgramCorrelator correlate(VTProgramCorrelatorFactory factory, VTOptions options, public VTProgramCorrelator correlate(VTProgramCorrelatorFactory factory, VTOptions options,
TaskMonitor monitor) throws CancelledException { TaskMonitor monitor) throws CancelledException {
VTProgramCorrelator correlator = factory.createCorrelator(getTool(), sourceProgram, VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram,
sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), options); sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), options);
int id = session.startTransaction("Correlate"); int id = session.startTransaction("Correlate");

View file

@ -459,7 +459,7 @@ public class TagFilterTest extends VTBaseTestCase {
public static VTProgramCorrelator createProgramCorrelator(ServiceProvider serviceProvider, public static VTProgramCorrelator createProgramCorrelator(ServiceProvider serviceProvider,
Program sourceProgram, Program destinationProgram) { Program sourceProgram, Program destinationProgram) {
return new DummyTestProgramCorrelator(serviceProvider, sourceProgram, destinationProgram); return new DummyTestProgramCorrelator(sourceProgram, destinationProgram);
} }
} }

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,8 +33,10 @@ public interface AddressCorrelation {
* *
* @param sourceAddress * @param sourceAddress
* the source program address * the source program address
* @param monitor the task monitor
* @return the destination program address range, or null if the source program address maps * @return the destination program address range, or null if the source program address maps
* to one that is "deleted" in the destination program * to one that is "deleted" in the destination program
* @throws CancelledException if cancelled
*/ */
public AddressRange getCorrelatedDestinationRange(Address sourceAddress, TaskMonitor monitor) public AddressRange getCorrelatedDestinationRange(Address sourceAddress, TaskMonitor monitor)
throws CancelledException; throws CancelledException;