Merge remote-tracking branch

'origin/GP-1676-dragonmacher-bad-tool-option' into patch (Closes #3858)
This commit is contained in:
ghidra1 2022-01-20 17:38:24 -05:00
commit 21ff55ab9e
8 changed files with 36 additions and 95 deletions

View file

@ -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);

View file

@ -53,20 +53,27 @@ import ghidra.program.util.ProgramSelection;
)
//@formatter:on
public 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);
}
@Override

View file

@ -49,40 +49,19 @@ import ghidra.util.bean.opteditor.OptionsVetoException;
//@formatter:on
public 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' entry
private 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 OptionsChangeListe
GoToService 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 OptionsChangeListe
goToDialog.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
*/
@Override
public void optionsChanged(ToolOptions options, String opName, Object oldValue,
Object newValue) {
@ -177,12 +140,6 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe
}
}
//////////////////////////////////////////////////////////////////////
// //
// Overridden Plugin Methods //
// //
//////////////////////////////////////////////////////////////////////
@Override
public void dispose() {
ToolOptions options = tool.getOptions(ToolConstants.TOOL_OPTIONS);
@ -191,9 +148,8 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe
super.dispose();
}
private void getOptions() {
private void initOptions() {
ToolOptions opt = tool.getOptions(ToolConstants.TOOL_OPTIONS);
// descriptions
opt.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.");
// options
maximumGotoEntries =
opt.getInt(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES, DEFAULT_MAX_GOTO_ENTRIES);

View file

@ -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,
@Override
public void optionsChanged(ToolOptions options, String optionName, Object oldValue,
Object newValue) {
getOptions();
loadOptions();
}
protected void updateSelection(NavigatableActionContext context) {

View file

@ -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 ProgramLocationPreviewTab
this.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);
}
@Override

View file

@ -91,7 +91,6 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeList
private 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 OptionsChangeList
ToolOptions 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 OptionsChangeList
PluginConstants.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,

View file

@ -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();

View file

@ -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;