Ghidra is a software reverse engineering (SRE) framework
GP-1676 - Fixed incorrect tool option usage
dragonmacherdd6448d06d62
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserSelectionPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserSelectionPlugin.javaindex cb7893a65f..7d84e598fb 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserSelectionPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserSelectionPlugin.java@@ -56,20 +56,10 @@ import resources.ResourceManager;public class CodeBrowserSelectionPlugin extends Plugin {private static final String SELECTION_LIMIT_OPTION_NAME = "Table From Selection Limit";- private static final int DEFAULT_TABLE_LIMIT = 20000;public CodeBrowserSelectionPlugin(PluginTool tool) {super(tool);createActions();- registerOptions();- }-- private void registerOptions() {- ToolOptions toolOptions = tool.getOptions(ToolConstants.TOOL_OPTIONS);- toolOptions.registerOption(SELECTION_LIMIT_OPTION_NAME, DEFAULT_TABLE_LIMIT,- new HelpLocation("CodeBrowserPlugin", "Selection_Table"),- "The maximum number of code units to include when creating a table from " +- "a selection in the Listing");}private void createActions() {@@ -122,14 +112,14 @@ public class CodeBrowserSelectionPlugin extends Plugin {Msg.showWarn(this, null, "No Table Service", "Please add the TableServicePlugin.");return;}+Program program = componentProvider.getProgram();Listing listing = program.getListing();-ProgramSelection selection = componentProvider.getSelection();CodeUnitIterator codeUnits = listing.getCodeUnits(selection, true);if (!codeUnits.hasNext()) {tool.setStatusInfo(- "Unable to create table from selection: no " + "code units in selection");+ "Unable to create table from selection: no code units in selection");return;}@@ -147,7 +137,6 @@ public class CodeBrowserSelectionPlugin extends Plugin {CodeUnitFromSelectionTableModelLoader loader =new CodeUnitFromSelectionTableModelLoader(iterator, selection);-return new CustomLoadingAddressTableModel(" - from " + selection.getMinAddress(), tool,program, loader, null, true);}@@ -168,8 +157,8 @@ public class CodeBrowserSelectionPlugin extends Plugin {throws CancelledException {ToolOptions options = tool.getOptions(ToolConstants.TOOL_OPTIONS);- int resultsLimit =- options.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_TABLE_LIMIT);+ int resultsLimit = options.getInt(GhidraOptions.OPTION_SEARCH_LIMIT,+ PluginConstants.DEFAULT_SEARCH_LIMIT);long size = selection.getNumAddresses();monitor.initialize(size);diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToServicePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToServicePlugin.javaindex c8349428b4..34276ea156 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToServicePlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/gotoquery/GoToServicePlugin.java@@ -53,20 +53,27 @@ import ghidra.program.util.ProgramSelection;)//@formatter:onpublic final class GoToServicePlugin extends ProgramPlugin {+private GoToServiceImpl gotoService;private boolean disposed;/*** Creates a new instance of the <CODE>GoToServicePlugin</CODE>- * @param plugintool the tool+ * @param tool the tool*/- public GoToServicePlugin(PluginTool plugintool) {- super(plugintool, true, true);+ public GoToServicePlugin(PluginTool tool) {+ super(tool, true, true);++ Options opt = tool.getOptions(PluginConstants.SEARCH_OPTION_NAME);++ // we register this option here, since the other search plugins all depend on this service+ opt.registerOption(GhidraOptions.OPTION_SEARCH_LIMIT,+ PluginConstants.DEFAULT_SEARCH_LIMIT, null,+ "The maximum number of search results.");gotoService = new GoToServiceImpl(this, new DefaultNavigatable());registerServiceProvided(GoToService.class, gotoService);-}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPlugin.javaindex ab6e0839f3..f7d3954dc4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPlugin.java@@ -49,40 +49,19 @@ import ghidra.util.bean.opteditor.OptionsVetoException;//@formatter:onpublic class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListener {- //////////////////////////////////////////////////////////////////////- // //- // Instance fields //- // //- //////////////////////////////////////////////////////////////////////-- private GoToAddressLabelDialog goToDialog;- private DockingAction action;- // configurable properties- private int maximumGotoEntries;- private boolean cStyleInput;- private boolean goToMemory;-- //////////////////////////////////////////////////////////////////////- // //- // Class fields and methods //- // //- //////////////////////////////////////////////////////////////////////-private static final int DEFAULT_MAX_GOTO_ENTRIES = 10;private static final boolean DEFAULT_C_STYLE = false;- /**- * This option controls the Go To dialog's feature that remembers the last successful- * go to entry.- */+ // remembers the last successful 'go to' entryprivate static final String GO_TO_MEMORY = "Goto Dialog Memory";private static final boolean DEFAULT_MEMORY = true;- //////////////////////////////////////////////////////////////////////- // //- // Constructor //- // //- //////////////////////////////////////////////////////////////////////+ private GoToAddressLabelDialog goToDialog;+ private DockingAction action;++ private int maximumGotoEntries;+ private boolean cStyleInput;+ private boolean goToMemory;public GoToAddressLabelPlugin(PluginTool pluginTool) {super(pluginTool);@@ -120,17 +99,11 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListeGoToService gotoService = tool.getService(GoToService.class);goToDialog = new GoToAddressLabelDialog(gotoService, this);maximumGotoEntries = DEFAULT_MAX_GOTO_ENTRIES;- getOptions();+ initOptions();tool.addAction(action);}- //////////////////////////////////////////////////////////////////////- // //- // Configurable properties- // //- //////////////////////////////////////////////////////////////////////-public final int getMaximumGotoEntries() {return maximumGotoEntries;}@@ -145,16 +118,6 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListegoToDialog.writeConfigState(saveState);}- /**- * Notification that an option changed.- *- * @param options options object containing the property that changed- * @param group name of the group to which this option is associated,- * null if not associated with any group- * @param opName name of option that changed- * @param oldValue old value of the option- * @param newValue new value of the option- */@Overridepublic void optionsChanged(ToolOptions options, String opName, Object oldValue,Object newValue) {@@ -177,12 +140,6 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe}}- //////////////////////////////////////////////////////////////////////- // //- // Overridden Plugin Methods //- // //- //////////////////////////////////////////////////////////////////////-@Overridepublic void dispose() {ToolOptions options = tool.getOptions(ToolConstants.TOOL_OPTIONS);@@ -191,9 +148,8 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListesuper.dispose();}- private void getOptions() {+ private void initOptions() {ToolOptions opt = tool.getOptions(ToolConstants.TOOL_OPTIONS);- // descriptionsopt.registerOption(GhidraOptions.OPTION_NUMERIC_FORMATTING, DEFAULT_C_STYLE, null,"Interpret value entered in the Go To dialog as either hex, " +"octal, or binary number.");@@ -206,7 +162,6 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe"successful go to input in the combo box of the Go " +"To dialog and will select the " + "value for easy paste replacement.");- // optionsmaximumGotoEntries =opt.getInt(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES, DEFAULT_MAX_GOTO_ENTRIES);diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.javaindex 17a9b0a500..698be48843 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java@@ -93,7 +93,6 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,private MemSearchDialog searchDialog;private GoToService goToService;private int searchLimit;- private static int DEFAULT_SEARCH_LIMIT = 500; // Default maximum number of search results.private ImageIcon searchIcon;private Color defaultHighlightColor;@@ -121,7 +120,7 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,createActions();initializeOptionListeners();- getOptions();+ loadOptions();tool.addContextListener(this);}@@ -383,8 +382,6 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,opt.registerOption(PluginConstants.AUTO_RESTRICT_SELECTION, true, null,"Automactically adjusts memory searches restricted" +" to the current selection, as selections comes and goes");- opt.registerOption(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_SEARCH_LIMIT, null,- "Number of search hits found before stopping");opt.registerOption(PluginConstants.SEARCH_HIGHLIGHT_NAME, true, null,"Toggles highlight search results");@@ -400,10 +397,11 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,opt.addOptionsChangeListener(this);}- private void getOptions() {+ private void loadOptions() {Options opt = tool.getOptions(PluginConstants.SEARCH_OPTION_NAME);- int newSearchLimit = opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_SEARCH_LIMIT);+ int newSearchLimit =+ opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, PluginConstants.DEFAULT_SEARCH_LIMIT);if (newSearchLimit <= 0) {throw new OptionsVetoException("Search limit must be greater than 0");}@@ -424,7 +422,7 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,@Overridepublic void optionsChanged(ToolOptions options, String optionName, Object oldValue,Object newValue) {- getOptions();+ loadOptions();}protected void updateSelection(NavigatableActionContext context) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/AbstractSearchTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/AbstractSearchTableModel.javaindex 7a6ffb9361..54725c99fd 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/AbstractSearchTableModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/AbstractSearchTableModel.java@@ -32,7 +32,6 @@ import ghidra.util.task.TaskMonitor;*/public abstract class AbstractSearchTableModel extends ProgramLocationPreviewTableModel {- private final static int DEFAULT_SEARCH_LIMIT = 500;final static String TITLE = "Text Search";protected SearchOptions options;@@ -50,7 +49,8 @@ public abstract class AbstractSearchTableModel extends ProgramLocationPreviewTabthis.set = set;this.options = options;Options opt = tool.getOptions(PluginConstants.SEARCH_OPTION_NAME);- searchLimit = opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_SEARCH_LIMIT);+ searchLimit =+ opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, PluginConstants.DEFAULT_SEARCH_LIMIT);}@Overridediff --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 5ed124474a..d0b45c54f5 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@@ -91,7 +91,6 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeListprivate static final ImageIcon searchIcon = ResourceManager.loadImage("images/searchm_obj.gif");private static final String DESCRIPTION = "Search program text for string";- private final static int DEFAULT_SEARCH_LIMIT = 500;private final static Highlight[] NO_HIGHLIGHTS = new Highlight[0];private boolean waitingForSearchAll;@@ -442,9 +441,6 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeListToolOptions opt = tool.getOptions(PluginConstants.SEARCH_OPTION_NAME);HelpLocation loc = new HelpLocation(HelpTopics.SEARCH, "HighlightText");- opt.registerOption(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_SEARCH_LIMIT, loc,- "Max number of matches on a search that will be displayed.");-opt.registerOption(PluginConstants.SEARCH_HIGHLIGHT_NAME, true, loc,"Determines whether to highlight the matched string for a search in the listing.");opt.registerOption(PluginConstants.SEARCH_HIGHLIGHT_COLOR_NAME,@@ -454,7 +450,8 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeListPluginConstants.SEARCH_HIGHLIGHT_COLOR, loc,"Color to use for highlighting when the match string occurs at the current address.");- searchLimit = opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_SEARCH_LIMIT);+ searchLimit =+ opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, PluginConstants.DEFAULT_SEARCH_LIMIT);doHighlight = opt.getBoolean(PluginConstants.SEARCH_HIGHLIGHT_NAME, true);highlightColor = opt.getColor(PluginConstants.SEARCH_HIGHLIGHT_COLOR_NAME,diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/navigation/GoToQuery.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/navigation/GoToQuery.javaindex 21ea4d5ed6..637fbce3bf 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/navigation/GoToQuery.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/navigation/GoToQuery.java@@ -71,13 +71,8 @@ public class GoToQuery {this.plugin = plugin;this.goToService = goToService;this.navigationOptions = navigationOptions;- Options opt = plugin.getTool().getOptions(PluginConstants.SEARCH_OPTION_NAME);- if (!opt.contains(GhidraOptions.OPTION_SEARCH_LIMIT)) {- opt.registerOption(GhidraOptions.OPTION_SEARCH_LIMIT,- PluginConstants.DEFAULT_SEARCH_LIMIT, null,- "The maximum number of search hits before stopping.");- }+ Options opt = plugin.getTool().getOptions(PluginConstants.SEARCH_OPTION_NAME);this.maxHits =opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, PluginConstants.DEFAULT_SEARCH_LIMIT);this.fromAddress = fromAddr;@@ -496,7 +491,7 @@ public class GoToQuery {Program program = navigatable.getProgram();SymbolTable symTable = program.getSymbolTable();- List<Symbol> symbols = new ArrayList<Symbol>();+ List<Symbol> symbols = new ArrayList<>();SymbolIterator symbolIterator = symTable.getSymbols(queryData.getQueryString());while (symbolIterator.hasNext()) {Symbol symbol = symbolIterator.next();diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/GoToPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPluginTest.javasimilarity index 99%rename from Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/GoToPluginTest.javarename to Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPluginTest.javaindex 0eab8446e6..132a10fe1b 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/GoToPluginTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/GoToAddressLabelPluginTest.java@@ -66,7 +66,7 @@ import ghidra.util.table.field.LabelTableColumn;import ghidra.util.task.TaskMonitor;import util.CollectionUtils;-public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {+public class GoToAddressLabelPluginTest extends AbstractGhidraHeadedIntegrationTest {private TestEnv env;private PluginTool tool;private AddressFactory addrFactory;