Ghidra is a software reverse engineering (SRE) framework
GP-7305 - Fixed GTabl's 'copy column' action to copy WYSIWYG
dragonmacherc5270577a1f5
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 e620ee86a2..10632ea896 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@@ -810,7 +810,7 @@ class MemoryMapProvider extends ComponentProviderAdapter {}@Override- protected <T> SelectionManager createSelectionManager() {+ protected SelectionManager createSelectionManager() {return null;}}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.javaindex 79b02d1d6c..5aa74d96da 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java@@ -271,25 +271,15 @@ public class GTable extends JTable {selectionModel.setSelectionMode(selectionMode);}- protected <T> SelectionManager createSelectionManager() {- RowObjectTableModel<Object> rowModel = getRowObjectTableModel();+ protected SelectionManager createSelectionManager() {+ RowObjectTableModel<?> rowModel = getRowObjectTableModel();if (rowModel != null) {return new RowObjectSelectionManager<>(this, rowModel);}return null;}- /**- * @param <T> the type of the row object- * @return the model- * @implNoteThe The cast to {@code RowObjectTableModel<T>} is safe, since we are create a new- * {@link SelectionManager} of an arbitrary type T defined here. So, T doesn't- * really exist and therefore the cast isn't really casting to anything. The- * {@link SelectionManager} will take on the type of the given model. The T is just- * there on the {@link SelectionManager} to make its internal methods consistent.- */- @SuppressWarnings("unchecked")- private <T> RowObjectTableModel<T> getRowObjectTableModel() {+ private RowObjectTableModel<?> getRowObjectTableModel() {if (getModel() instanceof RowObjectTableModel model) {return model;}@@ -1242,37 +1232,14 @@ public class GTable extends JTable {* makes the data almost unreadable/unusable.*/@Override- public Object getValueAt(int row, int column) {+ public Object getValueAt(int viewRow, int viewColumn) {if (!copying) {- return super.getValueAt(row, column);- }-- Object value = getCellValue(row, column);- Object updated = maybeConvertValue(value);- return updated;- }-- private Object getCellValue(int row, int viewColumn) {- RowObjectTableModel<Object> rowModel = getRowObjectTableModel();- if (rowModel == null) {- Object value = super.getValueAt(row, viewColumn);- return maybeConvertValue(value);+ return super.getValueAt(viewRow, viewColumn);}- Object rowObject = rowModel.getRowObject(row);+ int modelRow = convertRowIndexToModel(viewRow);int modelColumn = convertColumnIndexToModel(viewColumn);- String stringValue = TableUtils.getTableCellStringValue(rowModel, rowObject, modelColumn);- return maybeConvertValue(stringValue);- }-- private Object maybeConvertValue(Object value) {- if (value == null) {- return null;- }-- String asString = value.toString();- String converted = HTMLUtilities.fromHTML(asString);- return converted;+ return TableUtils.getTableCellStringValue(this, modelRow, modelColumn);}/**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 689ce5c4bb..602ef2809d 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@@ -15,6 +15,7 @@*/package docking.widgets.table;+import java.awt.Component;import java.awt.Graphics;import java.math.BigDecimal;import java.time.Duration;@@ -29,6 +30,7 @@ import org.jdesktop.animation.timing.Animator;import docking.util.AnimationPainter;import docking.util.AnimationRunner;import ghidra.docking.settings.Settings;+import ghidra.util.HTMLUtilities;import ghidra.util.bean.GGlassPane;import ghidra.util.table.column.GColumnRenderer;import ghidra.util.table.column.GColumnRenderer.ColumnConstraintFilterMode;@@ -97,23 +99,85 @@ public class TableUtils {selectionModel.setValueIsAdjusting(false);}+ /**+ * Uses the given row-based table model, row 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.+ * As such, if the value is HTML, it will be converted to non-HTML.+ *+ * @param <ROW_OBJECT> The model's row object type+ * @param table the table+ * @param modelRow the model's row index+ * @param modelColumn the model's column index+ * @return the string value; null if no value can be fabricated+ */+ public static <ROW_OBJECT> String getTableCellStringValue(JTable table, int modelRow,+ int modelColumn) {++ TableModel model = table.getModel();+ if (model instanceof RowObjectTableModel) {+ RowObjectFilterModel<?> rowModel = (RowObjectFilterModel<?>) model;+ return getTableCellStringValue(rowModel, modelRow, modelColumn);+ }++ Object value = model.getValueAt(modelRow, modelColumn);+ int viewRow = table.convertColumnIndexToView(modelRow);+ int viewColumn = table.convertRowIndexToView(modelColumn);+ TableCellRenderer renderer = table.getCellRenderer(modelRow, modelColumn);+ Component c =+ renderer.getTableCellRendererComponent(table, value, false, false, viewRow, viewColumn);+ if (c instanceof JLabel label) {+ String text = label.getText();+ return convertFromHtml(text);+ }++ return null;+ }++ private static <ROW_OBJECT> String getTableCellStringValue(+ RowObjectTableModel<ROW_OBJECT> model, int modelRow, int modelColumn) {++ ROW_OBJECT rowObject = model.getRowObject(modelRow);+ return getTableCellStringValue(model, rowObject, modelColumn);+ }+/*** 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.+ * <P>+ * This is used to provide a means for filtering on the text that is displayed to the user.+ * As such, if the value is HTML, it will be converted to non-HTML.** @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 rowObject the row object+ * @param modelColumn the model's column index* @return the string value; null if no value can be fabricated*/public static <ROW_OBJECT> String getTableCellStringValue(RowObjectTableModel<ROW_OBJECT> model,- ROW_OBJECT rowObject, int column) {+ ROW_OBJECT rowObject, int modelColumn) {++ String rawString = doGetTableCellStringValue(model, rowObject, modelColumn);+ return convertFromHtml(rawString);+ }++ private static String convertFromHtml(Object value) {+ if (value == null) {+ return null;+ }++ String asString = value.toString();+ return HTMLUtilities.fromHTML(asString);+ }++ private static <ROW_OBJECT> String doGetTableCellStringValue(+ RowObjectTableModel<ROW_OBJECT> model, ROW_OBJECT rowObject, int modelColumn) {// note: this call can be slow when columns dynamically calculate values from the database- Object value = model.getColumnValueForRow(rowObject, column);+ Object value = model.getColumnValueForRow(rowObject, modelColumn);if (value == null) {return null;}@@ -130,7 +194,7 @@ public class TableUtils {*/// 1)- String renderedString = getRenderedColumnValue(model, value, column);+ String renderedString = getRenderedColumnValue(model, value, modelColumn);if (renderedString != null) {return renderedString;}@@ -138,7 +202,7 @@ public class TableUtils {// 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();+ return value.toString();}// 3