Java Code Examples for ghidra.framework.options.Options#getOptionNames()

The following examples show how to use ghidra.framework.options.Options#getOptionNames() . 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: PropertyListMergeManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Check the property names in the list; if values changed in both
 * places, then this is a conflict.
 * @param listName name of the property list
 */
private void checkValues(String listName) {
	Options myList = myProgram.getOptions(listName);
	Options resultList = resultProgram.getOptions(listName);
	Options origList = originalProgram.getOptions(listName);

	List<String> myNameList = myList.getOptionNames();
	List<String> resultNameList = resultList.getOptionNames();

	for (int i = 0; i < myNameList.size(); i++) {
		String name = myNameList.get(i);
		if (resultNameList.contains(name)) {
			updateValue(myList, resultList, origList, name);
		}
		else {
			// not in the result
			checkForAddedProperty(myList, resultList, origList, name);
		}
	}
	checkDeletedProperties(resultList, origList, myNameList, resultNameList,
		origList.getOptionNames());
}
 
Example 2
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 3
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 4
Source File: ListingPanelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void resetFormatOptions() {
	Options fieldOptions = cb.getFormatManager().getFieldOptions();
	List<String> names = fieldOptions.getOptionNames();

	for (String name : names) {
		if (!name.startsWith("Format Code")) {
			continue;
		}
		if (name.indexOf("Show ") >= 0 || name.indexOf("Flag ") >= 0) {
			fieldOptions.setBoolean(name, false);
		}
		else if (name.indexOf("Lines") >= 0) {
			fieldOptions.setInt(name, 0);
		}
	}
	waitForPostedSwingRunnables();
	cb.updateNow();
}
 
Example 5
Source File: CodeBrowserScreenMovementTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void resetFormatOptions(CodeBrowserPlugin plugin) {
	Options fieldOptions = plugin.getFormatManager().getFieldOptions();
	List<String> names = fieldOptions.getOptionNames();
	for (int i = 0; i < names.size(); i++) {
		String name = names.get(i);
		if (!name.startsWith("Format Code")) {
			continue;
		}
		if (name.indexOf("Show ") >= 0 || name.indexOf("Flag ") >= 0) {
			fieldOptions.setBoolean(name, false);
		}
		else if (name.indexOf("Lines") >= 0) {
			fieldOptions.setInt(name, 0);
		}
	}
	waitForPostedSwingRunnables();
	plugin.updateNow();
}
 
Example 6
Source File: CommentsPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void resetFormatOptions(CodeBrowserPlugin codeBrowserPlugin) {
	Options fieldOptions = codeBrowserPlugin.getFormatManager().getFieldOptions();
	List<String> names = fieldOptions.getOptionNames();
	for (int i = 0; i < names.size(); i++) {
		String name = names.get(i);
		if (!name.startsWith("Format Code")) {
			continue;
		}
		if (name.indexOf("Show ") >= 0 || name.indexOf("Flag ") >= 0) {
			fieldOptions.setBoolean(name, false);
		}
		else if (name.indexOf("Lines") >= 0) {
			fieldOptions.setInt(name, 0);
		}
	}
	waitForSwing();
	codeBrowserPlugin.updateNow();
}
 
Example 7
Source File: KeyBindingUtilsTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean compareOptionsWithKeyStrokeMap(Options oldOptions,
		Map<String, KeyStroke> panelKeyStrokeMap) {
	List<String> propertyNames = oldOptions.getOptionNames();
	for (String name : propertyNames) {

		boolean match = panelKeyStrokeMap.containsKey(name);
		KeyStroke optionsKs = oldOptions.getKeyStroke(name, null);
		KeyStroke panelKs = panelKeyStrokeMap.get(name);

		// if the value is null, then it would not have been placed into the options map 
		// in the key bindings panel, so we only care about non-null values
		if (optionsKs != null) {
			match &= (optionsKs.equals(panelKs));
		}
		else {
			match = true;
		}

		// short-circuit if there are any data that don't match
		if (!match) {
			return false;
		}
	}

	return true;
}
 
Example 8
Source File: GnuDemanglerAnalyzerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setOption(String optionName, String value) {

		String fullOptionName = analyzer.getName() + Options.DELIMITER_STRING + optionName;
		Options options = program.getOptions("Analyzers");

		for (String name : options.getOptionNames()) {
			if (name.equals(fullOptionName)) {
				tx(program, () -> options.setString(optionName, value));

				// we must call this manually, since we are not using a tool
				analyzer.optionsChanged(options, program);
				return;
			}
		}

		fail("Could not find option '" + optionName + "'");
	}
 
Example 9
Source File: GnuDemanglerAnalyzerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setOption(String optionName, boolean doUse) {

		String fullOptionName = analyzer.getName() + Options.DELIMITER_STRING + optionName;
		Options options = program.getOptions("Analyzers");

		for (String name : options.getOptionNames()) {
			if (name.equals(fullOptionName)) {
				tx(program, () -> options.setBoolean(optionName, doUse));

				// we must call this manually, since we are not using a tool
				analyzer.optionsChanged(options, program);
				return;
			}
		}

		fail("Could not find option '" + optionName + "'");
	}
 
Example 10
Source File: DataTypeArchiveDB.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> getMetadata() {

	metadata.clear();
	metadata.put("Data Type Archive Name", getName());
	metadata.put("# of Data Types", "" + getDataTypeManager().getDataTypeCount(true));
	metadata.put("# of Data Type Categories", "" + getDataTypeManager().getCategoryCount());

	Options propList = getOptions(Program.PROGRAM_INFO);
	List<String> propNames = propList.getOptionNames();
	Collections.sort(propNames);
	for (String name : propNames) {
		metadata.put(name, propList.getValueAsString(name));
	}
	return metadata;
}
 
Example 11
Source File: AutoAnalysisManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public void restoreDefaultOptions() {
	boolean commit = false;
	int id = program.startTransaction("Restore Default Analysis Options");
	try {
		Options options = program.getOptions(Program.ANALYSIS_PROPERTIES);
		for (String propertyName : options.getOptionNames()) {
			options.restoreDefaultValue(propertyName);
		}

		commit = true;
	}
	finally {
		program.endTransaction(id, commit);
	}
}
 
Example 12
Source File: PropertyListMergeManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Add the property list to the result program.
 * @param id of property list
 */
private void addPropertyList(String listName) {
	Options list = myProgram.getOptions(listName);
	Options resultList = resultProgram.getOptions(listName);
	for (String optionName : list.getOptionNames()) {
		if (currentMonitor.isCancelled()) {
			return;
		}
		addProperty(list, resultList, optionName);
		currentMonitor.setProgress(++progressIndex);
	}

}
 
Example 13
Source File: KeyBindingUtilsTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private List<String> getOptionsNamesWithValues(Options options) {
	List<String> namesWithValues = new ArrayList<>();
	List<String> optionNames = options.getOptionNames();
	for (String string : optionNames) {
		if (options.getObject(string, null) != null) {
			namesWithValues.add(string);
		}
	}
	return namesWithValues;
}
 
Example 14
Source File: AnalyzeAllOpenProgramsTaskTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void verifyDefaultOptions(Collection<Program> programs) {
	for (Program program : programs) {
		Options options = program.getOptions(Program.ANALYSIS_PROPERTIES);
		for (String name : options.getOptionNames()) {
			assertTrue("Program options are unexpectedly changed: " + program,
				options.isDefaultValue(name));
		}
	}
}
 
Example 15
Source File: CodeBrowserOptionsTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private List<String> getOptionNames(Options options, String prefix) {
	List<String> names = options.getOptionNames();
	ArrayList<String> list = new ArrayList<>();
	for (String element : names) {
		if (element.startsWith(prefix)) {
			list.add(element);
		}
	}
	return list;
}
 
Example 16
Source File: CodeBrowserOptionsTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionsHeaders() throws Exception {

	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	List<String> names = options.getOptionNames();
	Set<String> map = new HashSet<>();
	for (String element : names) {
		int index = element.indexOf(Options.DELIMITER);
		if (index > 0) { // ignore those at the top level
			map.add(element.substring(0, index));
		}
	}
	String[] groups = new String[map.size()];
	map.toArray(groups);
	Arrays.sort(groups);
	int idx = 0;
	assertEquals("Address Field", groups[idx++]);
	assertEquals("Array Options", groups[idx++]);
	assertEquals("Bytes Field", groups[idx++]);
	assertEquals("Cursor", groups[idx++]);
	assertEquals("Cursor Text Highlight", groups[idx++]);
	assertEquals("EOL Comments Field", groups[idx++]);
	assertEquals("Format Code", groups[idx++]);
	assertEquals("Function Pointers", groups[idx++]);
	assertEquals("Function Signature Field", groups[idx++]);
	assertEquals("Labels Field", groups[idx++]);
	assertEquals("Mnemonic Field", groups[idx++]);
	assertEquals("Mouse", groups[idx++]);
	assertEquals("Operands Field", groups[idx++]);
	assertEquals("Pcode Field", groups[idx++]);
	assertEquals("Plate Comments Field", groups[idx++]);
	assertEquals("Post-comments Field", groups[idx++]);
	assertEquals("Pre-comments Field", groups[idx++]);
	assertEquals("Register Field", groups[idx++]);
	assertEquals("Selection Colors", groups[idx++]);
	assertEquals("XREFs Field", groups[idx++]);
}
 
Example 17
Source File: ProgramDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getMetadata() {
	metadata.clear();
	metadata.put("Program Name", getName());
	metadata.put("Language ID",
		languageID + " (" + languageVersion + "." + languageMinorVersion + ")");
	metadata.put("Compiler ID", compilerSpecID.getIdAsString());
	metadata.put("Processor", language.getProcessor().toString());
	metadata.put("Endian", memoryManager.isBigEndian() ? "Big" : "Little");
	metadata.put("Address Size", "" + addressFactory.getDefaultAddressSpace().getSize());
	metadata.put("Minimum Address", getString(getMinAddress()));
	metadata.put("Maximum Address", getString(getMaxAddress()));
	metadata.put("# of Bytes", "" + getNumberOfBytes());
	metadata.put("# of Memory Blocks", "" + memoryManager.getBlocks().length);
	metadata.put("# of Instructions", "" + listing.getNumInstructions());
	metadata.put("# of Defined Data", "" + listing.getNumDefinedData());
	metadata.put("# of Functions", "" + getFunctionManager().getFunctionCount());
	metadata.put("# of Symbols", "" + getSymbolTable().getNumSymbols());
	metadata.put("# of Data Types", "" + getDataTypeManager().getDataTypeCount(true));
	metadata.put("# of Data Type Categories", "" + getDataTypeManager().getCategoryCount());

	Options propList = getOptions(Program.PROGRAM_INFO);
	List<String> propNames = propList.getOptionNames();
	Collections.sort(propNames);
	for (String propName : propNames) {
		metadata.put(propName, propList.getValueAsString(propName));
	}
	return metadata;
}
 
Example 18
Source File: GhidraScript.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the given program's ANALYSIS_PROPERTIES and returns a HashMap of the
 * program's analysis options to current values (values represented as strings).
 * <p>
 * The string "(default)" is appended to the value if it represents the
 * default value for the option it is assigned to.
 *
 * @param program  the program to get analysis options from
 * @return  mapping of analysis options to current settings (represented as strings)
 */
public Map<String, String> getCurrentAnalysisOptionsAndValues(Program program) {

	Map<String, String> availableOptions = new HashMap<>();
	Options options = program.getOptions(Program.ANALYSIS_PROPERTIES);

	for (String propertyName : options.getOptionNames()) {
		OptionType propertyType = options.getType(propertyName);
		Object propertyValue = null;

		switch (propertyType) {
			case INT_TYPE:
				propertyValue = Integer.valueOf(options.getInt(propertyName, -1));
				break;

			case LONG_TYPE:
				propertyValue = Long.valueOf(options.getLong(propertyName, -1l));
				break;

			case STRING_TYPE:
				propertyValue = options.getString(propertyName, "");
				break;

			case DOUBLE_TYPE:
				propertyValue = Double.valueOf(options.getDouble(propertyName, -1.0d));
				break;

			case BOOLEAN_TYPE:
				propertyValue = Boolean.valueOf(options.getBoolean(propertyName, false));
				break;
			case FLOAT_TYPE:
				propertyValue = Float.valueOf(options.getFloat(propertyName, 0f));
				break;

			case DATE_TYPE:
			case BYTE_ARRAY_TYPE:
			case COLOR_TYPE:
			case CUSTOM_TYPE:
			case FILE_TYPE:
			case FONT_TYPE:
			case KEYSTROKE_TYPE:
				// do nothing; don't allow user to set these options (doesn't make any sense)
				break;

			case NO_TYPE:
				break;
			case ENUM_TYPE:
				propertyValue = options.getObject(propertyName, null);
				break;
			default:
				// Do nothing
		}

		if (propertyValue != null) {
			availableOptions.put(propertyName, propertyValue.toString());
		}
	}

	return availableOptions;
}
 
Example 19
Source File: ProgramDB.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void checkOldProperties(int openMode, TaskMonitor monitor)
		throws IOException, VersionException {
	Record record = table.getRecord(new StringField(EXECUTE_PATH));
	if (record != null) {
		if (openMode == READ_ONLY) {
			return; // not important, get on path or format will return "unknown"
		}
		if (openMode != UPGRADE) {
			throw new VersionException(true);
		}
		Options pl = getOptions(PROGRAM_INFO);
		String value = record.getString(0);
		pl.setString(EXECUTABLE_PATH, value);
		table.deleteRecord(record.getKeyField());
		record = table.getRecord(new StringField(EXECUTE_FORMAT));
		if (record != null) {
			pl.setString(EXECUTABLE_FORMAT, value);
			table.deleteRecord(record.getKeyField());
		}
	}
	int storedVersion = getStoredVersion();
	if (storedVersion < ANALYSIS_OPTIONS_MOVED_VERSION) {
		if (openMode == READ_ONLY) {
			return;
		}
		if (openMode != UPGRADE) {
			throw new VersionException(true);
		}
		Options oldList = getOptions("Analysis");
		for (String propertyName : oldList.getOptionNames()) {
			oldList.removeOption(propertyName);
		}
	}
	if (storedVersion < METADATA_ADDED_VERSION) {
		if (openMode == READ_ONLY) {
			return;
		}
		if (openMode != UPGRADE) {
			throw new VersionException(true);
		}
	}

}
 
Example 20
Source File: KeyBindingsPanel.java    From ghidra with Apache License 2.0 3 votes vote down vote up
private Map<String, KeyStroke> createActionNameToKeyStrokeMap(Options keyBindingOptions) {

		Map<String, KeyStroke> localActionMap = new HashMap<>();

		List<String> optionNames = keyBindingOptions.getOptionNames();

		for (String element : optionNames) {
			KeyStroke newKeyStroke = keyBindingOptions.getKeyStroke(element, null);
			localActionMap.put(element, newKeyStroke);
		}

		return localActionMap;
	}