Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7403 - Minor cleanup for translating filter rows

dragonmachere93f715c4368
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.java
index fd4be69d4f..820a1b3f48 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
@@ -345,7 +345,7 @@ class MemoryMapProvider extends ComponentProviderAdapter {
.helpLocation(new HelpLocation("MemoryMapPlugin", "Navigation"))
.description(HTMLUtilities.toHTML("Toggle <b>on</b> means to select the block" +
" that contains the current location"))
- .onAction(c -> followLocationChanges = toggleNavigateAction.isSelected())
+ .onAction(_ -> followLocationChanges = toggleNavigateAction.isSelected())
.buildAndInstallLocal(this);
}
@@ -436,6 +436,10 @@ class MemoryMapProvider extends ComponentProviderAdapter {
return table;
}
+ GTableFilterPanel<MemoryBlock> getTableFilterPanel() {
+ return filterPanel;
+ }
+
/**
* Update the memory map table. Something has changed.
*/
@@ -649,10 +653,12 @@ class MemoryMapProvider extends ComponentProviderAdapter {
setStatusText("Program is busy, try again later");
return;
}
- ArrayList<MemoryBlock> delBlocks = new ArrayList<>();
+
+ List<MemoryBlock> delBlocks = new ArrayList<>();
int delRows[] = table.getSelectedRows();
- for (int element : delRows) {
- MemoryBlock block = tableModel.getBlockAt(filterPanel.getModelRow(element));
+ for (int row : delRows) {
+ int modelRow = filterPanel.getModelRow(row);
+ MemoryBlock block = tableModel.getBlockAt(modelRow);
delBlocks.add(block);
}
table.clearSelection();
@@ -662,7 +668,7 @@ class MemoryMapProvider extends ComponentProviderAdapter {
/**
* Callback for deleting a block of memory
*/
- private void deleteBlock(ArrayList<MemoryBlock> blocks) {
+ private void deleteBlock(List<MemoryBlock> blocks) {
memManager.deleteBlocks(blocks);
}
@@ -768,10 +774,11 @@ class MemoryMapProvider extends ComponentProviderAdapter {
* Merge the selected blocks.
*/
private void mergeBlocks() {
- ArrayList<MemoryBlock> blocks = new ArrayList<>();
+ List<MemoryBlock> blocks = new ArrayList<>();
int rows[] = table.getSelectedRows();
- for (int element : rows) {
- MemoryBlock block = tableModel.getBlockAt(filterPanel.getModelRow(element));
+ for (int row : rows) {
+ int modelRow = filterPanel.getModelRow(row);
+ MemoryBlock block = tableModel.getBlockAt(modelRow);
blocks.add(block);
}
table.clearSelection();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider2Test.java
index 28b6e54f59..d94641a18f 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider2Test.java
@@ -19,7 +19,6 @@ import static org.junit.Assert.*;
import java.awt.Component;
import java.awt.Container;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.*;
import javax.swing.table.TableModel;
@@ -889,8 +888,9 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
public void testDeleteBlock() throws Exception {
Address minAddr = program.getMinAddress();
+
// select a row
- table.addRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Delete Block");
performAction(action, false);
@@ -900,15 +900,8 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
assertNotNull(d);
assertEquals("Delete Memory Block?", d.getTitle());
- JButton button = findButton(d.getComponent(), "Yes");
- assertNotNull(button);
-
- runSwingLater(() -> button.getActionListeners()[0].actionPerformed(null));
- Thread.sleep(500);
- while (!program.canLock()) {
- Thread.sleep(100);
- }
- Thread.sleep(500);
+ pressButtonByText(d, "Yes", false);
+ waitForCondition(() -> program.canLock());
program.flushEvents();
waitForSwing();
@@ -925,8 +918,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
@Test
public void testDeleteBlockAnswerNo() {
- // select a row
- table.addRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Delete Block");
performAction(action, false);
@@ -950,8 +942,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
assertEquals(1, table.getRowCount());
assertEquals(".data", table.getValueAt(0, MemoryMapModel.NAME));
- // select a row
- table.addRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Delete Block");
performAction(action, false);
@@ -964,10 +955,8 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
assertTrue("Wrong block in message: " + message, message.contains(".data"));
assertFalse("Wrong block in message: " + message, message.contains(".text"));
- JButton button = findButton(d.getComponent(), "No");
- assertNotNull(button);
+ pressButtonByText(d, "No");
- runSwing(() -> button.getActionListeners()[0].actionPerformed(null));
assertNotNull(memory.getBlock(".text"));
assertNotNull(memory.getBlock(".data"));
}
@@ -981,7 +970,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
});
int row = table.getModel().getRowCount() - 1;
- table.setRowSelectionInterval(row, row);
+ select(row, row);
DockingActionIf action = getAction(plugin, "Move Block");
performAction(action, false);
@@ -1013,17 +1002,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
Address startAddr = block.getStart();
Address endAddr = block.getEnd();
- // Select correct row
- AtomicInteger row = new AtomicInteger();
- runSwing(() -> {
- for (int i = 0; i < table.getRowCount(); i++) {
- if (".test".equals(table.getModel().getValueAt(i, 0))) {
- table.setRowSelectionInterval(i, i);
- row.set(i);
- break;
- }
- }
- });
+ int row = selectBlockRow(".test");
waitForSwing();
@@ -1075,18 +1054,14 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
assertTrue(okButton.isEnabled());
pressButton(okButton);
- // wait for thread to start
- Thread.sleep(1000);
-
- while (!program.canLock()) {
- Thread.sleep(100);
- }
+ waitForTasks();
program.flushEvents();
waitForSwing();
- assertEquals(".test", model.getValueAt(row.get(), MemoryMapModel.NAME));
- assertEquals(newStart.toString(), model.getValueAt(row.get(), MemoryMapModel.START));
- assertEquals(newEnd.toString(), model.getValueAt(row.get(), MemoryMapModel.END));
+
+ assertEquals(".test", model.getValueAt(row, MemoryMapModel.NAME));
+ assertEquals(newStart.toString(), model.getValueAt(row, MemoryMapModel.START));
+ assertEquals(newEnd.toString(), model.getValueAt(row, MemoryMapModel.END));
}
@Test
@@ -1097,7 +1072,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
false);
});
- table.setRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Move Block");
assertTrue(action.isEnabled());
@@ -1155,7 +1130,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
false);
});
- table.setRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Move Block");
assertTrue(action.isEnabled());
@@ -1213,7 +1188,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
false);
});
- table.setRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Move Block");
assertTrue(action.isEnabled());
@@ -1274,7 +1249,7 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
false);
});
- table.setRowSelectionInterval(0, 0);
+ select(0, 0);
DockingActionIf action = getAction(plugin, "Move Block");
assertTrue(action.isEnabled());
@@ -1324,6 +1299,22 @@ public class MemoryMapProvider2Test extends AbstractGhidraHeadedIntegrationTest
close(d);
}
+ private int selectBlockRow(String blockName) {
+ return runSwing(() -> {
+ for (int i = 0; i < table.getRowCount(); i++) {
+ if (blockName.equals(table.getModel().getValueAt(i, 0))) {
+ select(i, i);
+ return i;
+ }
+ }
+ return -1;
+ });
+ }
+
+ private void select(int row1, int row2) {
+ runSwing(() -> table.setRowSelectionInterval(row1, row2));
+ }
+
private void showProvider() {
DockingActionIf action = getAction(plugin, "Memory Map");
performAction(action, true);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider4Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider4Test.java
index 94e17e6aef..53ea0d459b 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider4Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/memory/MemoryMapProvider4Test.java
@@ -4,9 +4,9 @@
* 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.
@@ -39,6 +39,7 @@ import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
+import ghidra.program.model.mem.MemoryBlock;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.util.task.TaskMonitor;
@@ -108,7 +109,7 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
assertEquals("0000004f", model.getValueAt(3, MemoryMapModel.END));
// select rows 0 through 3
- table.setRowSelectionInterval(0, 3);
+ select(0, 3);
DockingActionIf action = getAction(plugin, "Merge Blocks");
assertTrue(action.isEnabled());
performAction(action, false);
@@ -139,8 +140,7 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
});
// filter so that only the middle two blocks are visible
- GTableFilterPanel<?> filterPanel =
- (GTableFilterPanel<?>) getInstanceField("filterPanel", provider);
+ GTableFilterPanel<MemoryBlock> filterPanel = provider.getTableFilterPanel();
runSwing(() -> filterPanel.setFilterText("mergeMe"));
waitForSwing();
assertEquals(2, table.getRowCount());
@@ -148,7 +148,7 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
assertEquals("mergeMe3", table.getValueAt(1, MemoryMapModel.NAME));
// select both visible rows
- table.setRowSelectionInterval(0, 1);
+ select(0, 1);
DockingActionIf action = getAction(plugin, "Merge Blocks");
assertTrue(action.isEnabled());
performAction(action, false);
@@ -183,8 +183,7 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
// select rows 0 and 2
// blocks are not contiguous
// verify an error message is displayed
- table.setRowSelectionInterval(0, 0);
- table.addRowSelectionInterval(2, 2);
+ selectDiscontiguous(0, 2);
DockingActionIf action = getAction(plugin, "Merge Blocks");
assertTrue(action.isEnabled());
performAction(action, false);
@@ -204,7 +203,7 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
});
// select rows 0 and 1
- table.setRowSelectionInterval(0, 1);
+ select(0, 1);
DockingActionIf action = getAction(plugin, "Merge Blocks");
assertTrue(action.isEnabled());
@@ -249,7 +248,7 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
});
// select rows 0 and 1
- table.setRowSelectionInterval(0, 1);
+ select(0, 1);
DockingActionIf action = getAction(plugin, "Merge Blocks");
assertTrue(action.isEnabled());
@@ -265,6 +264,21 @@ public class MemoryMapProvider4Test extends AbstractGhidraHeadedIntegrationTest
assertEquals("0000004f", model.getValueAt(0, MemoryMapModel.END));
}
+ private void select(int row1, int row2) {
+ runSwing(() -> table.setRowSelectionInterval(row1, row2));
+ }
+
+ private void selectDiscontiguous(int... rows) {
+ runSwing(() -> {
+
+ table.clearSelection();
+ for (int i : rows) {
+ table.addRowSelectionInterval(i, i);
+ }
+
+ });
+ }
+
private void showProvider() {
DockingActionIf action = getAction(plugin, "Memory Map");
performAction(action, true);
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java
index d2794d98ce..e57f99c96d 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java
@@ -27,9 +27,7 @@ import docking.widgets.FindDialogResultsProvider;
import docking.widgets.SearchLocation;
import docking.widgets.dialogs.InputDialog;
import docking.widgets.fieldpanel.support.FieldLocation;
-import docking.widgets.table.GTable;
-import docking.widgets.table.GTableFilterPanel;
-import docking.widgets.table.RowObjectFilterModel;
+import docking.widgets.table.*;
import ghidra.app.decompiler.ClangToken;
import ghidra.app.decompiler.component.DecompilerFindDialog;
import ghidra.app.decompiler.component.DecompilerPanel;
@@ -305,12 +303,14 @@ public class DecompilerFindDialogTest extends AbstractDecompilerTest {
GTable table = getResultsTable();
assertEquals(10, table.getRowCount());
- SearchLocation firstUnfiltered = getRowObject(table, 0);
+ DecompilerSearchLocation firstUnfiltered =
+ (DecompilerSearchLocation) getRowObject(table, 0);
+ assertEquals("undefined4 *puVar3;", firstUnfiltered.getTextLine());
// filter so that the visible rows are not the first rows of the unfiltered list
setFilterText("puVar5");
int rowCount = table.getRowCount();
- assertTrue(rowCount > 0 && rowCount < 10);
+ assertEquals(4, rowCount);
assertNotEquals(firstUnfiltered, getRowObject(table, 0));
// click the visible rows and verify the cursor location
@@ -334,7 +334,7 @@ public class DecompilerFindDialogTest extends AbstractDecompilerTest {
setFilterText("puVar5");
int rowCount = table.getRowCount();
- assertTrue(rowCount > 1 && rowCount < 10);
+ assertEquals(4, rowCount);
// remove the last visible row
int lastRow = rowCount - 1;
@@ -343,9 +343,7 @@ public class DecompilerFindDialogTest extends AbstractDecompilerTest {
FindDialogResultsProvider tableProvider =
waitForComponentProvider(FindDialogResultsProvider.class);
- DockingActionIf removeAction = getLocalAction(tableProvider, "Remove Items");
- performAction(removeAction, tableProvider, true);
- waitForSwing();
+ pressDelete(tableProvider);
List<SearchLocation> remaining = tableProvider.getResults();
assertEquals(9, remaining.size());
@@ -359,6 +357,12 @@ public class DecompilerFindDialogTest extends AbstractDecompilerTest {
//==================================================================================================
// Private Methods
//==================================================================================================
+ private void pressDelete(FindDialogResultsProvider tableProvider) {
+
+ DockingActionIf removeAction = getLocalAction(tableProvider, "Remove Items");
+ performAction(removeAction, tableProvider, true);
+ waitForSwing();
+ }
private void clickAndVerify(int row, GTable table, List<DecompilerSearchLocation> results) {