mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GT-3305 - Version Tracking - Fixed 'Create Manual Match' actions to work
from within the source/destination tools Fixes #2215
This commit is contained in:
parent
04594f770b
commit
dc52727cca
10 changed files with 121 additions and 152 deletions
|
@ -22,7 +22,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import docking.DialogComponentProvider;
|
||||
import docking.action.DockingActionIf;
|
||||
|
@ -179,8 +178,8 @@ public abstract class AbstractGhidraHeadedIntegrationTest
|
|||
* @return the new tool
|
||||
*/
|
||||
public static PluginTool saveTool(final Project project, final PluginTool tool) {
|
||||
AtomicReference<PluginTool> ref = new AtomicReference<>();
|
||||
runSwing(() -> {
|
||||
|
||||
PluginTool newTool = runSwing(() -> {
|
||||
ToolChest toolChest = project.getLocalToolChest();
|
||||
ToolTemplate toolTemplate = tool.saveToolToToolTemplate();
|
||||
toolChest.replaceToolTemplate(toolTemplate);
|
||||
|
@ -188,10 +187,10 @@ public abstract class AbstractGhidraHeadedIntegrationTest
|
|||
ToolManager toolManager = project.getToolManager();
|
||||
Workspace workspace = toolManager.getActiveWorkspace();
|
||||
tool.close();
|
||||
ref.set((PluginTool) workspace.runTool(toolTemplate));
|
||||
return workspace.runTool(toolTemplate);
|
||||
});
|
||||
|
||||
return ref.get();
|
||||
return newTool;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -533,7 +533,7 @@ public class TestEnv {
|
|||
Workspace workspace = toolManager.getActiveWorkspace();
|
||||
|
||||
AbstractDockingTest.setErrorGUIEnabled(wasErrorGUIEnabled);
|
||||
return (PluginTool) workspace.runTool(toolTemplate);
|
||||
return workspace.runTool(toolTemplate);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -560,20 +560,19 @@ public class TestEnv {
|
|||
JavaScriptProvider scriptProvider = new JavaScriptProvider();
|
||||
PrintWriter writer = new PrintWriter(System.out);
|
||||
ResourceFile resourceFile = new ResourceFile(scriptFile);
|
||||
GhidraScript script=null;
|
||||
GhidraScript script = null;
|
||||
try {
|
||||
script=scriptProvider.getScriptInstance(resourceFile, writer);
|
||||
script = scriptProvider.getScriptInstance(resourceFile, writer);
|
||||
}
|
||||
catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
if (script==null) {
|
||||
if (script == null) {
|
||||
writer.flush();
|
||||
throw new RuntimeException("Failed to compile script " + scriptFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
String scriptName = scriptFile.getName();
|
||||
ScriptTaskListener listener = new ScriptTaskListener(scriptName);
|
||||
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,
|
||||
CompilerSpec compilerSpec) throws LanguageNotFoundException, IOException,
|
||||
CancelledException, DuplicateNameException, InvalidNameException, VersionException {
|
||||
|
@ -950,18 +936,6 @@ public class TestEnv {
|
|||
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)
|
||||
throws CancelledException, DuplicateNameException, InvalidNameException,
|
||||
VersionException, IOException {
|
||||
|
|
|
@ -24,7 +24,8 @@ import ghidra.feature.vt.gui.plugin.*;
|
|||
import ghidra.feature.vt.gui.task.CreateManualMatchTask;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.task.*;
|
||||
import ghidra.util.task.Task;
|
||||
import ghidra.util.task.TaskListener;
|
||||
|
||||
public abstract class AbstractManualMatchFromToolsAction extends DockingAction {
|
||||
|
||||
|
@ -54,7 +55,7 @@ public abstract class AbstractManualMatchFromToolsAction extends DockingAction {
|
|||
return;
|
||||
}
|
||||
|
||||
final CreateManualMatchTask task = getTask(controller, sourceFunction, destinationFunction);
|
||||
CreateManualMatchTask task = getTask(controller, sourceFunction, destinationFunction);
|
||||
|
||||
task.addTaskListener(new TaskListener() {
|
||||
@Override
|
||||
|
@ -68,7 +69,7 @@ public abstract class AbstractManualMatchFromToolsAction extends DockingAction {
|
|||
}
|
||||
});
|
||||
|
||||
TaskLauncher.launch(task);
|
||||
plugin.getController().runVTTask(task);
|
||||
}
|
||||
|
||||
protected abstract CreateManualMatchTask getTask(VTController controller,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,17 +15,19 @@
|
|||
*/
|
||||
package ghidra.feature.vt.gui.actions;
|
||||
|
||||
import docking.action.MenuData;
|
||||
import ghidra.feature.vt.gui.plugin.VTController;
|
||||
import ghidra.feature.vt.gui.plugin.VTPlugin;
|
||||
import ghidra.feature.vt.gui.task.CreateManualMatchTask;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.util.HelpLocation;
|
||||
import docking.action.MenuData;
|
||||
|
||||
public class CreateManualMatchFromToolsAction extends AbstractManualMatchFromToolsAction {
|
||||
|
||||
public static final String NAME = "Create Manual Match From Tool";
|
||||
|
||||
public CreateManualMatchFromToolsAction(VTPlugin plugin) {
|
||||
super(plugin, "Create Manual Match From Tool");
|
||||
super(plugin, NAME);
|
||||
String menuGroup = "1"; // first group in the popup
|
||||
setPopupMenuData(new MenuData(new String[] { VTPlugin.MATCH_POPUP_MENU_NAME,
|
||||
"Create Manual Match" }, CreateManualMatchAction.ICON, menuGroup));
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
package help.screenshot;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -94,13 +93,8 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
public void setUp() throws Exception {
|
||||
vtTestEnv = new VTTestEnv();
|
||||
session = vtTestEnv.createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
|
||||
try {
|
||||
correlator = vtTestEnv.correlate(new ExactMatchInstructionsProgramCorrelatorFactory(),
|
||||
null, TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
}
|
||||
catch (Exception e) {
|
||||
failWithException("Exceptioin correlating", e);
|
||||
}
|
||||
correlator = vtTestEnv.correlate(new ExactMatchInstructionsProgramCorrelatorFactory(),
|
||||
null, TaskMonitor.DUMMY);
|
||||
sourceProgram = vtTestEnv.getSourceProgram();
|
||||
destinationProgram = vtTestEnv.getDestinationProgram();
|
||||
controller = vtTestEnv.getVTController();
|
||||
|
@ -117,7 +111,6 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
session = null;
|
||||
controller = null;
|
||||
correlator = null;
|
||||
vtTestEnv.releaseSession();
|
||||
vtTestEnv.dispose();
|
||||
saveOrDisplayImage();
|
||||
}
|
||||
|
@ -308,7 +301,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
controller.runVTTask(task);
|
||||
|
||||
vtTestEnv.correlate(new SymbolNameProgramCorrelatorFactory(), null,
|
||||
TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
TaskMonitor.DUMMY);
|
||||
|
||||
sourceAddress = sourceProgram.getAddressFactory().getAddress("0x00411860");
|
||||
sourceFunction = sourceProgram.getFunctionManager().getFunctionAt(sourceAddress);
|
||||
|
@ -347,7 +340,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
controller.runVTTask(task);
|
||||
|
||||
vtTestEnv.correlate(new SymbolNameProgramCorrelatorFactory(), null,
|
||||
TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
TaskMonitor.DUMMY);
|
||||
|
||||
sourceAddress = sourceProgram.getAddressFactory().getAddress("0x00411860");
|
||||
sourceFunction = sourceProgram.getFunctionManager().getFunctionAt(sourceAddress);
|
||||
|
@ -580,7 +573,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
private void replaceMarkup(VTMatch match, String markupSourceAddress, String markupType) {
|
||||
MatchInfo matchInfo = controller.getMatchInfo(match);
|
||||
Collection<VTMarkupItem> appliableMarkupItems =
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
|
||||
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
|
||||
Address itemSourceAddress = vtMarkupItem.getSourceAddress();
|
||||
VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType();
|
||||
|
@ -599,7 +592,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
private void addMarkup(VTMatch match, String markupSourceAddress, String markupType) {
|
||||
MatchInfo matchInfo = controller.getMatchInfo(match);
|
||||
Collection<VTMarkupItem> appliableMarkupItems =
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
|
||||
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
|
||||
Address itemSourceAddress = vtMarkupItem.getSourceAddress();
|
||||
VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType();
|
||||
|
@ -619,7 +612,7 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator
|
|||
String markupSourceAddress, String markupType) {
|
||||
MatchInfo matchInfo = controller.getMatchInfo(match);
|
||||
Collection<VTMarkupItem> appliableMarkupItems =
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
|
||||
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
|
||||
Address itemSourceAddress = vtMarkupItem.getSourceAddress();
|
||||
VTMarkupType itemMarkupType = vtMarkupItem.getMarkupType();
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
*/
|
||||
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 java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
|
||||
import ghidra.feature.vt.api.correlator.program.*;
|
||||
import ghidra.feature.vt.api.main.*;
|
||||
|
@ -33,12 +39,6 @@ import ghidra.program.util.AddressCorrelation;
|
|||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
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
|
||||
|
@ -61,28 +61,21 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
|
|||
protected Function sourceFunction;
|
||||
protected Function destinationFunction;
|
||||
|
||||
public AddressCorrelationTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
vtTestEnv = new VTTestEnv();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
sourceProgram = null;
|
||||
destinationProgram = null;
|
||||
session = null;
|
||||
controller = null;
|
||||
correlator = null;
|
||||
vtTestEnv.releaseSession();
|
||||
vtTestEnv.dispose();
|
||||
}
|
||||
|
||||
/////////////// TESTS ///////////////
|
||||
|
||||
@Test
|
||||
public void testExactMatchBytes() throws Exception {
|
||||
// Test a function match created by the Exact Bytes Match correlator.
|
||||
|
@ -152,7 +145,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
|
|||
|
||||
createSession(languageProgram1, languageProgram2);
|
||||
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());
|
||||
useMatch("0x00401000", "0x00402000");
|
||||
checkAddressCorrelation(LinearFunctionAddressCorrelation.NAME);
|
||||
|
@ -354,7 +348,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
|
|||
protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) {
|
||||
try {
|
||||
correlator =
|
||||
vtTestEnv.correlate(correlatorFactory, null, TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
vtTestEnv.correlate(correlatorFactory, null, TaskMonitor.DUMMY);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Assert.fail(e.getMessage());
|
||||
|
@ -392,7 +386,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
|
|||
* @param addressCorrelationName the name of the expected address correlation for determining
|
||||
* 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 =
|
||||
controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache.
|
||||
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
|
||||
|
@ -487,8 +482,9 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
|
|||
String sourceAddressString, String comment, String destinationAddressString) {
|
||||
Address srcAddress = addr(sourceAddressString, sourceProgram);
|
||||
Address destAddress =
|
||||
destinationAddressString.equals("NO_ADDRESS") ? Address.NO_ADDRESS : addr(
|
||||
destinationAddressString, destinationProgram);
|
||||
destinationAddressString.equals("NO_ADDRESS") ? Address.NO_ADDRESS
|
||||
: addr(
|
||||
destinationAddressString, destinationProgram);
|
||||
|
||||
Collection<VTMarkupItem> appliableMarkupItems =
|
||||
controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache.
|
||||
|
|
|
@ -15,8 +15,13 @@
|
|||
*/
|
||||
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 java.util.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import ghidra.app.cmd.label.SetLabelPrimaryCmd;
|
||||
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
|
||||
import ghidra.feature.vt.api.correlator.program.SymbolNameProgramCorrelatorFactory;
|
||||
|
@ -29,11 +34,7 @@ import ghidra.program.model.symbol.*;
|
|||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
import ghidra.util.task.TaskMonitorAdapter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
/**
|
||||
* 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 destinationFunction;
|
||||
|
||||
public VTExactSymbolMatch2Test() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
vtTestEnv = new VTTestEnv();
|
||||
|
@ -73,7 +70,6 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
|
|||
session = null;
|
||||
controller = null;
|
||||
correlator = null;
|
||||
vtTestEnv.releaseSession();
|
||||
vtTestEnv.dispose();
|
||||
}
|
||||
|
||||
|
@ -465,7 +461,7 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
|
|||
protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) {
|
||||
try {
|
||||
correlator =
|
||||
vtTestEnv.correlate(correlatorFactory, null, TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
vtTestEnv.correlate(correlatorFactory, null, TaskMonitor.DUMMY);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Assert.fail(e.getMessage());
|
||||
|
@ -508,7 +504,8 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
|
|||
* @param sourceAddressString the source address.
|
||||
* @param destinationAddressString the destination address.
|
||||
*/
|
||||
protected void verifyNoFunctionMatch(String sourceAddressString, String destinationAddressString) {
|
||||
protected void verifyNoFunctionMatch(String sourceAddressString,
|
||||
String destinationAddressString) {
|
||||
sourceAddress = addr(sourceAddressString, sourceProgram);
|
||||
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.
|
||||
* @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
|
||||
* @throws DuplicateNameException if the name exists
|
||||
* @throws InvalidInputException if name is invalid
|
||||
|
@ -632,7 +629,8 @@ public class VTExactSymbolMatch2Test extends AbstractGhidraHeadedIntegrationTest
|
|||
String[] actualSourceSymbols =
|
||||
convertSymbolsToNames(sourceProgram.getSymbolTable().getSymbols(sourceAddress));
|
||||
String[] actualDestSymbols =
|
||||
convertSymbolsToNames(destinationProgram.getSymbolTable().getSymbols(destinationAddress));
|
||||
convertSymbolsToNames(
|
||||
destinationProgram.getSymbolTable().getSymbols(destinationAddress));
|
||||
|
||||
Arrays.sort(actualSourceSymbols);
|
||||
Arrays.sort(actualDestSymbols);
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.swing.table.TableModel;
|
|||
|
||||
import org.junit.*;
|
||||
|
||||
import docking.ActionContext;
|
||||
import docking.action.DockingActionIf;
|
||||
import docking.menu.ActionState;
|
||||
import docking.menu.MultiStateDockingAction;
|
||||
|
@ -35,10 +36,13 @@ import docking.widgets.filter.TextFilterStrategy;
|
|||
import docking.widgets.table.GTable;
|
||||
import docking.widgets.table.threaded.ThreadedTableModel;
|
||||
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.impl.VTProgramCorrelatorInfo;
|
||||
import ghidra.feature.vt.api.main.*;
|
||||
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.VTPlugin;
|
||||
import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableModel;
|
||||
|
@ -62,7 +66,7 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
|
|||
private VTController controller;
|
||||
private Program sourceProgram;
|
||||
private Program destinationProgram;
|
||||
private PluginTool tool;
|
||||
private PluginTool vtTool;
|
||||
private VTPlugin versionTrackingPlugin;
|
||||
private FunctionManager sourceFunctionManager;
|
||||
private FunctionManager destinationFunctionManager;
|
||||
|
@ -81,10 +85,6 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
|
|||
private GhidraTableFilterPanel<?> destinationFilter;
|
||||
private VTFunctionAssociationProvider functionAssociationProvider;
|
||||
|
||||
public VTFunctionAssociationTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -92,8 +92,8 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
|
|||
setErrorGUIEnabled(false);
|
||||
|
||||
env = new VTTestEnv();
|
||||
tool = env.showTool();
|
||||
tool.setSize(800, 800);
|
||||
vtTool = env.showTool();
|
||||
vtTool.setSize(800, 800);
|
||||
env.createSession("VersionTracking/WallaceSrc", "VersionTracking/WallaceVersion2",
|
||||
new ExactMatchInstructionsProgramCorrelatorFactory());
|
||||
sourceProgram = env.getSourceProgram();
|
||||
|
@ -153,11 +153,8 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
|
|||
@After
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
runSwing(() -> tool.close());
|
||||
|
||||
env.releaseSession();
|
||||
runSwing(() -> vtTool.close());
|
||||
env.dispose();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -344,6 +341,36 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
|
|||
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
|
||||
public void testCreateManualMatchAndAcceptAction() throws Exception {
|
||||
|
||||
|
@ -617,7 +644,7 @@ public class VTFunctionAssociationTest extends AbstractGhidraHeadedIntegrationTe
|
|||
final VTFunctionAssociationProvider provider =
|
||||
(VTFunctionAssociationProvider) TestUtils.getInstanceField(
|
||||
"functionAssociationProvider", versionTrackingPlugin);
|
||||
runSwing(() -> tool.showComponentProvider(provider, true));
|
||||
runSwing(() -> vtTool.showComponentProvider(provider, true));
|
||||
waitForSwing();
|
||||
waitForTasks();
|
||||
waitForSwing();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
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 org.junit.Assert.*;
|
||||
|
||||
|
@ -51,9 +51,9 @@ import ghidra.util.Msg;
|
|||
import ghidra.util.exception.DuplicateNameException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
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
|
||||
// ============================
|
||||
|
@ -97,15 +97,9 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
|
|||
protected Function sourceFunction;
|
||||
protected Function destinationFunction;
|
||||
|
||||
public AbstractFunctionSignatureMarkupTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
// setErrorGUIEnabled(false);
|
||||
|
||||
vtTestEnv = new VTTestEnv();
|
||||
session = vtTestEnv.createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
|
||||
try {
|
||||
|
@ -146,7 +140,6 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
|
|||
session = null;
|
||||
controller = null;
|
||||
correlator = null;
|
||||
vtTestEnv.releaseSession();
|
||||
vtTestEnv.dispose();
|
||||
|
||||
}
|
||||
|
@ -388,7 +381,7 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
|
|||
protected VTMarkupItem getFunctionSignatureMarkup(VTMatch match) {
|
||||
MatchInfo matchInfo = controller.getMatchInfo(match);
|
||||
Collection<VTMarkupItem> appliableMarkupItems =
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
|
||||
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
|
||||
if (vtMarkupItem.getMarkupType() instanceof FunctionSignatureMarkupType) {
|
||||
return vtMarkupItem;
|
||||
|
@ -402,7 +395,7 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
|
|||
List<VTMarkupItem> list = new ArrayList<>();
|
||||
MatchInfo matchInfo = controller.getMatchInfo(match);
|
||||
Collection<VTMarkupItem> appliableMarkupItems =
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitorAdapter.DUMMY_MONITOR);
|
||||
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
|
||||
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
|
||||
if (vtMarkupItem.getMarkupType().getClass() == markupTypeClass) {
|
||||
if (!onlyUnapplied || vtMarkupItem.getStatus() == VTMarkupItemStatus.UNAPPLIED) {
|
||||
|
@ -413,32 +406,6 @@ public abstract class AbstractFunctionSignatureMarkupTest extends AbstractGhidra
|
|||
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) {
|
||||
List<VTMatchSet> matchSets = session.getMatchSets();
|
||||
// Get matchSet 2 since 0 is manual matches and 1 is implied matches.
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
*/
|
||||
package ghidra.feature.vt.gui;
|
||||
|
||||
import static docking.test.AbstractDockingTest.performAction;
|
||||
import static docking.test.AbstractDockingTest.waitForTableModel;
|
||||
import static generic.test.AbstractGenericTest.*;
|
||||
import static docking.test.AbstractDockingTest.*;
|
||||
|
||||
import java.io.IOException;
|
||||
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.main.*;
|
||||
import ghidra.feature.vt.api.util.VTOptions;
|
||||
import ghidra.feature.vt.gui.plugin.VTController;
|
||||
import ghidra.feature.vt.gui.plugin.VTPlugin;
|
||||
import ghidra.feature.vt.gui.plugin.*;
|
||||
import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableModel;
|
||||
import ghidra.feature.vt.gui.provider.matchtable.VTMatchTableProvider;
|
||||
import ghidra.framework.plugintool.Plugin;
|
||||
|
@ -132,7 +129,7 @@ public class VTTestEnv extends TestEnv {
|
|||
return correlator;
|
||||
}
|
||||
|
||||
public void releaseSession() {
|
||||
private void releaseSession() {
|
||||
if (sourceProgram != null) {
|
||||
release(sourceProgram);
|
||||
}
|
||||
|
@ -141,6 +138,12 @@ public class VTTestEnv extends TestEnv {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
releaseSession();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public VTController getVTController() {
|
||||
return controller;
|
||||
}
|
||||
|
@ -153,6 +156,16 @@ public class VTTestEnv extends TestEnv {
|
|||
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() {
|
||||
return destinationProgram;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue