Ghidra is a software reverse engineering (SRE) framework
Removed a wrapper class that was preventing sorting from working correctly
dragonmacher6ae5f9320f2b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapProvider.javaindex 4886f7e05d..e5f3758566 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapProvider.java@@ -295,8 +295,7 @@ class MemoryMapProvider extends ComponentProviderAdapter {setBaseAction.setDescription("Set Image Base");tool.addLocalAction(this, setBaseAction);- MakeProgramSelectionAction action =- new MakeProgramSelectionAction(plugin, table);+ MakeProgramSelectionAction action = new MakeProgramSelectionAction(plugin, table);action.getToolBarData().setToolBarGroup("B"); // the other actions are in group 'A'tool.addLocalAction(this, action);}@@ -370,10 +369,6 @@ class MemoryMapProvider extends ComponentProviderAdapter {return table;}- MemoryMapModel getModel() {- return tableModel;- }-/*** Update the memory map table. Something has changed.*/diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTable.java b/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTable.javaindex 9b6198b48c..75838fb184 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTable.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTable.java@@ -24,6 +24,7 @@ import javax.swing.table.TableCellRenderer;import javax.swing.table.TableModel;import docking.widgets.table.GTable;+import docking.widgets.table.WrappingTableModel;import ghidra.app.nav.Navigatable;import ghidra.app.services.GoToService;import ghidra.framework.plugintool.ServiceProvider;@@ -36,10 +37,10 @@ import ghidra.util.Msg;/*** Navigation is only supported if the underlying table model* implements <code>ProgramTableModel</code> and the <code>setGoToService()</code> method- * has been called with a valid reference. When both of these conditions are met, then the- * table will navigate on a user's double-click or on an <code>Enter</code> key press. Also, if+ * has been called with a valid reference. When both of these conditions are met, then the+ * table will navigate on a user's double-click or on an <code>Enter</code> key press. Also, if* selection navigation is enabled, then this table will navigate <b>any time the selection of- * the table changes</b>. To prevent this feature call+ * the table changes</b>. To prevent this feature call* {@link #setNavigateOnSelectionEnabled(boolean)} with a value of false.* <p>*/@@ -53,14 +54,13 @@ public class GhidraTable extends GTable {private ListSelectionListener navigationSelectionListener;public GhidraTable() {- super();}public GhidraTable(TableModel model) {super(model);}- /**+ /*** Installs the default {@link TableCellRenderer}s for known Ghidra table cell data classes.* Subclasses can override this method to add additional types or to change the default* associations.@@ -82,7 +82,7 @@ public class GhidraTable extends GTable {* Sets the GoTo service to use when navigation is enabled on this table.* @param goToService the GoTo service* @param nav the navigable- * @deprecated use {@link #installNavigation(ServiceProvider)} or+ * @deprecated use {@link #installNavigation(ServiceProvider)} or* {@link #installNavigation(ServiceProvider,Navigatable)}*/@Deprecated@@ -91,11 +91,11 @@ public class GhidraTable extends GTable {}/**- * Sets the service provider to use when navigation is enabled on this table. The service- * provider will be used to retrieve the {@link GoToService}, as needed after the system has- * been initialized. If you do not have a {@link Navigatable} preferences, then call+ * Sets the service provider to use when navigation is enabled on this table. The service+ * provider will be used to retrieve the {@link GoToService}, as needed after the system has+ * been initialized. If you do not have a {@link Navigatable} preferences, then call* {@link #installNavigation(ServiceProvider)} instead.- *+ ** @param sp the service provider* @param nav the navigable*/@@ -113,10 +113,10 @@ public class GhidraTable extends GTable {}/**- * Sets the service provider to use when navigation is enabled on this table. The service- * provider will be used to retrieve the {@link GoToService}, as needed after the system has+ * Sets the service provider to use when navigation is enabled on this table. The service+ * provider will be used to retrieve the {@link GoToService}, as needed after the system has* been initialized.- *+ ** @param sp the service provider*/public void installNavigation(ServiceProvider sp) {@@ -165,7 +165,7 @@ public class GhidraTable extends GTable {}/**- * Removes any installed navigation components, such as listeners, a navigatable and the+ * Removes any installed navigation components, such as listeners, a navigatable and the* service provider.*/public void removeNavigation() {@@ -178,7 +178,7 @@ public class GhidraTable extends GTable {}/**- * Returns the program selection equivalent to the rows currently selected in the table.+ * Returns the program selection equivalent to the rows currently selected in the table.* This method is only valid when the underlying table model implements* {@link ProgramTableModel}.* <P>@@ -191,13 +191,19 @@ public class GhidraTable extends GTable {if (programTableModel == null) {return null;}- return programTableModel.getProgramSelection(getSelectedRows());++ int[] viewRows = getSelectedRows();+ int[] modelRows = new int[viewRows.length];+ for (int i = 0; i < viewRows.length; i++) {+ modelRows[i] = getModelRow(viewRows[i]);+ }+ return programTableModel.getProgramSelection(modelRows);}/*** Returns the program being used by this table; null if the underlying model does not* implement {@link ProgramTableModel}- *+ ** @return the table's program*/public Program getProgram() {@@ -209,20 +215,21 @@ public class GhidraTable extends GTable {}private ProgramTableModel getProgramTableModel(TableModel model) {- if (model instanceof ProgramTableModel) {- return (ProgramTableModel) model;+ TableModel baseModel = getUnwrappedTableModel();+ if (baseModel instanceof ProgramTableModel) {+ return (ProgramTableModel) baseModel;}return null;}/**- * Does nothing if no {@link GoToService} has been installed from- * {@link #installNavigation(GoToService, Navigatable)}. Also, this method will do- * nothing if this table's <code>TableModel</code> is not an instance of {@link ProgramTableModel}.- * Otherwise, this method will attempt to go to the program location denoted by the+ * Does nothing if no {@link GoToService} has been installed from+ * {@link #installNavigation(GoToService, Navigatable)}. Also, this method will do+ * nothing if this table's <code>TableModel</code> is not an instance of {@link ProgramTableModel}.+ * Otherwise, this method will attempt to go to the program location denoted by the* given row and column.- *- * @param row the row+ *+ * @param row the row* @param column the column*/public void navigate(int row, int column) {@@ -230,12 +237,13 @@ public class GhidraTable extends GTable {return;}- column = convertColumnIndexToModel(column);+ int modelColumn = convertColumnIndexToModel(column);if (row < 0 || column < 0) {return;}- if (!(dataModel instanceof ProgramTableModel)) {+ ProgramTableModel programModel = getProgramTableModel(dataModel);+ if (programModel == null) {return;}@@ -244,22 +252,29 @@ public class GhidraTable extends GTable {return;}- ProgramTableModel ptm = (ProgramTableModel) dataModel;- ProgramLocation loc = ptm.getProgramLocation(row, column);+ int modelRow = getModelRow(row);+ ProgramLocation loc = programModel.getProgramLocation(modelRow, modelColumn);if (loc != null && loc.getAddress().isExternalAddress()) {- goToService.goTo(loc.getAddress(), ptm.getProgram());+ goToService.goTo(loc.getAddress(), programModel.getProgram());return;}- Program program = ptm.getProgram();+ Program program = programModel.getProgram();goToService.goTo(navigatable, loc, program);}+ private int getModelRow(int viewRow) {+ if (dataModel instanceof WrappingTableModel) {+ return ((WrappingTableModel) dataModel).getModelRow(viewRow);+ }+ return viewRow;+ }+/**- * Does nothing if no {@link GoToService} has been installed from- * {@link #installNavigation(GoToService, Navigatable)}. Otherwise, this method will attempt+ * Does nothing if no {@link GoToService} has been installed from+ * {@link #installNavigation(GoToService, Navigatable)}. Otherwise, this method will attempt* to go to the program location denoted by the given row and column.* <p>- * This method differs from {@link #navigate(int, int)} in that this method will not+ * This method differs from {@link #navigate(int, int)} in that this method will not* navigate if {@link #navigateOnSelection} is <code>false</code>.*/private void navigateOnCurrentSelection(int row, int column) {@@ -290,9 +305,9 @@ public class GhidraTable extends GTable {// Protect against a timing issue whereby program-based table models have had their// program closed while an edit is open. Sometimes, when the table repaints, the table// will trigger an editingStopped(), which attempts to commit the active edit. This can- // trigger an exception when the model attempts to access the program. Here we are+ // trigger an exception when the model attempts to access the program. Here we are// attempting to prevent the edit from being committed.- //+ //if (programIsClosed()) {return;}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTableFilterPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTableFilterPanel.javaindex acb1bff4c6..de5596d170 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTableFilterPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/util/table/GhidraTableFilterPanel.java@@ -15,17 +15,10 @@*/package ghidra.util.table;-import java.util.List;-import javax.swing.JTable;-import javax.swing.event.TableModelEvent;-import javax.swing.event.TableModelListener;-import javax.swing.table.TableModel;-import docking.widgets.table.*;-import ghidra.program.model.listing.Program;-import ghidra.program.util.ProgramLocation;-import ghidra.program.util.ProgramSelection;+import docking.widgets.table.GTableFilterPanel;+import docking.widgets.table.RowObjectTableModel;/*** This is a "program aware" version of GTableFilterPanel@@ -47,203 +40,4 @@ public class GhidraTableFilterPanel<ROW_OBJECT> extends GTableFilterPanel<ROW_OBString filterLabel) {super(table, tableModel, filterLabel);}-- @Override // overridden because of our knowledge of program table models- protected RowObjectFilterModel<ROW_OBJECT> createTextFilterModel(- RowObjectTableModel<ROW_OBJECT> clientModel) {-- RowObjectFilterModel<ROW_OBJECT> filterModel = super.createTextFilterModel(clientModel);- if (!(clientModel instanceof ProgramTableModel)) {- return filterModel; // nothing to do- }-- if (filterModel instanceof ProgramTableModel) {- // the model is already filterable and a ProgramTableModel (e.g., a ThreadedTableModel)- return filterModel;- }-- return new FilterModelToProgramModelAdapter(filterModel, (ProgramTableModel) clientModel);- }--//==================================================================================================-// Inner Classes-//==================================================================================================-- /**- * A class to adapt a table model that can filter into a {@link ProgramTableModel}.- */- private class FilterModelToProgramModelAdapter- implements RowObjectFilterModel<ROW_OBJECT>, ProgramTableModel, WrappingTableModel {-- private final RowObjectFilterModel<ROW_OBJECT> filterModel;- private final ProgramTableModel programModel;-- private FilterModelToProgramModelAdapter(RowObjectFilterModel<ROW_OBJECT> tableModel,- ProgramTableModel programModel) {- this.filterModel = tableModel;- this.programModel = programModel;- }-- @Override- public String getName() {- return filterModel.getName();- }-- @Override- public void fireTableChanged(TableModelEvent event) {- if (filterModel instanceof WrappingTableModel) {- ((WrappingTableModel) filterModel).fireTableChanged(event);- }- }-- @Override- public void wrappedModelChangedFromTableChangedEvent() {- if (filterModel instanceof WrappingTableModel) {- ((WrappingTableModel) filterModel).wrappedModelChangedFromTableChangedEvent();- }- }-- @Override- public ROW_OBJECT getRowObject(int row) {- return filterModel.getRowObject(row);- }-- @Override- public List<ROW_OBJECT> getModelData() {- return filterModel.getModelData();- }-- @Override- public int getModelRow(int viewRow) {- return filterModel.getModelRow(viewRow);- }-- @Override- public int getRowIndex(ROW_OBJECT t) {- return filterModel.getRowIndex(t);- }-- @Override- public int getViewIndex(ROW_OBJECT t) {- return filterModel.getViewIndex(t);- }-- @Override- public int getModelIndex(ROW_OBJECT t) {- return filterModel.getModelIndex(t);- }-- @Override- public int getUnfilteredRowCount() {- return filterModel.getUnfilteredRowCount();- }-- @Override- public int getViewRow(int modelRow) {- return filterModel.getViewRow(modelRow);- }-- @Override- public boolean isFiltered() {- return filterModel.isFiltered();- }-- @Override- public void setTableFilter(TableFilter<ROW_OBJECT> tableFilter) {- filterModel.setTableFilter(tableFilter);- }-- @Override- public TableFilter<ROW_OBJECT> getTableFilter() {- return filterModel.getTableFilter();- }-- @Override- public void fireTableDataChanged() {- filterModel.fireTableDataChanged();- }-- @Override- public void addTableModelListener(TableModelListener l) {- filterModel.addTableModelListener(l);- }-- @Override- public void removeTableModelListener(TableModelListener l) {- filterModel.removeTableModelListener(l);- }-- @Override- public Class<?> getColumnClass(int columnIndex) {- return filterModel.getColumnClass(columnIndex);- }-- @Override- public int getColumnCount() {- return filterModel.getColumnCount();- }-- @Override- public String getColumnName(int columnIndex) {- return filterModel.getColumnName(columnIndex);- }-- @Override- public int getRowCount() {- return filterModel.getRowCount();- }-- @Override- public List<ROW_OBJECT> getUnfilteredData() {- return filterModel.getUnfilteredData();- }-- @Override- public Object getColumnValueForRow(ROW_OBJECT t, int columnIndex) {- return filterModel.getColumnValueForRow(t, columnIndex);- }-- @Override- public Object getValueAt(int rowIndex, int columnIndex) {- return filterModel.getValueAt(rowIndex, columnIndex);- }-- @Override- public boolean isCellEditable(int rowIndex, int columnIndex) {- return filterModel.isCellEditable(rowIndex, columnIndex);- }-- @Override- public void setValueAt(Object value, int rowIndex, int columnIndex) {- filterModel.setValueAt(value, rowIndex, columnIndex);- }-- @Override- public TableModel getWrappedModel() {- return filterModel;- }-- @Override- public Program getProgram() {- return programModel.getProgram();- }-- @Override- public ProgramLocation getProgramLocation(int row, int column) {- // Note: the given row is the filtered row index- int unfilteredRow = getModelRow(row);- return programModel.getProgramLocation(unfilteredRow, column);- }-- @Override- public ProgramSelection getProgramSelection(int[] rows) {- // Note: the given rows are the filtered row indexes- int[] unfilteredRows = new int[rows.length];- for (int i = 0; i < rows.length; i++) {- unfilteredRows[i] = getModelRow(rows[i]);- }- return programModel.getProgramSelection(unfilteredRows);- }- }-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/table/ProgramTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/util/table/ProgramTableModel.javaindex db47a012a8..7bd782469d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/util/table/ProgramTableModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/util/table/ProgramTableModel.java@@ -26,21 +26,21 @@ public interface ProgramTableModel {/*** Returns a program location corresponding the given row and column.* <p>- * Motivation: Given a table that has a column that contains addresses. If the user clicks on+ * Motivation: Given a table that has a column that contains addresses. If the user clicks on* this column, then it would be nice to have the CodeBrowser navigate to this address.- * @param row the row+ * @param modelRow the row* @param modelColumn the column in the model's index* @return a program location corresponding the given row and column*/- public ProgramLocation getProgramLocation(int row, int modelColumn);+ public ProgramLocation getProgramLocation(int modelRow, int modelColumn);/**- * Returns a program selection corresponding to the specified row index array. This array will+ * Returns a program selection corresponding to the specified row index array. This array will* contain the currently selected rows.- * @param rows the currently selected rows.+ * @param modelRows the currently selected rows.* @return a program selection*/- public ProgramSelection getProgramSelection(int[] rows);+ public ProgramSelection getProgramSelection(int[] modelRows);/*** Returns the program associated with this ProgramTableModel.diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.javaindex b475e256a9..45ed039279 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider1Test.java@@ -22,8 +22,7 @@ import java.awt.Rectangle;import java.util.*;import javax.swing.*;-import javax.swing.table.JTableHeader;-import javax.swing.table.TableCellEditor;+import javax.swing.table.*;import org.junit.*;@@ -55,7 +54,7 @@ public class MemoryMapProvider1Test extends AbstractGhidraHeadedIntegrationTestprivate Program program;private Memory memory;private JTable table;- private MemoryMapModel model;+ private TableModel model;private Program buildProgram(String programName) throws Exception {ProgramBuilder builder = new ProgramBuilder(programName, ProgramBuilder._TOY);@@ -118,7 +117,8 @@ public class MemoryMapProvider1Test extends AbstractGhidraHeadedIntegrationTestassertFalse(action.isEnabled());}else {- assertTrue(action.isEnabled());+ assertTrue("Action not enabled when it should be: " + action.getName(),+ action.isEnabled());}}}@@ -674,7 +674,7 @@ public class MemoryMapProvider1Test extends AbstractGhidraHeadedIntegrationTestwaitForSwing();provider = plugin.getMemoryMapProvider();table = provider.getTable();- model = provider.getModel();+ model = table.getModel();}private Address getAddr(long offset) {diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableUtils.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableUtils.javaindex 4b17fc608c..e057e24d6d 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableUtils.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/TableUtils.java@@ -31,13 +31,13 @@ public class TableUtils {/*** Uses the given row-based table model, row object and column index to determine what the* String value should be for that cell.- *+ ** <P>This is used to provide a means for filtering on the text that is displayed to the user.- *+ ** @param <ROW_OBJECT> The model's row object type* @param model the model* @param rowObject the row object for the row being queried- * @param column the column index <b>in the table model</b>+ * @param column the column index <b>in the table model</b>* @return the string value; null if no value can be fabricated*/public static <ROW_OBJECT> String getTableCellStringValue(RowObjectTableModel<ROW_OBJECT> model,@@ -56,7 +56,7 @@ public class TableUtils {2) See if the value is an instance of DisplayStringProvider, which describes howit should be rendered3) See if it is a label (this is uncommon)- 4) Rely on the toString(); this works as intended for Strings. This is the+ 4) Rely on the toString(); this works as intended for Strings. This is thedefault way that built-in table cell renderers will generate display text*/@@ -66,7 +66,7 @@ public class TableUtils {return renderedString;}- // 2) special plug-in point where clients can specify a value object that can return+ // 2) special plug-in point where clients can specify a value object that can return// its display stringif (value instanceof DisplayStringProvider) {return ((DisplayStringProvider) value).toString();@@ -91,6 +91,7 @@ public class TableUtils {return null;}+ @SuppressWarnings("unchecked")DynamicColumnTableModel<ROW_OBJECT> columnBasedModel =(DynamicColumnTableModel<ROW_OBJECT>) unwrappedModel;GColumnRenderer<Object> renderer = getColumnRenderer(columnBasedModel, columnIndex);@@ -123,14 +124,14 @@ public class TableUtils {* of the given table is not a {@link SortedTableModel}, then this method will do nothing.* <p>* If the given column index is not sortable, then this method will not change the state of- * the model. Otherwise, the sorted model will be sorted on the given column index. The+ * the model. Otherwise, the sorted model will be sorted on the given column index. The* results of calling this method depend upon the current sorted state of the given column:* <ol>- * <li>if the column is not yet the sorted column, then the column is made the sorted+ * <li>if the column is not yet the sorted column, then the column is made the sorted* column, if sortable, <b>and any other sorted columns will be made unsorted</b>, or</li>* <li>if the column is the sorted column and the direction will simply be toggled.</li>- * </ol>- *+ * </ol>+ ** @param table The table whose model shall be sorted.* @param columnIndex The column index upon which to sort.*/@@ -169,10 +170,10 @@ public class TableUtils {* of the given table is not a {@link SortedTableModel}, then this method will do nothing.* <p>* If the given column index is not sortable, then this method will not change the state of- * the model. The results of calling this method depend upon the current sorted state+ * the model. The results of calling this method depend upon the current sorted state* of the given column:* <ol>- * <li>if the column is not yet sorted, then the column is made sorted, if sortable,+ * <li>if the column is not yet sorted, then the column is made sorted, if sortable,* <b>and any other sorted columns will not be changed</b>, or</li>* <li>if the column is sorted, then:* <ol>@@ -180,8 +181,8 @@ public class TableUtils {* <li>if there are no other sorted columns, then no action will be taken</li>* </ol>* </li>- * </ol>- *+ * </ol>+ ** @param table The table whose model shall be sorted.* @param columnIndex The column index upon which to sort.*/@@ -205,9 +206,9 @@ public class TableUtils {if (editor.isColumnSorted(modelColumnIndex)) {- /*+ /*Note: this code allows us to disable the 'unsorting' of a table via the UI-+// remove it. If there is only one, don't remove the last oneif (editor.getSortedColumnCount() == 1) {Toolkit.getDefaultToolkit().beep();diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/WrappingTableModel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/WrappingTableModel.javaindex 5667319125..9e7c862c79 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/WrappingTableModel.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/WrappingTableModel.java@@ -29,6 +29,13 @@ public interface WrappingTableModel extends TableModel {*/public TableModel getWrappedModel();+ /**+ * Returns the unwrapped model's row for the given view row.+ * @param viewRow the row in the GUI+ * @return the row in the wrapped model's indexing+ */+ public int getModelRow(int viewRow);+/*** Allows this wrapping model to get update notifications directly from the filtering framework*/