Ghidra is a software reverse engineering (SRE) framework
GT-2872 - Search - updated the search dialog to show itself during a 'repeat' search if the task monitor is needed; updated the progress of the memory search to show progress
dragonmacher96788aa7fcf0
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcher.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcher.javaindex ea1c01a947..8e1aa42ef6 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcher.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcher.java@@ -15,6 +15,14 @@*/package ghidra.app.plugin.core.searchtext;+import java.math.BigInteger;+import java.util.*;+import java.util.regex.Matcher;+import java.util.regex.Pattern;++import docking.widgets.fieldpanel.Layout;+import docking.widgets.fieldpanel.support.FieldLocation;+import docking.widgets.fieldpanel.support.RowColLocation;import ghidra.app.plugin.core.searchtext.iterators.*;import ghidra.app.services.CodeViewerService;import ghidra.app.util.viewer.field.*;@@ -29,15 +37,6 @@ import ghidra.util.Msg;import ghidra.util.UserSearchUtils;import ghidra.util.task.TaskMonitor;-import java.math.BigInteger;-import java.util.*;-import java.util.regex.Matcher;-import java.util.regex.Pattern;--import docking.widgets.fieldpanel.Layout;-import docking.widgets.fieldpanel.support.FieldLocation;-import docking.widgets.fieldpanel.support.RowColLocation;-/*** This class attempts to search for text as it is rendered on the screen. This in in* contrast to the Program Database Searcher which searches the database. This is@@ -104,7 +103,7 @@ class ListingDisplaySearcher implements Searcher {searchPattern =UserSearchUtils.createSearchPattern(options.getText(), options.isCaseSensitive());- locationList = new ArrayList<ProgramLocation>();+ locationList = new ArrayList<>();locationIterator = locationList.listIterator();CodeViewerService service = tool.getService(CodeViewerService.class);@@ -152,7 +151,7 @@ class ListingDisplaySearcher implements Searcher {// with a defined code unit. See the history for the original code. See the// header for more info.//- List<AddressIterator> iterators = new ArrayList<AddressIterator>();+ List<AddressIterator> iterators = new ArrayList<>();Listing listing = program.getListing();@@ -169,9 +168,8 @@ class ListingDisplaySearcher implements Searcher {iterators.add(listing.getCommentAddressIterator(searchAddresses, options.isForward()));}if (options.searchLabels() || all) {- SymbolIterator labels =- program.getSymbolTable().getPrimarySymbolIterator(searchAddresses,- options.isForward());+ SymbolIterator labels = program.getSymbolTable().getPrimarySymbolIterator(+ searchAddresses, options.isForward());iterators.add(new LabelSearchAddressIterator(labels));}return iterators.toArray(new AddressIterator[iterators.size()]);@@ -229,8 +227,8 @@ class ListingDisplaySearcher implements Searcher {// if the tool is busy disassembling or if the program got closed,// ignore the exception.if (tool.isExecutingCommand()) {- tool.setStatusInfo("Search failed: try search when tool is not "- + "executing commands that may change the program");+ tool.setStatusInfo("Search failed: try search when tool is not " ++ "executing commands that may change the program");}else if (!program.isClosed() && program.getCurrentTransaction() != null) {tool.setStatusInfo("Search failed: try search when program is not being changed");@@ -264,6 +262,7 @@ class ListingDisplaySearcher implements Searcher {locationList.size() == 0) {currentAddress = addressIterator.next();+ monitor.setMessage("Checking address " + currentAddress);if (!options.searchAllFields()) {currentCodeUnit = listing.getCodeUnitContaining(currentAddress);}@@ -276,8 +275,10 @@ class ListingDisplaySearcher implements Searcher {(!options.isForward() && currentAddress.compareTo(startAddress) > 0)) {continue;}- if ((options.isForward() && currentAddress.compareTo(searchAddresses.getMaxAddress()) > 0) ||- (!options.isForward() && currentAddress.compareTo(searchAddresses.getMinAddress()) < 0)) {+ if ((options.isForward() &&+ currentAddress.compareTo(searchAddresses.getMaxAddress()) > 0) ||+ (!options.isForward() &&+ currentAddress.compareTo(searchAddresses.getMinAddress()) < 0)) {return;}if (!searchAddresses.contains(currentAddress)) {@@ -317,7 +318,8 @@ class ListingDisplaySearcher implements Searcher {}private void searchForward() {- for (int i = currentFieldIndex; i < currentLayout.getNumFields(); i++, currentFieldIndex++) {+ for (int i =+ currentFieldIndex; i < currentLayout.getNumFields(); i++, currentFieldIndex++) {int matchingFieldCount = findLocations(i);if (matchingFieldCount != 0) {currentFieldIndex += matchingFieldCount;@@ -543,7 +545,8 @@ class ListingDisplaySearcher implements Searcher {adjustIterator();}- private MnemonicText generateMnemonicSearchText(ListingField mnemonicField, ListingField opField) {+ private MnemonicText generateMnemonicSearchText(ListingField mnemonicField,+ ListingField opField) {String mnemonic = mnemonicField.getText();String operands = opField != null ? opField.getText() : "";@@ -600,7 +603,8 @@ class ListingDisplaySearcher implements Searcher {// note: the program database search generates a location with sub op index as -1,// so treat this as the same location if the sub op index is -1;// this happens when transitioning from a database search to listing display search.- return (opStartLoc.getSubOperandIndex() < 0 && opStartLoc.getOperandIndex() == opLoc.getOperandIndex());+ return (opStartLoc.getSubOperandIndex() < 0 &&+ opStartLoc.getOperandIndex() == opLoc.getOperandIndex());}//==================================================================================================diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextDialog.javaindex e1eeb628c6..40901068f6 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextDialog.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextDialog.java@@ -146,27 +146,19 @@ class SearchTextDialog extends DialogComponentProvider {}}- /* (non Javadoc)- * @see ghidra.util.bean.GhidraDialog#executeProgressTask(ghidra.util.task.Task, int)- */+ // overridden to increase visibility@Overrideprotected void executeProgressTask(Task task, int delay) {super.executeProgressTask(task, delay);}- /*- * (non Javadoc)- * @see ghidra.util.bean.GhidraDialog#getTaskMonitorComponent()- */+ // overridden to increase visibility@Overrideprotected TaskMonitorComponent getTaskMonitorComponent() {return super.getTaskMonitorComponent();}- /*- * (non Javadoc)- * @see ghidra.util.bean.GhidraDialog#getTaskScheduler()- */+ // overridden to increase visibility@Overrideprotected TaskScheduler getTaskScheduler() {return super.getTaskScheduler();@@ -178,9 +170,6 @@ class SearchTextDialog extends DialogComponentProvider {previousButton.setEnabled(!isBusy && searchEnabled);}- /**- * Enable/disable the search button.- */void setSearchEnabled(boolean enabled) {searchEnabled = enabled;updateSearchButtonsEnablement();@@ -195,14 +184,10 @@ class SearchTextDialog extends DialogComponentProvider {return searchSelectionCB.isSelected();}- ///////////////////////////////////////////////////////////////////private void setMessage(String msg) {super.setStatusText(msg);}- /**- * Create the main panel.- */private JPanel createMainPanel() {JPanel mainPanel = new JPanel();mainPanel.setLayout(new BorderLayout(10, 0));@@ -211,9 +196,6 @@ class SearchTextDialog extends DialogComponentProvider {return mainPanel;}- /**- * Create the top panel that has the text field.- */private JPanel createSearchPanel() {JPanel panel = new JPanel();panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 10, 4));@@ -252,9 +234,8 @@ class SearchTextDialog extends DialogComponentProvider {return panel;}- /**- * Create the inner panel that has the direction and the- * case sensitive panel.+ /*+ * Create the inner panel that has the direction and the case sensitive panel*/private JPanel createDetailsPanel() {JPanel detailsPanel = new JPanel(new BorderLayout());@@ -275,7 +256,6 @@ class SearchTextDialog extends DialogComponentProvider {private JPanel createRightPanel() {JPanel panel = new JPanel(new GridLayout(0, 1, 10, 10));-// JPanel panel = new JPanel(new VerticalLayout(5));panel.add(createDirectionPanel());panel.add(createOptionsPanel());return panel;@@ -296,11 +276,6 @@ class SearchTextDialog extends DialogComponentProvider {return panel;}- /**- * Create the options panel.- *- * @return JPanel- */private JPanel createFieldOptionsPanel() {JPanel optionsPanel = new JPanel();BoxLayout bl = new BoxLayout(optionsPanel, BoxLayout.Y_AXIS);diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin.javaindex aca3ea24c8..ae5899b2ae 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin.java@@ -277,11 +277,6 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeListsearchDialog.executeProgressTask(task, 500);}- /**- * Search for all matches.- *- * @param queryString string to use in the label on the query dialog- */void searchAll(SearchOptions options) {ProgramSelection selection = navigatable.getSelection();@@ -362,6 +357,7 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeList}void searched() {+ tool.contextChanged(null);searchedOnce = true;}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.javaindex dc8391c5ed..4c608b84be 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.java@@ -28,7 +28,6 @@ import ghidra.program.model.listing.Program;import ghidra.program.util.ProgramLocation;import ghidra.util.UserSearchUtils;import ghidra.util.task.TaskMonitor;-import ghidra.util.task.TaskMonitorAdapter;/*** This class combines multiple field searchers to present a simple searcher interface for users of@@ -56,26 +55,26 @@ import ghidra.util.task.TaskMonitorAdapter;*/public class ProgramDatabaseSearcher implements Searcher {- private List<ProgramDatabaseFieldSearcher> searchers =- new ArrayList<ProgramDatabaseFieldSearcher>();+ private List<ProgramDatabaseFieldSearcher> searchers = new ArrayList<>();private Address currentAddress;private boolean isForward;private SearchOptions searchOptions;private TaskMonitor monitor;public ProgramDatabaseSearcher(ServiceProvider serviceProvider, Program program,- ProgramLocation startLoc, AddressSetView set, SearchOptions options, TaskMonitor monitor) {+ ProgramLocation startLoc, AddressSetView set, SearchOptions options,+ TaskMonitor monitor) {this.searchOptions = options;- this.monitor = monitor != null ? monitor : TaskMonitorAdapter.DUMMY_MONITOR;+ this.monitor = monitor != null ? monitor : TaskMonitor.DUMMY;this.isForward = options.isForward();if (startLoc == null && set == null) {- startLoc =- new ProgramLocation(program, isForward ? program.getMinAddress()- : program.getMaxAddress());+ startLoc = new ProgramLocation(program,+ isForward ? program.getMinAddress() : program.getMaxAddress());}+initialize(serviceProvider, program, startLoc, set, options);currentAddress = findNextSignificantAddress();- this.monitor.setIndeterminate(true);+ monitor.initialize(set.getNumAddresses());}@Override@@ -85,6 +84,7 @@ public class ProgramDatabaseSearcher implements Searcher {orderedSearchers = new ArrayList<>(searchers);Collections.reverse(orderedSearchers);}+while (currentAddress != null) {monitor.setMessage("Checking address " + currentAddress);for (ProgramDatabaseFieldSearcher searcher : orderedSearchers) {@@ -92,11 +92,23 @@ public class ProgramDatabaseSearcher implements Searcher {return searcher.getMatch();}}++ Address lastAddress = currentAddress;currentAddress = findNextSignificantAddress();+ updateProgress(lastAddress, currentAddress);}return null;}+ private void updateProgress(Address lastAddress, Address newAddress) {+ if (newAddress == null) {+ return; // finished+ }++ int diff = (int) Math.abs(newAddress.subtract(lastAddress));+ monitor.incrementProgress(diff);+ }+@Overridepublic SearchOptions getSearchOptions() {return searchOptions;@@ -114,9 +126,8 @@ public class ProgramDatabaseSearcher implements Searcher {return null;}Address nextAddressToCheck = searcher.getNextSignificantAddress(currentAddress);- nextAddress =- isForward ? getMin(nextAddress, nextAddressToCheck) : getMax(nextAddress,- nextAddressToCheck);+ nextAddress = isForward ? getMin(nextAddress, nextAddressToCheck)+ : getMax(nextAddress, nextAddressToCheck);}return nextAddress;}@@ -142,8 +153,8 @@ public class ProgramDatabaseSearcher implements Searcher {return address1.compareTo(address2) > 0 ? address1 : address2;}- private void initialize(ServiceProvider serviceProvider, Program program,- ProgramLocation start, AddressSetView view, SearchOptions options) {+ private void initialize(ServiceProvider serviceProvider, Program program, ProgramLocation start,+ AddressSetView view, SearchOptions options) {searchOptions = options;boolean forward = options.isForward();@@ -159,20 +170,21 @@ public class ProgramDatabaseSearcher implements Searcher {pattern, CodeUnit.PLATE_COMMENT));}if (options.searchFunctions()) {- searchers.add(new FunctionFieldSearcher(program, adjustedStart, trimmedSet, forward,- pattern));+ searchers.add(+ new FunctionFieldSearcher(program, adjustedStart, trimmedSet, forward, pattern));}if (options.searchComments()) {searchers.add(new CommentFieldSearcher(program, adjustedStart, trimmedSet, forward,pattern, CodeUnit.PRE_COMMENT));}if (options.searchLabels()) {- searchers.add(new LabelFieldSearcher(program, adjustedStart, trimmedSet, forward,- pattern));+ searchers.add(+ new LabelFieldSearcher(program, adjustedStart, trimmedSet, forward, pattern));}if (options.searchBothDataMnemonicsAndOperands()) {- searchers.add(DataMnemonicOperandFieldSearcher.createDataMnemonicAndOperandFieldSearcher(- program, adjustedStart, trimmedSet, forward, pattern, format));+ searchers.add(+ DataMnemonicOperandFieldSearcher.createDataMnemonicAndOperandFieldSearcher(program,+ adjustedStart, trimmedSet, forward, pattern, format));}if (options.searchOnlyDataMnemonics()) {searchers.add(DataMnemonicOperandFieldSearcher.createDataMnemonicOnlyFieldSearcher(@@ -183,16 +195,19 @@ public class ProgramDatabaseSearcher implements Searcher {program, adjustedStart, trimmedSet, forward, pattern, format));}if (options.searchBothInstructionMnemonicAndOperands()) {- searchers.add(InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher(- program, adjustedStart, trimmedSet, forward, pattern, format));+ searchers.add(+ InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher(+ program, adjustedStart, trimmedSet, forward, pattern, format));}if (options.searchOnlyInstructionMnemonics()) {- searchers.add(InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicOnlyFieldSearcher(- program, adjustedStart, trimmedSet, forward, pattern, format));+ searchers.add(+ InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicOnlyFieldSearcher(+ program, adjustedStart, trimmedSet, forward, pattern, format));}if (options.searchOnlyInstructionOperands()) {- searchers.add(InstructionMnemonicOperandFieldSearcher.createInstructionOperandOnlyFieldSearcher(- program, adjustedStart, trimmedSet, forward, pattern, format));+ searchers.add(+ InstructionMnemonicOperandFieldSearcher.createInstructionOperandOnlyFieldSearcher(+ program, adjustedStart, trimmedSet, forward, pattern, format));}if (options.searchComments()) {searchers.add(new CommentFieldSearcher(program, adjustedStart, trimmedSet, forward,@@ -229,8 +244,8 @@ public class ProgramDatabaseSearcher implements Searcher {// minimum address of the code unit. Otherwise the FieldSearcher will// throw an IllegalArgumentException.if (!adjustedStart.getAddress().equals(maxAddress)) {- trimmedSet =- trimAddressSet(program, trimmedSet, adjustedStart.getAddress(), forward);+ trimmedSet = trimAddressSet(program, trimmedSet, adjustedStart.getAddress(),+ forward);}}}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java b/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.javaindex 672186881a..70f06fca41 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java@@ -72,7 +72,7 @@ public class DialogComponentProviderprivate TaskScheduler taskScheduler;private TaskMonitorComponent taskMonitorComponent;- private static KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);+ private static final KeyStroke ESC_KEYSTROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);private CardLayout progressCardLayout;private JButton defaultButton;@@ -180,7 +180,7 @@ public class DialogComponentProvider}};- KeyBindingUtils.registerAction(rootPanel, escKeyStroke, escAction,+ KeyBindingUtils.registerAction(rootPanel, ESC_KEYSTROKE, escAction,JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);}@@ -642,18 +642,6 @@ public class DialogComponentProvider}}- private void doSetSubStatusText(String text, MessageType type, boolean alert) {-- SystemUtilities.assertThisIsTheSwingThread(- "Setting text must be performed on the Swing thread");-- updateStatusToolTip();-- if (alert) {- alertMessage();- }- }-/*** Signals for this dialog to visually draw the user's attention to the status text*/@@ -765,6 +753,13 @@ public class DialogComponentProvider}private void showProgressBar(String localTitle, boolean hasProgress, boolean canCancel) {++ if (!isVisible()) {+ // It doesn't make any sense to show the task monitor when the dialog is not+ // visible, so show the dialog+ DockingWindowManager.showDialog(getParent(), this);+ }+taskMonitorComponent.setTaskName(localTitle);taskMonitorComponent.showProgress(hasProgress);taskMonitorComponent.setCancelButtonVisibility(canCancel);@@ -1065,6 +1060,13 @@ public class DialogComponentProviderreturn dialog;}+ private Component getParent() {+ if (dialog == null) {+ return null;+ }+ return dialog.getParent();+ }+public boolean isVisible() {return ((dialog != null) && dialog.isVisible());}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DockingTool.java b/Ghidra/Framework/Docking/src/main/java/docking/DockingTool.javaindex ff6c60d77b..bc8d59b66a 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/DockingTool.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/DockingTool.java@@ -28,11 +28,13 @@ public interface DockingTool {/*** Returns a combination of the tool name and the instance name of the form* tool name(instance name), e.g., SomeTool(2)+ * @return the tool name*/public String getName();/**- * Returns true if tool is visible.+ * Returns true if tool is visible+ * @return true if tool is visible*/public boolean isVisible();@@ -52,7 +54,8 @@ public interface DockingTool {public void toFront();/**- * Get the icon that the tool is using.+ * Get the icon that the tool is using+ * @return the icon that the tool is using*/public ImageIcon getIcon();@@ -64,8 +67,8 @@ public interface DockingTool {public void addComponentProvider(ComponentProvider componentProvider, boolean show);/**- * Removes the given ComponentProvider from the tool.- * @param componentProviderAdapter the provider to remove from the tool.+ * Removes the given ComponentProvider from the tool+ * @param componentProvider the provider to remove from the tool*/public void removeComponentProvider(ComponentProvider componentProvider);@@ -191,10 +194,12 @@ public interface DockingTool {public void updateTitle(ComponentProvider componentProvider);/**- * Signals to the tool that the provider's context has changed. This lets toolbar actions update- * enablement based on current context.+ * Signals to the tool that the provider's context has changed. This lets toolbar and+ * menu actions update enablement based on current context.+ *+ * <p>Pass <code>null</code> to signal that the entire tool's context has changed*- * @param provider the provider whose context changed.+ * @param provider the provider whose context changed; null to signal the tool's context*/public void contextChanged(ComponentProvider provider);@@ -207,6 +212,8 @@ public interface DockingTool {/*** Get the options for the given category name; if no options exist with* the given name, then one is created.+ * @param categoryName the category name+ * @return the options*/public ToolOptions getOptions(String categoryName);@@ -217,7 +224,8 @@ public interface DockingTool {public void setConfigChanged(boolean changed);/**- * Return true if the tool's configuration has changed.+ * Return true if the tool's configuration has changed+ * @return true if the tool's configuration has changed*/public boolean hasConfigChanged();