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

The following examples show how to use ghidra.framework.options.Options#setEnum() . 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: GhidraScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void setEnum(Options options, String analysisOption, String analysisOptionValue) {

	@SuppressWarnings("rawtypes")
	Enum enumm = options.getEnum(analysisOption, null);
	if (enumm == null) {
		throw new IllegalStateException(
			"Attempted to set an Enum option without an " + "existing enum value alreday set.");
	}

	@SuppressWarnings({ "rawtypes" })
	Enum newEnumm = Enum.valueOf(enumm.getClass(), analysisOptionValue);
	if (newEnumm != null) {
		options.setEnum(analysisOption, newEnumm);
	}
}
 
Example 2
Source File: BasicCompilerSpec.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Adds and enables an option to have the decompiler display java.
 * @param program to be enabled
 */
public static void enableJavaLanguageDecompilation(Program program) {
	Options decompilerPropertyList =
		program.getOptions(BasicCompilerSpec.DECOMPILER_PROPERTY_LIST_NAME);
	decompilerPropertyList.registerOption(BasicCompilerSpec.DECOMPILER_OUTPUT_LANGUAGE,
		BasicCompilerSpec.DECOMPILER_OUTPUT_DEF, null,
		BasicCompilerSpec.DECOMPILER_OUTPUT_DESC);
	decompilerPropertyList.setEnum(BasicCompilerSpec.DECOMPILER_OUTPUT_LANGUAGE,
		DecompilerLanguage.JAVA_LANGUAGE);
}
 
Example 3
Source File: DiffApplySettingsOptionManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void saveCodeUnitReplaceOption(Options options, ProgramMergeFilter defaultApplyFilter,
		int setting) {
	int filter =
		(defaultApplyFilter.getFilter(ProgramMergeFilter.INSTRUCTIONS) >= defaultApplyFilter.getFilter(ProgramMergeFilter.DATA)) ? ProgramMergeFilter.INSTRUCTIONS
				: ProgramMergeFilter.DATA;
	REPLACE_CHOICE defaultSetting = REPLACE_CHOICE.REPLACE;
	REPLACE_CHOICE optionSetting = options.getEnum(getOptionName(setting), defaultSetting);
	REPLACE_CHOICE diffSetting = convertTypeToReplaceEnum(defaultApplyFilter, filter);
	if (!diffSetting.equals(optionSetting)) {
		options.setEnum(getOptionName(setting), diffSetting);
	}
}
 
Example 4
Source File: DiffApplySettingsOptionManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void saveReplaceOption(Options options, ProgramMergeFilter defaultApplyFilter,
		int setting) {
	REPLACE_CHOICE defaultSetting = REPLACE_CHOICE.REPLACE;
	REPLACE_CHOICE optionSetting = options.getEnum(getOptionName(setting), defaultSetting);
	REPLACE_CHOICE diffSetting =
		convertTypeToReplaceEnum(defaultApplyFilter, getMergeFilterType(setting));
	if (!diffSetting.equals(optionSetting)) {
		options.setEnum(getOptionName(setting), diffSetting);
	}
}
 
Example 5
Source File: DiffApplySettingsOptionManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void saveMergeOption(Options options, ProgramMergeFilter defaultApplyFilter, int setting) {
	MERGE_CHOICE defaultSetting = MERGE_CHOICE.MERGE;
	MERGE_CHOICE optionSetting = options.getEnum(getOptionName(setting), defaultSetting);
	MERGE_CHOICE diffSetting =
		convertTypeToMergeEnum(defaultApplyFilter, getMergeFilterType(setting));
	if (!diffSetting.equals(optionSetting)) {
		options.setEnum(getOptionName(setting), diffSetting);
	}
}
 
Example 6
Source File: DiffApplySettingsOptionManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void saveSymbolMergeOption(Options options, ProgramMergeFilter defaultApplyFilter,
		int setting) {
	SYMBOL_MERGE_CHOICE defaultSetting = SYMBOL_MERGE_CHOICE.MERGE_AND_SET_PRIMARY;
	SYMBOL_MERGE_CHOICE optionSetting = options.getEnum(getOptionName(setting), defaultSetting);
	SYMBOL_MERGE_CHOICE diffSetting = getSymbolMergeEnum(defaultApplyFilter);
	if (!diffSetting.equals(optionSetting)) {
		options.setEnum(getOptionName(setting), diffSetting);
	}
}
 
Example 7
Source File: GhidraScriptTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetInvalidAnalysisOptionsAndValues() {

	//
	//  Try setting an analysis option with an invalid name or value, and
	//  ensure that the correct behavior occurs.
	//

	// create a enum test option

	int startTransaction = program.startTransaction("Test");
	Options options = program.getOptions(Program.ANALYSIS_PROPERTIES);
	options.setEnum("bob", TestEnum.a);
	program.endTransaction(startTransaction, true);

	GhidraScript script = getScript();

	String validOptionName = "bob";

	// Try to set a valid option to an invalid value and verify that the invalid value was not stored.
	String invalidValue = "d";
	script.setAnalysisOption(program, validOptionName, invalidValue);
	assertFalse(script.getCurrentAnalysisOptionsAndValues(program).get(validOptionName).equals(
		invalidValue));

	// Try to set an invalid option and verify that the option is not successfully set.
	String invalidOption = "invalidOption";
	String validValue = "__stdcall";
	script.setAnalysisOption(program, invalidOption, validValue);
	assertNull(script.getCurrentAnalysisOptionsAndValues(program).get(invalidOption));

	// Set more than one invalid name/option at a time, verify that none are successfully set
	Map<String, String> invalidOptionsAndValues = new HashMap<>();

	invalidOptionsAndValues.put(validOptionName, "d");
	invalidOptionsAndValues.put(invalidOption, invalidValue);

	script.setAnalysisOptions(program, invalidOptionsAndValues);
	Map<String, String> currentOptions = script.getCurrentAnalysisOptionsAndValues(program);
	assertNotNull(currentOptions.get(validOptionName));
	assertNull(currentOptions.get(invalidOption));
}