Java Code Examples for ghidra.framework.plugintool.PluginTool#getOptions()

The following examples show how to use ghidra.framework.plugintool.PluginTool#getOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphASTControlFlowAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void decompilerActionPerformed(DecompilerActionContext context) {
	PluginTool tool = context.getTool();
	GraphDisplayBroker service = tool.getService(GraphDisplayBroker.class);
	if (service == null) {
		Msg.showError(this, tool.getToolFrame(), "AST Graph Failed",
			"Graph consumer not found: Please add a graph consumer provider to your tool");
		return;
	}

	// TODO: Options should really be obtained from graph service
	Options options = tool.getOptions("Graph");
	boolean reuseGraph = options.getBoolean("Reuse Graph", false);
	int codeLimitPerBlock = options.getInt("Max Code Lines Displayed", 10);
	HighFunction highFunction = context.getHighFunction();
	Address locationAddr = context.getLocation().getAddress();
	ASTGraphTask task = new ASTGraphTask(service, !reuseGraph, codeLimitPerBlock, locationAddr,
		highFunction, CONTROL_FLOW_GRAPH, tool);
	new TaskLauncher(task, tool.getToolFrame());
}
 
Example 2
Source File: DiffApplySettingsOptionManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Saves the indicated merge filter as the default apply settings.
 * @param defaultApplyFilter merge filter indicating default apply settings.
 */
public void saveDefaultApplyFilter(ProgramMergeFilter newDefaultApplyFilter) {
	PluginTool tool = plugin.getTool();
	Options options = tool.getOptions(DIFF_OPTIONS);

	saveReplaceOption(options, newDefaultApplyFilter, PROGRAM_CONTEXT);
	saveReplaceOption(options, newDefaultApplyFilter, BYTES);
	saveReplaceOption(options, newDefaultApplyFilter, REFERENCES);
	saveReplaceOption(options, newDefaultApplyFilter, BOOKMARKS);
	saveReplaceOption(options, newDefaultApplyFilter, PROPERTIES);
	saveReplaceOption(options, newDefaultApplyFilter, FUNCTIONS);

	saveMergeOption(options, newDefaultApplyFilter, PLATE_COMMENTS);
	saveMergeOption(options, newDefaultApplyFilter, PRE_COMMENTS);
	saveMergeOption(options, newDefaultApplyFilter, EOL_COMMENTS);
	saveMergeOption(options, newDefaultApplyFilter, REPEATABLE_COMMENTS);
	saveMergeOption(options, newDefaultApplyFilter, POST_COMMENTS);

	saveMergeOption(options, newDefaultApplyFilter, FUNCTION_TAGS);

	saveCodeUnitReplaceOption(options, newDefaultApplyFilter, CODE_UNITS);
	saveSymbolMergeOption(options, newDefaultApplyFilter, SYMBOLS);

	tool.setConfigChanged(true);
}
 
Example 3
Source File: EntropyOverviewOptionsManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public EntropyOverviewOptionsManager(PluginTool tool, EntropyOverviewColorService service) {
	this.service = service;
	ToolOptions options = tool.getOptions(OPTIONS_NAME);
	HelpLocation help = new HelpLocation(OverviewColorPlugin.HELP_TOPIC, "EntropyOverviewBar");

	options.addOptionsChangeListener(this);
	options.setOptionsHelpLocation(help);

	options.registerOption(CHUNKSIZE_STRING, chunksize_def, help, CHUNKSIZE_DESC_STRING);
	options.registerOption(KNOT1_COLOR_STRING, knot1_def_color, help, KNOT_COLOR_STRING);
	options.registerOption(KNOT2_COLOR_STRING, knot2_def_color, help, KNOT_COLOR_STRING);
	options.registerOption(KNOT3_COLOR_STRING, knot3_def_color, help, KNOT_COLOR_STRING);
	options.registerOption(KNOT4_COLOR_STRING, knot4_def_color, help, KNOT_COLOR_STRING);
	options.registerOption(KNOT5_COLOR_STRING, knot5_def_color, help, KNOT_COLOR_STRING);

	options.registerOption(KNOT1_TYPE_STRING, knot1_def_type, help, KNOT_TYPE_STRING);
	options.registerOption(KNOT2_TYPE_STRING, knot2_def_type, help, KNOT_TYPE_STRING);
	options.registerOption(KNOT3_TYPE_STRING, knot3_def_type, help, KNOT_TYPE_STRING);
	options.registerOption(KNOT4_TYPE_STRING, knot4_def_type, help, KNOT_TYPE_STRING);
	options.registerOption(KNOT5_TYPE_STRING, knot5_def_type, help, KNOT_TYPE_STRING);

	readOptions(options);
	updatePalettes();
}
 
Example 4
Source File: AbstractToolSavingTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/** A crude counting of available options */
// the 'name' variable in the inner-loop
protected int countOptions(PluginTool tool) {
	Msg.debug(this, "\n\nCount Options: ");
	Options[] options = tool.getOptions();
	int count = 0;
	for (Options option : options) {
		List<String> optionNames = option.getOptionNames();
		for (String name : optionNames) {
			Object value = invokeInstanceMethod("getObject", option,
				new Class[] { String.class, Object.class }, new Object[] { name, null });
			Msg.debug(this, "\tname: " + name + " - value: " + value);
			count++;
		}
	}

	return count;
}
 
Example 5
Source File: AbstractToolSavingTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected Map<String, Object> getOptionsMap(PluginTool tool) {
	Map<String, Object> map = new TreeMap<>();
	Options[] options = tool.getOptions();
	for (Options option : options) {
		String optionsName = option.getName();

		if (optionsName.equals("Key Bindings")) {
			Msg.debug(this, "break");
		}

		List<String> optionNames = option.getOptionNames();
		for (String name : optionNames) {
			Object value = invokeInstanceMethod("getObject", option,
				new Class[] { String.class, Object.class }, new Object[] { name, null });
			map.put(optionsName + "." + name, value);
		}
	}
	return map;
}
 
Example 6
Source File: DecompileOptions.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void grabFromToolOptions(Plugin ownerPlugin) {
	if (ownerPlugin == null) {
		return;
	}

	PluginTool tool = ownerPlugin.getTool();
	Options toolOptions = tool.getOptions(CATEGORY_BROWSER_FIELDS);

	middleMouseHighlightColor =
		toolOptions.getColor(HIGHLIGHT_COLOR_NAME, HIGHLIGHT_MIDDLE_MOUSE_DEF);

	CURSOR_MOUSE_BUTTON_NAMES mouseEvent =
		toolOptions.getEnum(CURSOR_HIGHLIGHT_BUTTON_NAME, CURSOR_MOUSE_BUTTON_NAMES.MIDDLE);
	middleMouseHighlightButton = mouseEvent.getMouseEventID();
}
 
Example 7
Source File: BlockModelServicePlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public BlockModelServicePlugin(PluginTool tool) {

		super(tool, false, false);

		// Add standard simple block model
		BlockModelInfo info = new BlockModelInfo(SimpleBlockModel.NAME, SimpleBlockModel.class);
		basicModelsByName.put(SimpleBlockModel.NAME, info);
		activeBasicModel = info;

		// Add standard multi-entry subroutine model
		info = new BlockModelInfo(MultEntSubModel.NAME, MultEntSubModel.class);
		subroutineModelsByName.put(MultEntSubModel.NAME, info);
		activeSubroutineModel = info;

		// Add special subroutine models
		info =
			new BlockModelInfo(OverlapCodeSubModel.OVERLAP_MODEL_NAME, OverlapCodeSubModel.class);
		subroutineModelsByName.put(OverlapCodeSubModel.OVERLAP_MODEL_NAME, info);
		info = new BlockModelInfo(IsolatedEntrySubModel.ISOLATED_MODEL_NAME,
			IsolatedEntrySubModel.class);
		subroutineModelsByName.put(IsolatedEntrySubModel.ISOLATED_MODEL_NAME, info);
		info =
			new BlockModelInfo(OverlapCodeSubModel.OVERLAP_MODEL_NAME, PartitionCodeSubModel.class);
		subroutineModelsByName.put(PartitionCodeSubModel.NAME, info);

		String[] availableModelNames = getAvailableModelNames(SUBROUTINE_MODEL);
		selectedSubroutineModelName = availableModelNames[0];

		// Install model selection option in Tool panel
		options = tool.getOptions(ToolConstants.TOOL_OPTIONS);
		editor = new StringWithChoicesEditor(availableModelNames);
		options.registerOption(SUB_OPTION, OptionType.STRING_TYPE, selectedSubroutineModelName,
			null, "The default subroutine model used when creating call graphs.", editor);
		setPreferedModel(options);
		updateModelOptions();
		options.addOptionsChangeListener(this);

		// Set active subroutine block model
//        activeSubroutineModelFactory = (CodeBlockModel) subroutineModelsByName.get(subroutineModelList.getSelectedValue());
	}
 
Example 8
Source File: AbstractSearchTableModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public AbstractSearchTableModel(PluginTool tool, Program p, AddressSetView set,
		SearchOptions options) {

	super(TITLE, tool, p, null, true);
	this.tool = tool;
	this.set = set;
	this.options = options;
	Options opt = tool.getOptions(PluginConstants.SEARCH_OPTION_NAME);
	searchLimit = opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, DEFAULT_SEARCH_LIMIT);
}
 
Example 9
Source File: ConsoleTextPane.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ConsoleTextPane(PluginTool tool) {
	createAttribtues();
	setEditable(true);

	ToolOptions options = tool.getOptions(OPTIONS_NAME);
	options.addOptionsChangeListener(this);
	initOptions(options);
}
 
Example 10
Source File: ToolPropertiesExampleScript.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void run() throws Exception {

	PluginTool tool = state.getTool();

	Options options = tool.getOptions( "name of my script" );

	String fooString = options.getString( "foo", null );

	if ( fooString == null ) {//does not exist in tool options

		fooString = askString( "enter foo", "what value for foo:" );

		if ( fooString != null ) {
			options.setString( "foo", fooString );
		}
	}

	popup( fooString );
}
 
Example 11
Source File: DiffApplySettingsOptionManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
	 * Gets the merge filter for the default apply settings.
	 * @return merge filter indicating default apply settings.
	 */
	public ProgramMergeFilter getDefaultApplyFilter() {
		PluginTool tool = plugin.getTool();
		Options options = tool.getOptions(DIFF_OPTIONS);

//		case PROGRAM_CONTEXT:
//		case BYTES:
//		case CODE_UNITS:
//		case REFERENCES:
//		case BOOKMARKS:
//		case PROPERTIES:
//		case FUNCTIONS:

		// Get the current settings as options
		REPLACE_CHOICE programContext =
			options.getEnum(OPTION_PROGRAM_CONTEXT, REPLACE_CHOICE.REPLACE);
		REPLACE_CHOICE bytes = options.getEnum(OPTION_BYTES, REPLACE_CHOICE.REPLACE);
		REPLACE_CHOICE codeUnits = options.getEnum(OPTION_CODE_UNITS, REPLACE_CHOICE.REPLACE);
		REPLACE_CHOICE references = options.getEnum(OPTION_REFERENCES, REPLACE_CHOICE.REPLACE);
		MERGE_CHOICE plateComments = options.getEnum(OPTION_PLATE_COMMENTS, MERGE_CHOICE.MERGE);
		MERGE_CHOICE preComments = options.getEnum(OPTION_PRE_COMMENTS, MERGE_CHOICE.MERGE);
		MERGE_CHOICE eolComments = options.getEnum(OPTION_EOL_COMMENTS, MERGE_CHOICE.MERGE);
		MERGE_CHOICE repeatableComments =
			options.getEnum(OPTION_REPEATABLE_COMMENTS, MERGE_CHOICE.MERGE);
		MERGE_CHOICE postComments = options.getEnum(OPTION_POST_COMMENTS, MERGE_CHOICE.MERGE);
		SYMBOL_MERGE_CHOICE symbols =
			options.getEnum(OPTION_SYMBOLS, SYMBOL_MERGE_CHOICE.MERGE_AND_SET_PRIMARY);
		REPLACE_CHOICE bookmarks = options.getEnum(OPTION_BOOKMARKS, REPLACE_CHOICE.REPLACE);
		REPLACE_CHOICE properties = options.getEnum(OPTION_PROPERTIES, REPLACE_CHOICE.REPLACE);
		REPLACE_CHOICE functions = options.getEnum(OPTION_FUNCTIONS, REPLACE_CHOICE.REPLACE);
		MERGE_CHOICE functionTags = options.getEnum(OPTION_FUNCTION_TAGS, MERGE_CHOICE.MERGE);

		// Convert the options to a merge filter.
		ProgramMergeFilter filter = new ProgramMergeFilter();
		filter.setFilter(ProgramMergeFilter.PROGRAM_CONTEXT, programContext.ordinal());
		filter.setFilter(ProgramMergeFilter.BYTES, bytes.ordinal());
		filter.setFilter(ProgramMergeFilter.CODE_UNITS, codeUnits.ordinal());
		filter.setFilter(ProgramMergeFilter.REFERENCES, references.ordinal());
		filter.setFilter(ProgramMergeFilter.PLATE_COMMENTS, plateComments.ordinal());
		filter.setFilter(ProgramMergeFilter.PRE_COMMENTS, preComments.ordinal());
		filter.setFilter(ProgramMergeFilter.EOL_COMMENTS, eolComments.ordinal());
		filter.setFilter(ProgramMergeFilter.REPEATABLE_COMMENTS, repeatableComments.ordinal());
		filter.setFilter(ProgramMergeFilter.POST_COMMENTS, postComments.ordinal());
		filter.setFilter(ProgramMergeFilter.SYMBOLS,
			convertSymbolMergeChoiceToMergeChoice(symbols).ordinal());
		filter.setFilter(ProgramMergeFilter.BOOKMARKS, bookmarks.ordinal());
		filter.setFilter(ProgramMergeFilter.PROPERTIES, properties.ordinal());
		filter.setFilter(ProgramMergeFilter.FUNCTIONS, functions.ordinal());
		filter.setFilter(ProgramMergeFilter.FUNCTION_TAGS, functionTags.ordinal());
		filter.setFilter(ProgramMergeFilter.PRIMARY_SYMBOL,
			convertSymbolMergeChoiceToReplaceChoiceForPrimay(symbols).ordinal());

		return filter;
	}
 
Example 12
Source File: NavigationOptions.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public NavigationOptions(PluginTool tool) {
	this(tool.getOptions(NavigationOptions.NAVIGATION_OPTIONS));
}
 
Example 13
Source File: AutoAnalysisManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void initializeToolOptions(PluginTool tool) {
	Options options = tool.getOptions("Auto Analysis");
	options.registerOption(OPTION_NAME_THREAD_USE, analysisSharedThreadPoolSize, null,
		OPTION_DESCRIPTION_THREAD_USE);
	analysisSharedThreadPoolSize = getSharedThreadPoolSizeOption(tool);
}
 
Example 14
Source File: AutoAnalysisManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private static int getSharedThreadPoolSizeOption(PluginTool tool) {
	Options options = tool.getOptions("Auto Analysis");
	return options.getInt(OPTION_NAME_THREAD_USE, analysisSharedThreadPoolSize);
}
 
Example 15
Source File: AbstractToolSavingTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected boolean getBooleanFooOptions(PluginTool tool) {
	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	return options.getBoolean("foo", false);
}
 
Example 16
Source File: AbstractToolSavingTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected void setBooleanFooOptions(PluginTool tool, boolean value) {
	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	options.setBoolean("foo", value);
}