GT-3305 - Version Tracking - Fixed 'Create Manual Match' actions to work

from within the source/destination tools

Fixes #2215
This commit is contained in:
dragonmacher 2020-09-15 15:02:48 -04:00
parent 04594f770b
commit dc52727cca
10 changed files with 121 additions and 152 deletions

View file

@ -22,7 +22,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import docking.DialogComponentProvider; import docking.DialogComponentProvider;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
@ -179,8 +178,8 @@ public abstract class AbstractGhidraHeadedIntegrationTest
* @return the new tool * @return the new tool
*/ */
public static PluginTool saveTool(final Project project, final PluginTool tool) { public static PluginTool saveTool(final Project project, final PluginTool tool) {
AtomicReference<PluginTool> ref = new AtomicReference<>();
runSwing(() -> { PluginTool newTool = runSwing(() -> {
ToolChest toolChest = project.getLocalToolChest(); ToolChest toolChest = project.getLocalToolChest();
ToolTemplate toolTemplate = tool.saveToolToToolTemplate(); ToolTemplate toolTemplate = tool.saveToolToToolTemplate();
toolChest.replaceToolTemplate(toolTemplate); toolChest.replaceToolTemplate(toolTemplate);
@ -188,10 +187,10 @@ public abstract class AbstractGhidraHeadedIntegrationTest
ToolManager toolManager = project.getToolManager(); ToolManager toolManager = project.getToolManager();
Workspace workspace = toolManager.getActiveWorkspace(); Workspace workspace = toolManager.getActiveWorkspace();
tool.close(); tool.close();
ref.set((PluginTool) workspace.runTool(toolTemplate)); return workspace.runTool(toolTemplate);
}); });
return ref.get(); return newTool;
} }
/** /**

View file

@ -533,7 +533,7 @@ public class TestEnv {
Workspace workspace = toolManager.getActiveWorkspace(); Workspace workspace = toolManager.getActiveWorkspace();
AbstractDockingTest.setErrorGUIEnabled(wasErrorGUIEnabled); AbstractDockingTest.setErrorGUIEnabled(wasErrorGUIEnabled);
return (PluginTool) workspace.runTool(toolTemplate); return workspace.runTool(toolTemplate);
}); });
} }
@ -560,20 +560,19 @@ public class TestEnv {
JavaScriptProvider scriptProvider = new JavaScriptProvider(); JavaScriptProvider scriptProvider = new JavaScriptProvider();
PrintWriter writer = new PrintWriter(System.out); PrintWriter writer = new PrintWriter(System.out);
ResourceFile resourceFile = new ResourceFile(scriptFile); ResourceFile resourceFile = new ResourceFile(scriptFile);
GhidraScript script=null; GhidraScript script = null;
try { try {
script=scriptProvider.getScriptInstance(resourceFile, writer); script = scriptProvider.getScriptInstance(resourceFile, writer);
} }
catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (script==null) { if (script == null) {
writer.flush(); writer.flush();
throw new RuntimeException("Failed to compile script " + scriptFile.getAbsolutePath()); throw new RuntimeException("Failed to compile script " + scriptFile.getAbsolutePath());
} }
String scriptName = scriptFile.getName(); String scriptName = scriptFile.getName();
ScriptTaskListener listener = new ScriptTaskListener(scriptName); ScriptTaskListener listener = new ScriptTaskListener(scriptName);
scriptManagerPlugin.runScript(scriptName, listener); scriptManagerPlugin.runScript(scriptName, listener);
@ -927,19 +926,6 @@ public class TestEnv {
}); });
} }
/**
* Import a program as binary.
* @param programName resource name that is the name of the program
* @param language language
* @param compilerSpec compiler spec
* @return program
* @throws IOException
* @throws LanguageNotFoundException
* @throws VersionException
* @throws InvalidNameException
* @throws DuplicateNameException
* @throws CancelledException
*/
public Program loadResourceProgramAsBinary(String programName, Language language, public Program loadResourceProgramAsBinary(String programName, Language language,
CompilerSpec compilerSpec) throws LanguageNotFoundException, IOException, CompilerSpec compilerSpec) throws LanguageNotFoundException, IOException,
CancelledException, DuplicateNameException, InvalidNameException, VersionException { CancelledException, DuplicateNameException, InvalidNameException, VersionException {
@ -950,18 +936,6 @@ public class TestEnv {
return gp.importProgram(file, language, compilerSpec); return gp.importProgram(file, language, compilerSpec);
} }
/**
* Import a program as binary.
* @param programName resource name that is the name of the program
* @param processor processor
* @return program
* @throws IOException
* @throws LanguageNotFoundException
* @throws VersionException
* @throws InvalidNameException
* @throws DuplicateNameException
* @throws CancelledException
*/
public Program loadResourceProgramAsBinary(String programName, Processor processor) public Program loadResourceProgramAsBinary(String programName, Processor processor)
throws CancelledException, DuplicateNameException, InvalidNameException, throws CancelledException, DuplicateNameException, InvalidNameException,
VersionException, IOException { VersionException, IOException {

View file

@ -24,7 +24,8 @@ import ghidra.feature.vt.gui.plugin.*;
import ghidra.feature.vt.gui.task.CreateManualMatchTask; import ghidra.feature.vt.gui.task.CreateManualMatchTask;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.task.*; import ghidra.util.task.Task;
import ghidra.util.task.TaskListener;
public abstract class AbstractManualMatchFromToolsAction extends DockingAction { public abstract class AbstractManualMatchFromToolsAction extends DockingAction {
@ -54,7 +55,7 @@ public abstract class AbstractManualMatchFromToolsAction extends DockingAction {
return; return;
} }
final CreateManualMatchTask task = getTask(controller, sourceFunction, destinationFunction); CreateManualMatchTask task = getTask(controller, sourceFunction, destinationFunction);
task.addTaskListener(new TaskListener() { task.addTaskListener(new TaskListener() {
@Override @Override
@ -68,7 +69,7 @@ public abstract class AbstractManualMatchFromToolsAction extends DockingAction {
} }
}); });
TaskLauncher.launch(task); plugin.getController().runVTTask(task);
} }
protected abstract CreateManualMatchTask getTask(VTController controller, protected abstract CreateManualMatchTask getTask(VTController controller,

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,17 +15,19 @@
*/ */
package ghidra.feature.vt.gui.actions; package ghidra.feature.vt.gui.actions;
import docking.action.MenuData;
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.feature.vt.gui.task.CreateManualMatchTask; import ghidra.feature.vt.gui.task.CreateManualMatchTask;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
import docking.action.MenuData;
public class CreateManualMatchFromToolsAction extends AbstractManualMatchFromToolsAction { public class CreateManualMatchFromToolsAction extends AbstractManualMatchFromToolsAction {
public static final String NAME = "Create Manual Match From Tool";
public CreateManualMatchFromToolsAction(VTPlugin plugin) { public CreateManualMatchFromToolsAction(VTPlugin plugin) {
super(plugin, "Create Manual Match From Tool"); super(plugin, NAME);
String menuGroup = "1"; // first group in the popup String menuGroup = "1"; // first group in the popup
setPopupMenuData(new MenuData(new String[] { VTPlugin.MATCH_POPUP_MENU_NAME, setPopupMenuData(new MenuData(new String[] { VTPlugin.MATCH_POPUP_MENU_NAME,
"Create Manual Match" }, CreateManualMatchAction.ICON, menuGroup)); "Create Manual Match" }, CreateManualMatchAction.ICON, menuGroup));

View file

@ -15,8 +15,7 @@
*/ */
package help.screenshot; package help.screenshot;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import java.awt.*; import java.awt.*;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -94,13 +93,8 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
public void setUp() throws Exception { public void setUp() throws Exception {
vtTestEnv = new VTTestEnv(); vtTestEnv = new VTTestEnv();
session = vtTestEnv.createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME); session = vtTestEnv.createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
try { correlator = vtTestEnv.correlate(new ExactMatchInstructionsProgramCorrelatorFactory(),
correlator = vtTestEnv.correlate(new ExactMatchInstructionsProgramCorrelatorFactory(), null, TaskMonitor.DUMMY);
null, TaskMonitorAdapter.DUMMY_MONITOR);
}
catch (Exception e) {
failWithException("Exceptioin correlating", e);
}
sourceProgram = vtTestEnv.getSourceProgram(); sourceProgram = vtTestEnv.getSourceProgram();
destinationProgram = vtTestEnv.getDestinationProgram(); destinationProgram = vtTestEnv.getDestinationProgram();
controller = vtTestEnv.getVTController(); controller = vtTestEnv.getVTController();
@ -117,7 +111,6 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
session = null; session = null;
controller = null; controller = null;
correlator = null; correlator = null;
vtTestEnv.releaseSession();
vtTestEnv.dispose(); vtTestEnv.dispose();
saveOrDisplayImage(); saveOrDisplayImage();
} }
@ -308,7 +301,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
controller.runVTTask(task); controller.runVTTask(task);
vtTestEnv.correlate(new SymbolNameProgramCorrelatorFactory(), null, vtTestEnv.correlate(new SymbolNameProgramCorrelatorFactory(), null,
TaskMonitorAdapter.DUMMY_MONITOR); TaskMonitor.DUMMY);
sourceAddress = sourceProgram.getAddressFactory().getAddress("0x00411860"); sourceAddress = sourceProgram.getAddressFactory().getAddress("0x00411860");
sourceFunction = sourceProgram.getFunctionManager().getFunctionAt(sourceAddress); sourceFunction = sourceProgram.getFunctionManager().getFunctionAt(sourceAddress);
@ -347,7 +340,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
controller.runVTTask(task); controller.runVTTask(task);
vtTestEnv.correlate(new SymbolNameProgramCorrelatorFactory(), null, vtTestEnv.correlate(new SymbolNameProgramCorrelatorFactory(), null,
TaskMonitorAdapter.DUMMY_MONITOR); TaskMonitor.DUMMY);
sourceAddress = sourceProgram.getAddressFactory().getAddress("0x00411860"); sourceAddress = sourceProgram.getAddressFactory().getAddress("0x00411860");
sourceFunction = sourceProgram.getFunctionManager().getFunctionAt(sourceAddress); sourceFunction = sourceProgram.getFunctionManager().getFunctionAt(sourceAddress);
@ -580,7 +573,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
private void replaceMarkup(VTMatch match, String markupSourceAddress, String markupType) { private void replaceMarkup(VTMatch match, String markupSourceAddress, String markupType) {
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR); matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) { for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
Address itemSourceAddress = vtMarkupItem.getSourceAddress(); Address itemSourceAddress = vtMarkupItem.getSourceAddress();
VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType(); VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType();
@ -599,7 +592,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
private void addMarkup(VTMatch match, String markupSourceAddress, String markupType) { private void addMarkup(VTMatch match, String markupSourceAddress, String markupType) {
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR); matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) { for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
Address itemSourceAddress = vtMarkupItem.getSourceAddress(); Address itemSourceAddress = vtMarkupItem.getSourceAddress();
VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType(); VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType();
@ -619,7 +612,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
String markupSourceAddress, String markupType) { String markupSourceAddress, String markupType) {
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR); matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) { for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
Address itemSourceAddress = vtMarkupItem.getSourceAddress(); Address itemSourceAddress = vtMarkupItem.getSourceAddress();
VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType(); VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType();

View file

@ -15,8 +15,14 @@
*/ */
package ghidra.feature.vt.api.correlator.address; package ghidra.feature.vt.api.correlator.address;
import static ghidra.feature.vt.db.VTTestUtils.addr; import static ghidra.feature.vt.db.VTTestUtils.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.Collection;
import java.util.List;
import org.junit.*;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager; import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.feature.vt.api.correlator.program.*; import ghidra.feature.vt.api.correlator.program.*;
import ghidra.feature.vt.api.main.*; import ghidra.feature.vt.api.main.*;
@ -33,12 +39,6 @@ import ghidra.program.util.AddressCorrelation;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import ghidra.util.task.TaskMonitorAdapter;
import java.util.Collection;
import java.util.List;
import org.junit.*;
/** /**
* Tests to verify that the correct address correlation is being determined and used for obtaining * Tests to verify that the correct address correlation is being determined and used for obtaining
@ -61,28 +61,21 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
protected Function sourceFunction; protected Function sourceFunction;
protected Function destinationFunction; protected Function destinationFunction;
public AddressCorrelationTest() { @Before
super(); public void setUp() throws Exception {
}
@Before
public void setUp() throws Exception {
vtTestEnv = new VTTestEnv(); vtTestEnv = new VTTestEnv();
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
sourceProgram = null; sourceProgram = null;
destinationProgram = null; destinationProgram = null;
session = null; session = null;
controller = null; controller = null;
correlator = null; correlator = null;
vtTestEnv.releaseSession();
vtTestEnv.dispose(); vtTestEnv.dispose();
} }
/////////////// TESTS ///////////////
@Test @Test
public void testExactMatchBytes() throws Exception { public void testExactMatchBytes() throws Exception {
// Test a function match created by the Exact Bytes Match correlator. // Test a function match created by the Exact Bytes Match correlator.
@ -152,7 +145,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
createSession(languageProgram1, languageProgram2); createSession(languageProgram1, languageProgram2);
vtTestEnv.showTool(); vtTestEnv.showTool();
addComment(CodeUnit.PLATE_COMMENT, "0x00401003", "Similar name plate comment not at entry."); addComment(CodeUnit.PLATE_COMMENT, "0x00401003",
"Similar name plate comment not at entry.");
addProgramCorrelation(new SimilarSymbolNameProgramCorrelatorFactory()); addProgramCorrelation(new SimilarSymbolNameProgramCorrelatorFactory());
useMatch("0x00401000", "0x00402000"); useMatch("0x00401000", "0x00402000");
checkAddressCorrelation(LinearFunctionAddressCorrelation.NAME); checkAddressCorrelation(LinearFunctionAddressCorrelation.NAME);
@ -354,7 +348,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) { protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) {
try { try {
correlator = correlator =
vtTestEnv.correlate(correlatorFactory, null, TaskMonitorAdapter.DUMMY_MONITOR); vtTestEnv.correlate(correlatorFactory, null, TaskMonitor.DUMMY);
} }
catch (Exception e) { catch (Exception e) {
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());
@ -392,7 +386,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
* @param addressCorrelationName the name of the expected address correlation for determining * @param addressCorrelationName the name of the expected address correlation for determining
* the destination address of non-function entry point markup items. * the destination address of non-function entry point markup items.
*/ */
private void checkMarkupDestinationSource(String addressCorrelationName, boolean canBeNoAddress) { private void checkMarkupDestinationSource(String addressCorrelationName,
boolean canBeNoAddress) {
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache. controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache.
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) { for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
@ -487,8 +482,9 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
String sourceAddressString, String comment, String destinationAddressString) { String sourceAddressString, String comment, String destinationAddressString) {
Address srcAddress = addr(sourceAddressString, sourceProgram); Address srcAddress = addr(sourceAddressString, sourceProgram);
Address destAddress = Address destAddress =
destinationAddressString.equals("NO_ADDRESS") ? Address.NO_ADDRESS : addr( destinationAddressString.equals("NO_ADDRESS") ? Address.NO_ADDRESS
destinationAddressString, destinationProgram); : addr(
destinationAddressString, destinationProgram);
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache. controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache.

View file

@ -15,8 +15,13 @@
*/ */
package ghidra.feature.vt.gui.provider; package ghidra.feature.vt.gui.provider;
import static ghidra.feature.vt.db.VTTestUtils.addr; import static ghidra.feature.vt.db.VTTestUtils.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.*;
import org.junit.*;
import ghidra.app.cmd.label.SetLabelPrimaryCmd; import ghidra.app.cmd.label.SetLabelPrimaryCmd;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager; import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.feature.vt.api.correlator.program.SymbolNameProgramCorrelatorFactory; import ghidra.feature.vt.api.correlator.program.SymbolNameProgramCorrelatorFactory;
@ -29,11 +34,7 @@ import ghidra.program.model.symbol.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException; import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitorAdapter; import ghidra.util.task.TaskMonitor;
import java.util.*;
import org.junit.*;
/** /**
* Tests to verify that the Exact Symbol Name program correlation determines matches as expected. * Tests to verify that the Exact Symbol Name program correlation determines matches as expected.
@ -57,10 +58,6 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
protected Function sourceFunction; protected Function sourceFunction;
protected Function destinationFunction; protected Function destinationFunction;
public VTExactSymbolMatch2Test() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
vtTestEnv = new VTTestEnv(); vtTestEnv = new VTTestEnv();
@ -73,7 +70,6 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
session = null; session = null;
controller = null; controller = null;
correlator = null; correlator = null;
vtTestEnv.releaseSession();
vtTestEnv.dispose(); vtTestEnv.dispose();
} }
@ -465,7 +461,7 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) { protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) {
try { try {
correlator = correlator =
vtTestEnv.correlate(correlatorFactory, null, TaskMonitorAdapter.DUMMY_MONITOR); vtTestEnv.correlate(correlatorFactory, null, TaskMonitor.DUMMY);
} }
catch (Exception e) { catch (Exception e) {
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());
@ -508,7 +504,8 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
* @param sourceAddressString the source address. * @param sourceAddressString the source address.
* @param destinationAddressString the destination address. * @param destinationAddressString the destination address.
*/ */
protected void verifyNoFunctionMatch(String sourceAddressString, String destinationAddressString) { protected void verifyNoFunctionMatch(String sourceAddressString,
String destinationAddressString) {
sourceAddress = addr(sourceAddressString, sourceProgram); sourceAddress = addr(sourceAddressString, sourceProgram);
destinationAddress = addr(destinationAddressString, destinationProgram); destinationAddress = addr(destinationAddressString, destinationProgram);
@ -595,7 +592,7 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
/** /**
* Adds a symbol with the indicated name at the specified address and makes it primary. * Adds a symbol with the indicated name at the specified address and makes it primary.
* @param program the program containing the symbol * @param program the program containing the symbol
* @param sourceAddressString the source address of the markup * @param addressString the source address of the markup
* @param symbolName the name of the symbol being added * @param symbolName the name of the symbol being added
* @throws DuplicateNameException if the name exists * @throws DuplicateNameException if the name exists
* @throws InvalidInputException if name is invalid * @throws InvalidInputException if name is invalid
@ -632,7 +629,8 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
String[] actualSourceSymbols = String[] actualSourceSymbols =
convertSymbolsToNames(sourceProgram.getSymbolTable().getSymbols(sourceAddress)); convertSymbolsToNames(sourceProgram.getSymbolTable().getSymbols(sourceAddress));
String[] actualDestSymbols = String[] actualDestSymbols =
convertSymbolsToNames(destinationProgram.getSymbolTable().getSymbols(destinationAddress)); convertSymbolsToNames(
destinationProgram.getSymbolTable().getSymbols(destinationAddress));
Arrays.sort(actualSourceSymbols); Arrays.sort(actualSourceSymbols);
Arrays.sort(actualDestSymbols); Arrays.sort(actualDestSymbols);

View file

@ -27,6 +27,7 @@ import javax.swing.table.TableModel;
import org.junit.*; import org.junit.*;
import docking.ActionContext;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.menu.ActionState; import docking.menu.ActionState;
import docking.menu.MultiStateDockingAction; import docking.menu.MultiStateDockingAction;
@ -35,10 +36,13 @@ import docking.widgets.filter.TextFilterStrategy;
import docking.widgets.table.GTable; import docking.widgets.table.GTable;
import docking.widgets.table.threaded.ThreadedTableModel; import docking.widgets.table.threaded.ThreadedTableModel;
import generic.test.TestUtils; import generic.test.TestUtils;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.plugin.core.codebrowser.CodeViewerProvider;
import ghidra.feature.vt.api.correlator.program.ExactMatchInstructionsProgramCorrelatorFactory; import ghidra.feature.vt.api.correlator.program.ExactMatchInstructionsProgramCorrelatorFactory;
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.VTTestEnv; import ghidra.feature.vt.gui.VTTestEnv;
import ghidra.feature.vt.gui.actions.CreateManualMatchFromToolsAction;
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.feature.vt.gui.provider.matchtable.VTMatchTableModel; import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableModel;
@ -62,7 +66,7 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
private VTController controller; private VTController controller;
private Program sourceProgram; private Program sourceProgram;
private Program destinationProgram; private Program destinationProgram;
private PluginTool tool; private PluginTool vtTool;
private VTPlugin versionTrackingPlugin; private VTPlugin versionTrackingPlugin;
private FunctionManager sourceFunctionManager; private FunctionManager sourceFunctionManager;
private FunctionManager destinationFunctionManager; private FunctionManager destinationFunctionManager;
@ -81,10 +85,6 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
private GhidraTableFilterPanel<?> destinationFilter; private GhidraTableFilterPanel<?> destinationFilter;
private VTFunctionAssociationProvider functionAssociationProvider; private VTFunctionAssociationProvider functionAssociationProvider;
public VTFunctionAssociationTest() {
super();
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -92,8 +92,8 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
setErrorGUIEnabled(false); setErrorGUIEnabled(false);
env = new VTTestEnv(); env = new VTTestEnv();
tool = env.showTool(); vtTool = env.showTool();
tool.setSize(800, 800); vtTool.setSize(800, 800);
env.createSession("VersionTracking/WallaceSrc", "VersionTracking/WallaceVersion2", env.createSession("VersionTracking/WallaceSrc", "VersionTracking/WallaceVersion2",
new ExactMatchInstructionsProgramCorrelatorFactory()); new ExactMatchInstructionsProgramCorrelatorFactory());
sourceProgram = env.getSourceProgram(); sourceProgram = env.getSourceProgram();
@ -153,11 +153,8 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
runSwing(() -> tool.close()); runSwing(() -> vtTool.close());
env.releaseSession();
env.dispose(); env.dispose();
} }
@Test @Test
@ -344,6 +341,36 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
assertEquals(VTAssociationStatus.AVAILABLE, match.getAssociation().getStatus()); assertEquals(VTAssociationStatus.AVAILABLE, match.getAssociation().getStatus());
} }
@Test
public void testCreateManualMatchFromCodeBrowserToolAction() throws Exception {
PluginTool sourceTool = env.getSourceTool();
PluginTool destinationTool = env.getDestinationTool();
// pick to addresses to 'match'
goTo(destinationTool, destinationProgram, "00412340");
goTo(sourceTool, sourceProgram, "004118f0");
assertFalse(hasMatch("deployGadget", "FUN_00412340"));
DockingActionIf matchAction =
getAction(destinationTool, CreateManualMatchFromToolsAction.NAME);
performActionInCodeBrowser(destinationTool, matchAction);
VTMatch match = findMatch("deployGadget", "FUN_00412340");
assertNotNull(match);
assertEquals(VTAssociationStatus.AVAILABLE, match.getAssociation().getStatus());
}
private void performActionInCodeBrowser(PluginTool ghidraTool,
DockingActionIf matchAction) {
CodeBrowserPlugin cb = getPlugin(ghidraTool, CodeBrowserPlugin.class);
CodeViewerProvider provider = cb.getProvider();
ActionContext context = runSwing(() -> provider.getActionContext(null));
performAction(matchAction, context, true);
}
@Test @Test
public void testCreateManualMatchAndAcceptAction() throws Exception { public void testCreateManualMatchAndAcceptAction() throws Exception {
@ -617,7 +644,7 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
final VTFunctionAssociationProvider provider = final VTFunctionAssociationProvider provider =
(VTFunctionAssociationProvider) TestUtils.getInstanceField( (VTFunctionAssociationProvider) TestUtils.getInstanceField(
"functionAssociationProvider", versionTrackingPlugin); "functionAssociationProvider", versionTrackingPlugin);
runSwing(() -> tool.showComponentProvider(provider, true)); runSwing(() -> vtTool.showComponentProvider(provider, true));
waitForSwing(); waitForSwing();
waitForTasks(); waitForTasks();
waitForSwing(); waitForSwing();

View file

@ -15,7 +15,7 @@
*/ */
package ghidra.feature.vt.api.markupitem; package ghidra.feature.vt.api.markupitem;
import static ghidra.feature.vt.db.VTTestUtils.addr; 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.*; import static org.junit.Assert.*;
@ -51,9 +51,9 @@ import ghidra.util.Msg;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException; import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import ghidra.util.task.TaskMonitorAdapter;
public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidraHeadedIntegrationTest { public abstract class AbstractFunctionSignatureMarkupTest
extends AbstractGhidraHeadedIntegrationTest {
// Default Apply Markup Options // Default Apply Markup Options
// ============================ // ============================
@ -97,15 +97,9 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
protected Function sourceFunction; protected Function sourceFunction;
protected Function destinationFunction; protected Function destinationFunction;
public AbstractFunctionSignatureMarkupTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// setErrorGUIEnabled(false);
vtTestEnv = new VTTestEnv(); vtTestEnv = new VTTestEnv();
session = vtTestEnv.createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME); session = vtTestEnv.createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
try { try {
@ -146,7 +140,6 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
session = null; session = null;
controller = null; controller = null;
correlator = null; correlator = null;
vtTestEnv.releaseSession();
vtTestEnv.dispose(); vtTestEnv.dispose();
} }
@ -388,7 +381,7 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
protected VTMarkupItem getFunctionSignatureMarkup(VTMatch match) { protected VTMarkupItem getFunctionSignatureMarkup(VTMatch match) {
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR); matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) { for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
if (vtMarkupItem.getMarkupType() instanceof FunctionSignatureMarkupType) { if (vtMarkupItem.getMarkupType() instanceof FunctionSignatureMarkupType) {
return vtMarkupItem; return vtMarkupItem;
@ -402,7 +395,7 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
List<VTMarkupItem> list = new ArrayList<>(); List<VTMarkupItem> list = new ArrayList<>();
MatchInfo matchInfo = controller.getMatchInfo(match); MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> appliableMarkupItems = Collection<VTMarkupItem> appliableMarkupItems =
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR); matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) { for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
if (vtMarkupItem.getMarkupType().getClass() == markupTypeClass) { if (vtMarkupItem.getMarkupType().getClass() == markupTypeClass) {
if (!onlyUnapplied || vtMarkupItem.getStatus() == VTMarkupItemStatus.UNAPPLIED) { if (!onlyUnapplied || vtMarkupItem.getStatus() == VTMarkupItemStatus.UNAPPLIED) {
@ -413,32 +406,6 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
return list; return list;
} }
// There is no longer a NoReturn markup
// protected VTMarkupItem getNoReturnMarkup(VTMatch match) {
// MatchInfo matchInfo = controller.getMatchInfo(match);
// Collection<VTMarkupItem> appliableMarkupItems =
// matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
// for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
// if (vtMarkupItem.getMarkupType() instanceof FunctionNoReturnMarkupType) {
// return vtMarkupItem;
// }
// }
// return null;
// }
//
// There is no longer a ParameterNames markup
// protected VTMarkupItem getParameterNamesMarkup(VTMatch match) {
// MatchInfo matchInfo = controller.getMatchInfo(match);
// Collection<VTMarkupItem> appliableMarkupItems =
// matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
// for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
// if (vtMarkupItem.getMarkupType() instanceof ParameterNamesMarkupType) {
// return vtMarkupItem;
// }
// }
// return null;
// }
protected VTMatch getMatch(Address source, Address destination) { protected VTMatch getMatch(Address source, Address destination) {
List<VTMatchSet> matchSets = session.getMatchSets(); List<VTMatchSet> matchSets = session.getMatchSets();
// Get matchSet 2 since 0 is manual matches and 1 is implied matches. // Get matchSet 2 since 0 is manual matches and 1 is implied matches.

View file

@ -15,9 +15,7 @@
*/ */
package ghidra.feature.vt.gui; package ghidra.feature.vt.gui;
import static docking.test.AbstractDockingTest.performAction; import static docking.test.AbstractDockingTest.*;
import static docking.test.AbstractDockingTest.waitForTableModel;
import static generic.test.AbstractGenericTest.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,8 +30,7 @@ import ghidra.app.plugin.core.progmgr.ProgramManagerPlugin;
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.feature.vt.gui.plugin.VTController; import ghidra.feature.vt.gui.plugin.*;
import ghidra.feature.vt.gui.plugin.VTPlugin;
import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableModel; import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableModel;
import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableProvider; import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableProvider;
import ghidra.framework.plugintool.Plugin; import ghidra.framework.plugintool.Plugin;
@ -132,7 +129,7 @@ public class VTTestEnv extends TestEnv {
return correlator; return correlator;
} }
public void releaseSession() { private void releaseSession() {
if (sourceProgram != null) { if (sourceProgram != null) {
release(sourceProgram); release(sourceProgram);
} }
@ -141,6 +138,12 @@ public class VTTestEnv extends TestEnv {
} }
} }
@Override
public void dispose() {
releaseSession();
super.dispose();
}
public VTController getVTController() { public VTController getVTController() {
return controller; return controller;
} }
@ -153,6 +156,16 @@ public class VTTestEnv extends TestEnv {
return sourceProgram; return sourceProgram;
} }
public PluginTool getSourceTool() {
VTSubToolManager toolManager = plugin.getToolManager();
return (PluginTool) invokeInstanceMethod("getSourceTool", toolManager);
}
public PluginTool getDestinationTool() {
VTSubToolManager toolManager = plugin.getToolManager();
return (PluginTool) invokeInstanceMethod("getDestinationTool", toolManager);
}
public Program getDestinationProgram() { public Program getDestinationProgram() {
return destinationProgram; return destinationProgram;
} }