Ghidra is a software reverse engineering (SRE) framework
GP-368 fix External Programs table rename / edit actions
dev747368874d5034e616
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/AddExternalReferenceNameAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/AddExternalReferenceNameAction.javadeleted file mode 100644index 65917ba146..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/AddExternalReferenceNameAction.java+++ /dev/null@@ -1,58 +0,0 @@-/* ###- * 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.app.plugin.core.references;--import javax.swing.ImageIcon;--import docking.ActionContext;-import docking.action.*;-import docking.widgets.dialogs.InputDialog;-import ghidra.app.cmd.refs.AddExternalNameCmd;-import ghidra.program.model.symbol.SourceType;-import ghidra.util.HelpLocation;-import ghidra.util.Msg;-import resources.ResourceManager;---public class AddExternalReferenceNameAction extends DockingAction {- private static ImageIcon ADD_ICON = ResourceManager.loadImage("images/Plus.png");- private final ExternalReferencesProvider provider;-- public AddExternalReferenceNameAction(ExternalReferencesProvider provider) {- super("Add External Program Name", provider.getOwner());- this.provider = provider;- setPopupMenuData( new MenuData( new String[] {"Add External Program"}, ADD_ICON, null ) );- setToolBarData( new ToolBarData(ADD_ICON, null ) );- }-- @Override- public void actionPerformed(ActionContext context) {- InputDialog dialog = new InputDialog("New External Program", "Enter Name");- dialog.setHelpLocation(new HelpLocation("ReferencesPlugin", "Add_External_Program_Name"));- provider.getTool().showDialog(dialog, provider);- if (dialog.isCanceled()) {- return;- }- String newExternalName = dialog.getValue().trim();- if (newExternalName.isEmpty()) {- Msg.showError(this, dialog.getComponent(), "Invalid Input",- "External program name cannot be empty");- return;- }- AddExternalNameCmd cmd = new AddExternalNameCmd(newExternalName, SourceType.USER_DEFINED);- provider.getTool().execute(cmd, provider.getProgram());- }-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ClearExternalNameAssociationAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ClearExternalNameAssociationAction.javadeleted file mode 100644index ddad0f59a3..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ClearExternalNameAssociationAction.java+++ /dev/null@@ -1,62 +0,0 @@-/* ###- * 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.- * 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.app.plugin.core.references;--import ghidra.app.cmd.refs.ClearExternalNameCmd;-import ghidra.framework.cmd.CompoundCmd;-import ghidra.program.model.listing.Program;--import java.util.List;--import javax.swing.ImageIcon;--import resources.ResourceManager;-import docking.ActionContext;-import docking.action.*;---public class ClearExternalNameAssociationAction extends DockingAction {- private static ImageIcon CLEAR_ICON = ResourceManager.loadImage("images/erase16.png");- private final ExternalReferencesProvider provider;--- public ClearExternalNameAssociationAction(ExternalReferencesProvider provider) {- super("Clear External Name Association", provider.getOwner());- this.provider = provider;- this.setPopupMenuData( new MenuData(- new String[] {"Clear External Name Association"}, CLEAR_ICON, null ) );-- this.setToolBarData( new ToolBarData(CLEAR_ICON, null ) );-- setEnabled(true);- }- @Override- public boolean isAddToPopup(ActionContext context) {- return true;- }-- @Override- public void actionPerformed(ActionContext context) {- Program program = provider.getProgram();- List<String> externalNames = provider.getSelectedExternalNames();- CompoundCmd cmd = new CompoundCmd("Clear External Program Associations");- for (String externalName : externalNames) {- cmd.add(new ClearExternalNameCmd(externalName));- }- provider.getTool().execute(cmd, program);- }-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/DeleteExternalReferenceNameAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/DeleteExternalReferenceNameAction.javadeleted file mode 100644index 02cab3228b..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/DeleteExternalReferenceNameAction.java+++ /dev/null@@ -1,82 +0,0 @@-/* ###- * 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.- * 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.app.plugin.core.references;--import ghidra.app.cmd.refs.RemoveExternalNameCmd;-import ghidra.framework.cmd.CompoundCmd;-import ghidra.program.model.listing.Program;-import ghidra.program.model.symbol.ExternalManager;-import ghidra.util.Msg;--import java.util.List;--import javax.swing.ImageIcon;--import resources.ResourceManager;-import docking.ActionContext;-import docking.action.*;--public class DeleteExternalReferenceNameAction extends DockingAction {- private static ImageIcon DELETE_ICON = ResourceManager.loadImage("images/edit-delete.png");- private final ExternalReferencesProvider provider;-- public DeleteExternalReferenceNameAction(ExternalReferencesProvider provider) {- super("Delete External Program Name", provider.getOwner());- this.provider = provider;-// ACTIONS - auto generated- this.setPopupMenuData(new MenuData(new String[] { "Delete External Program" }, DELETE_ICON,- null));-- this.setToolBarData(new ToolBarData(DELETE_ICON, null));-- setEnabled(true);- }-- @Override- public boolean isAddToPopup(ActionContext context) {- return true;- }-- @Override- public void actionPerformed(ActionContext context) {- Program program = provider.getProgram();- ExternalManager externalManager = program.getExternalManager();- List<String> externalNames = provider.getSelectedExternalNames();- StringBuffer buf = new StringBuffer();- CompoundCmd cmd = new CompoundCmd("Delete External Program Name");- for (String externalName : externalNames) {- boolean hasLocations = externalManager.getExternalLocations(externalName).hasNext();- if (hasLocations) {- buf.append("\n ");- buf.append(externalName);- }- else {- cmd.add(new RemoveExternalNameCmd(externalName));- }- }- if (cmd.size() > 0) {- provider.getTool().execute(cmd, program);- }- if (buf.length() > 0) {- Msg.showError(getClass(), provider.getComponent(),- "Delete Failure", "The following external reference names could not be deleted\n" +- "because they contain external locations:\n" + buf.toString());- }-- }--}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalNamesTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalNamesTableModel.javadeleted file mode 100644index 12dfa43a67..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalNamesTableModel.java+++ /dev/null@@ -1,156 +0,0 @@-/* ###- * 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.app.plugin.core.references;--import java.awt.Window;-import java.util.*;--import org.apache.commons.lang3.StringUtils;--import docking.widgets.table.AbstractSortedTableModel;-import ghidra.app.cmd.refs.UpdateExternalNameCmd;-import ghidra.framework.cmd.Command;-import ghidra.framework.plugintool.PluginTool;-import ghidra.program.model.listing.Library;-import ghidra.program.model.listing.Program;-import ghidra.program.model.symbol.ExternalManager;-import ghidra.program.model.symbol.SourceType;-import ghidra.util.Msg;--public class ExternalNamesTableModel extends AbstractSortedTableModel<ExternalPath> {-- final static int NAME_COL = 0;- final static int PATH_COL = 1;- final static String EXTERNAL_NAME = "Name";- final static String PATH_NAME = "Ghidra Program";- private final List<String> columns = List.of(EXTERNAL_NAME, PATH_NAME);-- private PluginTool tool;- private Program program;- private List<ExternalPath> paths = new ArrayList<>();-- public ExternalNamesTableModel(PluginTool tool) {- this.tool = tool;- }-- @Override- public int getColumnCount() {- return columns.size();- }-- @Override- public String getColumnName(int column) {- return columns.get(column);- }-- @Override- public String getName() {- return "External Programs Model";- }-- @Override- public boolean isSortable(int columnIndex) {- return true;- }-- @Override- public boolean isCellEditable(int rowIndex, int columnIndex) {- if (columnIndex == NAME_COL) {- return true;- }- return false;- }-- @Override- public List<ExternalPath> getModelData() {- return paths;- }-- @Override- public Object getColumnValueForRow(ExternalPath t, int columnIndex) {-- switch (columnIndex) {- case NAME_COL:- return t.getName();- case PATH_COL:- return t.getPath();- }- return "Unknown Column!";- }-- @Override- public void setValueAt(Object aValue, int row, int column) {-- String newName = ((String) aValue).trim();- if (StringUtils.isBlank(newName)) {- return;- }-- int index = indexOf(newName);- if (index >= 0) {- Window window = tool.getActiveWindow();- Msg.showInfo(getClass(), window, "Duplicate Name", "Name already exists: " + newName);- return;- }-- ExternalPath path = paths.get(row);- String oldName = path.getName();- Command cmd = new UpdateExternalNameCmd(oldName, newName, SourceType.USER_DEFINED);- if (!tool.execute(cmd, program)) {- tool.setStatusInfo(cmd.getStatusMsg());- }- }-- private int indexOf(String name) {- for (int i = 0; i < paths.size(); i++) {- ExternalPath path = paths.get(i);- if (path.getName().equals(name)) {- return i;- }- }- return 0;- }-- void setProgram(Program program) {- this.program = program;- updateTableData();- }-- void updateTableData() {-- paths.clear();-- if (program == null) {- fireTableDataChanged();- return;- }-- ExternalManager extMgr = program.getExternalManager();- String[] programNames = extMgr.getExternalLibraryNames();- Arrays.sort(programNames);-- for (String programName : programNames) {- if (Library.UNKNOWN.equals(programName)) {- continue;- }-- ExternalPath path =- new ExternalPath(programName, extMgr.getExternalLibraryPath(programName));- paths.add(path);- }- fireTableDataChanged();- }-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalPath.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalPath.javadeleted file mode 100644index 14588b9235..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalPath.java+++ /dev/null@@ -1,72 +0,0 @@-/* ###- * 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.app.plugin.core.references;--import java.util.Objects;--/**- * A simple container class used as a row object- */-class ExternalPath {-- private String name;- private String path;-- ExternalPath(String name, String path) {- this.name = name;- this.path = path;- }-- String getName() {- return name;- }-- String getPath() {- return path;- }-- @Override- public int hashCode() {- final int prime = 31;- int result = 1;- result = prime * result + ((name == null) ? 0 : name.hashCode());- result = prime * result + ((path == null) ? 0 : path.hashCode());- return result;- }-- @Override- public boolean equals(Object obj) {- if (this == obj) {- return true;- }- if (obj == null) {- return false;- }- if (getClass() != obj.getClass()) {- return false;- }-- ExternalPath other = (ExternalPath) obj;- if (!Objects.equals(name, other.name)) {- return false;- }- if (!Objects.equals(path, other.path)) {- return false;- }- return true;- }--}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalReferencesProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalReferencesProvider.javaindex 8c5ca5647f..c1363e5505 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalReferencesProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ExternalReferencesProvider.java@@ -16,53 +16,103 @@package ghidra.app.plugin.core.references;import java.awt.BorderLayout;-import java.awt.Component;-import java.awt.event.*;-import java.util.ArrayList;-import java.util.List;+import java.awt.event.MouseEvent;+import java.util.*;import javax.swing.*;+import org.apache.commons.lang3.StringUtils;+import docking.ActionContext;+import docking.action.builder.ActionBuilder;+import docking.widgets.dialogs.InputDialog;+import docking.widgets.table.AbstractSortedTableModel;+import ghidra.app.cmd.refs.*;+import ghidra.framework.cmd.Command;+import ghidra.framework.cmd.CompoundCmd;+import ghidra.framework.main.DataTreeDialog;+import ghidra.framework.model.DomainFile;import ghidra.framework.model.DomainObjectListener;import ghidra.framework.plugintool.ComponentProviderAdapter;-import ghidra.framework.plugintool.PluginTool;+import ghidra.program.model.listing.Library;import ghidra.program.model.listing.Program;+import ghidra.program.model.symbol.ExternalManager;+import ghidra.program.model.symbol.SourceType;import ghidra.util.HelpLocation;+import ghidra.util.Msg;import ghidra.util.table.GhidraTable;+import resources.ResourceManager;+/**+ * ComponentProvider that displays a table of External Programs.+ * <p>+ */public class ExternalReferencesProvider extends ComponentProviderAdapter {+ private static ImageIcon ADD_ICON = ResourceManager.loadImage("images/Plus.png");+ private static ImageIcon DELETE_ICON = ResourceManager.loadImage("images/edit-delete.png");+ private static ImageIcon EDIT_ICON = ResourceManager.loadImage("images/editbytes.gif");+ private static ImageIcon CLEAR_ICON = ResourceManager.loadImage("images/erase16.png");+private JPanel mainPanel;private ExternalNamesTableModel tableModel;private GhidraTable table;private Program program;+ private String rowToHighlightDuringNextReload; // hack to reselect a renamed row during the next reload.private DomainObjectListener domainObjectListener = ev -> {if (isVisible()) {tableModel.updateTableData();+ if (rowToHighlightDuringNextReload != null) {+ int row = tableModel.indexOf(rowToHighlightDuringNextReload);+ rowToHighlightDuringNextReload = null;+ if (row >= 0) {+ table.selectRow(row);+ }+ }}};- private AddExternalReferenceNameAction addExternalAction;- private DeleteExternalReferenceNameAction deleteExternalAction;- private SetExternalNameAssociationAction setAssocationAction;- private ClearExternalNameAssociationAction clearAssociationAction;-public ExternalReferencesProvider(ReferencesPlugin plugin) {super(plugin.getTool(), "External Programs", plugin.getName());mainPanel = buildMainPanel();+ createActions();setHelpLocation(new HelpLocation("ReferencesPlugin", "ExternalNamesDialog"));addToTool();- addExternalAction = new AddExternalReferenceNameAction(this);- deleteExternalAction = new DeleteExternalReferenceNameAction(this);- setAssocationAction = new SetExternalNameAssociationAction(this);- clearAssociationAction = new ClearExternalNameAssociationAction(this);+ }++ private void createActions() {+ new ActionBuilder("Add External Program Name", getOwner())+ .popupMenuPath("Add External Program")+ .popupMenuIcon(ADD_ICON)+ .toolBarIcon(ADD_ICON)+ .enabledWhen(ac -> program != null)+ .onAction(ac -> addExternalProgram())+ .buildAndInstallLocal(this);++ new ActionBuilder("Delete External Program Name", getOwner())+ .popupMenuPath("Delete External Program")+ .popupMenuIcon(DELETE_ICON)+ .toolBarIcon(DELETE_ICON)+ .enabledWhen(ac -> hasSelectedRows())+ .onAction(ac -> deleteExternalProgram())+ .buildAndInstallLocal(this);++ new ActionBuilder("Set External Name Association", getOwner())+ .popupMenuPath("Set External Name Association")+ .popupMenuIcon(EDIT_ICON)+ .toolBarIcon(EDIT_ICON)+ .enabledWhen(ac -> isSingleRowSelected())+ .onAction(ac -> setExternalProgramAssociation())+ .buildAndInstallLocal(this);++ new ActionBuilder("Clear External Name Association", getOwner())+ .popupMenuPath("Clear External Name Association")+ .popupMenuIcon(CLEAR_ICON)+ .toolBarIcon(CLEAR_ICON)+ .enabledWhen(ac -> hasSelectedRows())+ .onAction(ac -> clearExternalAssociation())+ .buildAndInstallLocal(this);- addLocalAction(addExternalAction);- addLocalAction(setAssocationAction);- addLocalAction(clearAssociationAction);- addLocalAction(deleteExternalAction);- updateActionEnablement();}@Override@@ -71,6 +121,7 @@ public class ExternalReferencesProvider extends ComponentProviderAdapter {}void setProgram(Program program) {+ rowToHighlightDuringNextReload = null;if (this.program != null) {this.program.removeListener(domainObjectListener);}@@ -80,19 +131,18 @@ public class ExternalReferencesProvider extends ComponentProviderAdapter {}if (isVisible()) {- tableModel.setProgram(program);+ tableModel.updateTableData();}- updateActionEnablement();}@Overridepublic void componentHidden() {- tableModel.setProgram(null);+ tableModel.updateTableData();}@Overridepublic void componentShown() {- tableModel.setProgram(program);+ tableModel.updateTableData();}@Override@@ -102,43 +152,9 @@ public class ExternalReferencesProvider extends ComponentProviderAdapter {private JPanel buildMainPanel() {JPanel panel = new JPanel(new BorderLayout());- tableModel = new ExternalNamesTableModel(tool);-+ tableModel = new ExternalNamesTableModel();table = new GhidraTable(tableModel);- InputMap inputMap = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);- KeyStroke enter = KeyStroke.getKeyStroke("ENTER");- while (inputMap != null) {- inputMap.remove(enter);- inputMap = inputMap.getParent();- }-- table.addKeyListener(new KeyAdapter() {- @Override- public void keyReleased(KeyEvent e) {- int selectedRowCount = table.getSelectedRowCount();- if (selectedRowCount != 1) {- return;- }-- if (e.getKeyCode() == KeyEvent.VK_ENTER) {- int row = table.getSelectedRow();- table.editCellAt(row, 0);- Component editorComponent = table.getEditorComponent();- if (editorComponent != null) {- editorComponent.requestFocus();- }- }- }- });-- table.getSelectionModel().addListSelectionListener(e -> {- if (e.getValueIsAdjusting()) {- return;- }- updateActionEnablement();- });-JScrollPane sp = new JScrollPane(table);table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);@@ -149,33 +165,298 @@ public class ExternalReferencesProvider extends ComponentProviderAdapter {return panel;}- private void updateActionEnablement() {- deleteExternalAction.setEnabled(table.getSelectedRowCount() > 0);- clearAssociationAction.setEnabled(table.getSelectedRowCount() > 0);- setAssocationAction.setEnabled(table.getSelectedRowCount() == 1);- addExternalAction.setEnabled(program != null);+ private boolean isSingleRowSelected() {+ return table.getSelectedRowCount() == 1;}- public Program getProgram() {- return program;+ private boolean hasSelectedRows() {+ return table.getSelectedRowCount() > 0;}public List<String> getSelectedExternalNames() {List<String> externalNames = new ArrayList<>();- int[] selectedRows = table.getSelectedRows();- for (int row : selectedRows) {- String externalName = (String) tableModel.getValueAt(row, 0);- externalNames.add(externalName);+ for (int rowIndex : table.getSelectedRows()) {+ ExternalNamesRow row = tableModel.getRowObject(rowIndex);+ externalNames.add(row.getName());}return externalNames;}- @Override- public PluginTool getTool() {- return tool;- }-void dispose() {table.dispose();}++ private void addExternalProgram() {+ InputDialog dialog = new InputDialog("New External Program", "Enter Name");+ dialog.setHelpLocation(+ new HelpLocation("ReferencesPlugin", "Add_External_Program_Name"));+ getTool().showDialog(dialog, ExternalReferencesProvider.this);+ if (dialog.isCanceled()) {+ return;+ }+ String newExternalName = dialog.getValue().trim();+ if (newExternalName.isEmpty()) {+ Msg.showError(this, dialog.getComponent(), "Invalid Input",+ "External program name cannot be empty");+ return;+ }+ AddExternalNameCmd cmd =+ new AddExternalNameCmd(newExternalName, SourceType.USER_DEFINED);+ getTool().execute(cmd, program);+ }++ private void deleteExternalProgram() {+ ExternalManager externalManager = program.getExternalManager();+ StringBuilder buf = new StringBuilder();+ CompoundCmd cmd = new CompoundCmd("Delete External Program Name");+ for (String externalName : getSelectedExternalNames()) {+ boolean hasLocations =+ externalManager.getExternalLocations(externalName).hasNext();+ if (hasLocations) {+ buf.append("\n ");+ buf.append(externalName);+ }+ else {+ cmd.add(new RemoveExternalNameCmd(externalName));+ }+ }+ if (cmd.size() > 0) {+ getTool().execute(cmd, program);+ }+ if (buf.length() > 0) {+ Msg.showError(this, mainPanel, "Delete Failure",+ "The following external reference names could not be deleted\n" ++ "because they contain external locations:\n" + buf.toString());+ }+ }++ private void setExternalProgramAssociation() {+ List<String> selectedExternalNames = getSelectedExternalNames();+ String externalName = selectedExternalNames.get(0); // must be exactly one for us to be enabled.+ DataTreeDialog dialog = new DataTreeDialog(mainPanel,+ "Choose External Program (" + externalName + ")", DataTreeDialog.OPEN);++ dialog.setSearchText(externalName);++ dialog.addOkActionListener(e1 -> {+ DomainFile domainFile = dialog.getDomainFile();+ if (domainFile == null) {+ return;+ }+ String pathName = domainFile.toString();+ dialog.close();+ ExternalManager externalManager = program.getExternalManager();+ String externalLibraryPath =+ externalManager.getExternalLibraryPath(externalName);+ if (!pathName.equals(externalLibraryPath)) {+ Command cmd =+ new SetExternalNameCmd(externalName, domainFile.getPathname());+ getTool().execute(cmd, program);+ }+ });+ dialog.setHelpLocation(+ new HelpLocation("ReferencesPlugin", "ChooseExternalProgram"));+ getTool().showDialog(dialog);+ }++ private void clearExternalAssociation() {+ CompoundCmd cmd = new CompoundCmd("Clear External Program Associations");+ for (String externalName : getSelectedExternalNames()) {+ cmd.add(new ClearExternalNameCmd(externalName));+ }+ getTool().execute(cmd, program);+ }++ //-----------------------------------------------------------------------------------------+ private static class ExternalNamesRow {++ private String name;+ private String path;++ ExternalNamesRow(String name, String path) {+ this.name = name;+ this.path = path;+ }++ String getName() {+ return name;+ }++ String getPath() {+ return path;+ }++ @Override+ public int hashCode() {+ final int prime = 31;+ int result = 1;+ result = prime * result + ((name == null) ? 0 : name.hashCode());+ result = prime * result + ((path == null) ? 0 : path.hashCode());+ return result;+ }++ @Override+ public boolean equals(Object obj) {+ if (this == obj) {+ return true;+ }+ if (obj == null) {+ return false;+ }+ if (getClass() != obj.getClass()) {+ return false;+ }++ ExternalNamesRow other = (ExternalNamesRow) obj;+ if (!Objects.equals(name, other.name)) {+ return false;+ }+ if (!Objects.equals(path, other.path)) {+ return false;+ }+ return true;+ }++ }++ class ExternalNamesTableModel extends AbstractSortedTableModel<ExternalNamesRow> {++ final static int NAME_COL = 0;+ final static int PATH_COL = 1;+ final static String EXTERNAL_NAME = "Name";+ final static String PATH_NAME = "Ghidra Program";+ private final List<String> columns = List.of(EXTERNAL_NAME, PATH_NAME);++ private List<ExternalNamesRow> paths = new ArrayList<>();++ void updateTableData() {+ paths.clear();++ if (program != null && isVisible()) {+ ExternalManager extMgr = program.getExternalManager();+ String[] programNames = extMgr.getExternalLibraryNames();+ Arrays.sort(programNames);++ for (String programName : programNames) {+ if (Library.UNKNOWN.equals(programName)) {+ continue;+ }++ ExternalNamesRow path =+ new ExternalNamesRow(programName, extMgr.getExternalLibraryPath(programName));+ paths.add(path);+ }+ }+ tableModel.fireTableDataChanged();+ }++ private boolean rowAlreadyExists(String name) {+ return indexOf(name) != -1;+ }++ private int indexOf(String name) {+ for (int i = 0; i < paths.size(); i++) {+ ExternalNamesRow path = paths.get(i);+ if (path.getName().equals(name)) {+ return i;+ }+ }+ return -1;+ }+++ @Override+ public void dispose() {+ super.dispose();+ paths.clear();+ }++ @Override+ public int getColumnCount() {+ return columns.size();+ }++ @Override+ public String getColumnName(int column) {+ return columns.get(column);+ }++ @Override+ public String getName() {+ return "External Programs Model";+ }++ @Override+ public boolean isSortable(int columnIndex) {+ return true;+ }++ @Override+ public boolean isCellEditable(int rowIndex, int columnIndex) {+ if (columnIndex == NAME_COL) {+ return true;+ }+ return false;+ }++ @Override+ public List<ExternalNamesRow> getModelData() {+ return paths;+ }++ @Override+ public Object getColumnValueForRow(ExternalNamesRow t, int columnIndex) {++ switch (columnIndex) {+ case NAME_COL:+ return t.getName();+ case PATH_COL:+ return t.getPath();+ }+ return "Unknown Column!";+ }++ @Override+ public void setValueAt(Object aValue, int row, int column) {+ if (column != NAME_COL) {+ return;+ }++ String newName = ((String) aValue).trim();+ ExternalNamesRow path = paths.get(row);+ if (StringUtils.isBlank(newName) || path.getName().equals(newName)) {+ return;+ }++ if (rowAlreadyExists(newName)) {+ Msg.showInfo(getClass(), mainPanel, "Duplicate Name",+ "Name already exists: " + newName);+ return;+ }++ rowToHighlightDuringNextReload = newName;+ String oldName = path.getName();+ Command cmd = new UpdateExternalNameCmd(oldName, newName, SourceType.USER_DEFINED);+ if (!tool.execute(cmd, program)) {+ tool.setStatusInfo(cmd.getStatusMsg());+ }+ }++ @Override+ protected Comparator<ExternalNamesRow> createSortComparator(int columnIndex) {+ if (columnIndex == PATH_COL) {+ // force the path column to have a secondary compare using the name column+ // to ensure a 'stable' sort. Without this during analysis+ // the constant updates cause the table to sort randomly when+ // there are lots of empty path values.+ Comparator<ExternalNamesRow> c1 =+ (r1, r2) -> Objects.requireNonNullElse(r1.getPath(), "")+ .compareTo(Objects.requireNonNullElse(r2.getPath(), ""));+ return c1.thenComparing((r1, r2) -> r1.getName().compareTo(r2.getName()));+ }+ return super.createSortComparator(columnIndex);+ }++ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/SetExternalNameAssociationAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/SetExternalNameAssociationAction.javadeleted file mode 100644index 94b66aa3e7..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/SetExternalNameAssociationAction.java+++ /dev/null@@ -1,85 +0,0 @@-/* ###- * 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.- * 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.app.plugin.core.references;--import ghidra.app.cmd.refs.SetExternalNameCmd;-import ghidra.framework.cmd.Command;-import ghidra.framework.main.DataTreeDialog;-import ghidra.framework.model.DomainFile;-import ghidra.program.model.symbol.ExternalManager;-import ghidra.util.HelpLocation;--import java.awt.event.ActionEvent;-import java.awt.event.ActionListener;-import java.util.List;--import javax.swing.ImageIcon;--import resources.ResourceManager;-import docking.ActionContext;-import docking.action.*;---public class SetExternalNameAssociationAction extends DockingAction {- private static ImageIcon EDIT_ICON = ResourceManager.loadImage("images/editbytes.gif");- private final ExternalReferencesProvider provider;--- public SetExternalNameAssociationAction(ExternalReferencesProvider provider) {- super("Set External Name Association", provider.getOwner());- this.provider = provider;- this.setPopupMenuData(- new MenuData( new String[] {"Set External Name Association"}, EDIT_ICON, null ) );-- this.setToolBarData( new ToolBarData(EDIT_ICON, null ) );-- setEnabled(true);- }- @Override- public boolean isAddToPopup(ActionContext context) {- return true;- }- @Override- public void actionPerformed(ActionContext context) {- List<String> selectedExternalNames = provider.getSelectedExternalNames();- final String externalName = selectedExternalNames.get(0); // must be exactly one for us to be enabled.- final DataTreeDialog dialog = new DataTreeDialog( provider.getComponent(),- "Choose External Program ("+externalName+")", DataTreeDialog.OPEN );-- dialog.setSearchText(externalName);-- dialog.addOkActionListener(new ActionListener() {- public void actionPerformed(ActionEvent e1) {- DomainFile domainFile = dialog.getDomainFile();- if (domainFile == null) {- return;- }- String pathName = domainFile.toString();- dialog.close();- ExternalManager externalManager = provider.getProgram().getExternalManager();- String externalLibraryPath = externalManager.getExternalLibraryPath(externalName);- if (!pathName.equals(externalLibraryPath)) {- Command cmd = new SetExternalNameCmd(externalName, domainFile.getPathname());- provider.getTool().execute(cmd, provider.getProgram());- }- }- });- dialog.setHelpLocation(new HelpLocation("ReferencesPlugin","ChooseExternalProgram"));- provider.getTool().showDialog(dialog);- }--}