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

The following examples show how to use ghidra.framework.options.Options#contains() . 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: BasicCompilerSpec.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void registerProgramOptions(Program program) {

	// NOTE: Any changes to the option name/path must be handled carefully since
	// old property values will remain in the program.  There is currently no support
	// for upgrading/moving old property values.

	Options decompilerPropertyList = program.getOptions(DECOMPILER_PROPERTY_LIST_NAME);
	decompilerPropertyList.registerOption(EVALUATION_MODEL_PROPERTY_NAME,
		OptionType.STRING_TYPE, evaluationModelChoices[0], null,
		"Select the default function prototype/evaluation model to be used during Decompiler analysis",
		new StringWithChoicesEditor(evaluationModelChoices));

	if (decompilerPropertyList.contains(DECOMPILER_OUTPUT_LANGUAGE)) {
		decompilerPropertyList.registerOption(DECOMPILER_OUTPUT_LANGUAGE, DECOMPILER_OUTPUT_DEF,
			null, DECOMPILER_OUTPUT_DESC);

	}

	Options analysisPropertyList =
		program.getOptions(Program.ANALYSIS_PROPERTIES + ".Decompiler Parameter ID");
	analysisPropertyList.createAlias(EVALUATION_MODEL_PROPERTY_NAME, decompilerPropertyList,
		EVALUATION_MODEL_PROPERTY_NAME);
}
 
Example 2
Source File: RelocationManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRelocatable() {
	if (isRelocatable == null) {
		Options propList = program.getOptions(Program.PROGRAM_INFO);
		if (propList.contains(RELOCATABLE_PROP_NAME)) {
			isRelocatable = propList.getBoolean(RELOCATABLE_PROP_NAME, false);
		}
		else {
			isRelocatable = (getSize() > 0);
		}
	}
	return isRelocatable.booleanValue();
}
 
Example 3
Source File: ProgramDataTypeManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void removeOldFileNameList() {
	if (upgrade) {
		Options options = program.getOptions(Program.PROGRAM_INFO);
		if (options.contains(OLD_DT_ARCHIVE_FILENAMES)) {
			options.removeOption(OLD_DT_ARCHIVE_FILENAMES);
		}
	}
}
 
Example 4
Source File: BasicCompilerSpec.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public DecompilerLanguage getDecompilerOutputLanguage(Program program) {
	Options options = program.getOptions(DECOMPILER_PROPERTY_LIST_NAME);
	if (options.contains(DECOMPILER_OUTPUT_LANGUAGE)) {
		return options.getEnum(DECOMPILER_OUTPUT_LANGUAGE, DECOMPILER_OUTPUT_DEF);
	}
	return DECOMPILER_OUTPUT_DEF;
}
 
Example 5
Source File: GoToQuery.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public GoToQuery(Navigatable navigatable, Plugin plugin, GoToService goToService,
		QueryData queryData, Address fromAddr, GoToServiceListener listener,
		NavigationOptions navigationOptions, TaskMonitor monitor) {

	this.navigatable = navigatable;
	this.queryData = queryData;
	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.");
	}
	this.maxHits =
		opt.getInt(GhidraOptions.OPTION_SEARCH_LIMIT, PluginConstants.DEFAULT_SEARCH_LIMIT);
	this.fromAddress = fromAddr;
	this.monitor = monitor;

	if (listener != null) {
		this.listener = listener;
	}
	else {
		this.listener = new DummyGoToServiceListener();
	}

	programs = getAllPrograms();
	tableModelListener = new GoToQueryThreadedTableModelListener();
}
 
Example 6
Source File: GhidraProgramUtilities.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the program contains the analyzed flag.
 * @param program the program to check for the property
 * @return true if the program contains the analyzed flag
 */
public static boolean shouldAskToAnalyze(Program program) {
	try {
		SimpleDateFormat format = new SimpleDateFormat(Program.ANALYSIS_START_DATE_FORMAT);
		Date analysisStartDate = format.parse(Program.ANALYSIS_START_DATE);
		Date creationDate = program.getCreationDate();
		if (creationDate.compareTo(analysisStartDate) < 0) {
			return false;
		}
	}
	catch (ParseException e) {
	}
	Options options = program.getOptions(Program.PROGRAM_INFO);
	return !options.contains(Program.ANALYZED);
}
 
Example 7
Source File: GhidraScript.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Private method, returns any error message that may have resulted from attempting to set
 * the given analysis option to the given analysis value.
 *
 * @param options  the options for which analysisOption should be set to
 * 			analysisOptionValue
 * @param analysisOption	the option to be changed
 * @param analysisOptionValue	the value to be set for the option
 * @return  a String description of any errors that occurred during setting of options; if
 * 		empty String is returned, no problems occurred.
 */
private String setAnalysisOption(Options options, String analysisOption,
		String analysisOptionValue) {

	String changeFailedMessage = "";
	if (analysisOptionValue == null) {
		return changeFailedMessage + " " + analysisOption +
			" Can not set an analyzer option to null value.";
	}

	if (!options.contains(analysisOption)) {
		return changeFailedMessage + analysisOption + " could not be found for this program.";
	}

	OptionType optionType = options.getType(analysisOption);
	try {
		switch (optionType) {

			case INT_TYPE:
				options.setInt(analysisOption, Integer.valueOf(analysisOptionValue));
				break;

			case LONG_TYPE:
				options.setLong(analysisOption, Long.valueOf(analysisOptionValue));
				break;

			case STRING_TYPE:
				options.setString(analysisOption, analysisOptionValue);
				break;

			case DOUBLE_TYPE:

				options.setDouble(analysisOption, Double.valueOf(analysisOptionValue));
				break;
			case FLOAT_TYPE:
				options.setFloat(analysisOption, Float.valueOf(analysisOptionValue));
				break;

			case BOOLEAN_TYPE:
				// Tests if text actually equals "true" or "false
				String tempBool = analysisOptionValue.toLowerCase();

				if (tempBool.equals("true") || tempBool.equals("false")) {
					options.setBoolean(analysisOption, Boolean.valueOf(tempBool));
				}

				break;
			case ENUM_TYPE:
				setEnum(options, analysisOption, analysisOptionValue);
				break;
			case KEYSTROKE_TYPE:
			case FONT_TYPE:
			case DATE_TYPE:
			case BYTE_ARRAY_TYPE:
			case COLOR_TYPE:
			case CUSTOM_TYPE:
			case FILE_TYPE:
				changeFailedMessage +=
					"Not allowed to change settings usings strings for type: " + optionType;

			case NO_TYPE:
			default:
				changeFailedMessage += "The option could not be found for this program.";
		}

	}
	catch (NumberFormatException numFormatExc) {
		changeFailedMessage += "Could not convert '" + analysisOptionValue +
			"' to a number of type " + optionType + ".";
	}
	catch (IllegalArgumentException e) {
		changeFailedMessage = "Error changing setting for option '" + analysisOption + "'. ";
	}

	return changeFailedMessage;
}