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

The following examples show how to use ghidra.framework.options.Options#getString() . 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: ELFExternalSymbolResolver.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private static Collection<String> getOrderedLibraryNamesNeeded(Program program) {
	TreeMap<Integer, String> orderLibraryMap = new TreeMap<>();
	Options options = program.getOptions(Program.PROGRAM_INFO);
	//List<String> sortedOptionNames = new ArrayList<>();
	for (String optionName : options.getOptionNames()) {
		if (!optionName.startsWith(ElfLoader.ELF_REQUIRED_LIBRARY_PROPERTY_PREFIX) ||
			!optionName.endsWith("]")) {
			continue;
		}
		String libName = options.getString(optionName, null);
		if (libName == null) {
			continue;
		}
		String indexStr =
			optionName.substring(ElfLoader.ELF_REQUIRED_LIBRARY_PROPERTY_PREFIX.length(),
				optionName.length() - 1).trim();
		try {
			orderLibraryMap.put(Integer.parseInt(indexStr), libName.trim());
		}
		catch (NumberFormatException e) {
			Msg.error(ELFExternalSymbolResolver.class,
				"Program contains invalid property: " + optionName);
		}
	}
	return orderLibraryMap.values();
}
 
Example 2
Source File: MachoBinaryAnalysisCommand.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canApply(Program program) {
	try {
		Options options = program.getOptions("Program Information");
		String format = options.getString("Executable Format", null);
		if (!BinaryLoader.BINARY_NAME.equals(format)) {
			return false;
		}
		Memory memory = program.getMemory();
		Address address = getAddress(program);
		int magic = memory.getInt(address);
		return MachConstants.isMagic(magic);
	}
	catch (Exception e) {
	}
	return false;
}
 
Example 3
Source File: PropertyListMergeManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Object getValue(Options options, String propertyName) {
	OptionType type = options.getType(propertyName);
	switch (type) {
		case BOOLEAN_TYPE:
			return options.getBoolean(propertyName, false) ? Boolean.TRUE : Boolean.FALSE;

		case DOUBLE_TYPE:
			return new Double(options.getDouble(propertyName, 0d));

		case INT_TYPE:
			return new Integer(options.getInt(propertyName, 0));

		case LONG_TYPE:
			return new Long(options.getLong(propertyName, 0L));

		case NO_TYPE:
			return null;

		case STRING_TYPE:
			return options.getString(propertyName, (String) null);

		case DATE_TYPE:
			return options.getDate(propertyName, (Date) null);

		default:
			return null;
	}
}
 
Example 4
Source File: ProgramDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String getCompiler() {
	String compiler = null;
	Options pl = getOptions(PROGRAM_INFO);
	compiler = pl.getString(COMPILER, UNKNOWN);
	return compiler == null ? UNKNOWN : compiler;
}
 
Example 5
Source File: DataTypeArchiveUtility.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * get a list of known applicable .GDT archives for the given program.
 * 
 * @param program - program to lookup archives for
 * @return list of archives that could apply to this program
 */
public static List<String> getArchiveList(Program program) {
	List<String> list = new ArrayList<String>();

	Options props = program.getOptions(Program.PROGRAM_INFO);
	String format = props.getString("Executable Format", "");

	int size = program.getAddressFactory().getDefaultAddressSpace().getSize();

	if (format.equals(PeLoader.PE_NAME) ||
		(format.equals(CoffLoader.COFF_NAME) && isVisualStudio(program))) {
		// TODO: add in win7/win10
		if (size == 64) {
			list.add("windows_vs12_64");
		}
		else {
			list.add("windows_vs12_32");
		}
	}
	else if (format.equals(MachoLoader.MACH_O_NAME)) {
		// list.add("Cocoa");  // no more cocoa puffs for you
		// TODO: should we have a 64/32 version?
		// TODO: multiple OSX versions
		list.add("mac_osx");
	}
	else if (size == 64) {
		list.add("generic_clib_64");
	}
	// everyone else gets generic clib that was parsed as 32 bit wordsize
	else {
		list.add("generic_clib");
	}
	return list;
}
 
Example 6
Source File: ProgramMappingService.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if there is a current open Ghidra {@link Program} that has metadata
 * that links it to the specified {@link FSRL}.
 * <p>
 * (ie. an open program has a MD5 or FSRL metadata value that matches the fsrl param.)
 *
 * @param fsrl {@link FSRL} to search for in open program info.
 * @return boolean true if found.
 */
public static boolean isFileOpen(FSRL fsrl) {
	String expectedMD5 = fsrl.getMD5();

	List<DomainFile> openDomainFiles = new ArrayList<>();
	AppInfo.getActiveProject().getProjectData().findOpenFiles(openDomainFiles);

	Object consumer = new Object();
	for (DomainFile df : openDomainFiles) {
		DomainObject openedDomainObject = df.getOpenedDomainObject(consumer);
		try {
			if (openedDomainObject instanceof Program) {
				Program program = (Program) openedDomainObject;
				Options propertyList = program.getOptions(Program.PROGRAM_INFO);
				String fsrlStr =
					propertyList.getString(ProgramMappingService.PROGRAM_SOURCE_FSRL, null);
				String md5 =
					propertyList.getString(ProgramMappingService.PROGRAM_METADATA_MD5, null);

				if ((expectedMD5 != null && expectedMD5.equals(md5)) ||
					fsrl.isEquivalent(fsrlStr)) {
					createAssociation(fsrl, program);
					return true;
				}
			}
		}
		finally {
			if (openedDomainObject != null && openedDomainObject.isUsedBy(consumer)) {
				openedDomainObject.release(consumer);
			}
		}
	}
	return false;
}
 
Example 7
Source File: GnuDemanglerAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void optionsChanged(Options options, Program program) {
	doSignatureEnabled = options.getBoolean(OPTION_NAME_APPLY_SIGNATURE, doSignatureEnabled);
	demangleOnlyKnownPatterns =
		options.getBoolean(OPTION_NAME_DEMANGLE_USE_KNOWN_PATTERNS, demangleOnlyKnownPatterns);

	useDeprecatedDemangler =
		options.getBoolean(OPTION_NAME_USE_DEPRECATED_DEMANGLER, useDeprecatedDemangler);

	demanglerParameters =
		options.getString(OPTION_NAME_DEMANGLER_PARAMETERS, demanglerParameters);
}
 
Example 8
Source File: PdbProgramAttributes.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public PdbProgramAttributes(Program program) {

		Options propList = program.getOptions(Program.PROGRAM_INFO);

		pdbGuid = propList.getString(PdbParserConstants.PDB_GUID, (String) null);
		pdbAge = propList.getString(PdbParserConstants.PDB_AGE, (String) null);
		pdbLoaded = propList.getBoolean(PdbParserConstants.PDB_LOADED, false);
		programAnalyzed = propList.getBoolean(Program.ANALYZED, false);
		pdbSignature = propList.getString(PdbParserConstants.PDB_SIGNATURE, (String) null);
		pdbFile = propList.getString(PdbParserConstants.PDB_FILE, (String) null);

		executablePath = program.getExecutablePath();

		createGuidAgeString();
	}
 
Example 9
Source File: PdbAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void optionsChanged(Options options, Program program) {
	String symbolPath =
		options.getString(SYMBOLPATH_OPTION_NAME, SYMBOLPATH_OPTION_DEFAULT_VALUE);
	setSymbolsRepositoryPath(symbolPath);

	Preferences.setProperty(PdbParser.PDB_STORAGE_PROPERTY, symbolPath);
	Preferences.store();

	includePeSpecifiedPdbPath =
		options.getBoolean(OPTION_NAME_INCLUDE_PE_PDB_PATH, includePeSpecifiedPdbPath);
}
 
Example 10
Source File: DyldCacheAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canAnalyze(Program program) {
	Options options = program.getOptions("Program Information");
	String format = options.getString("Executable Format", null);
	if (!BinaryLoader.BINARY_NAME.equals(format)) {
		return false;
	}
	return DyldCacheUtils.isDyldCache(program);
}
 
Example 11
Source File: ProgramDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String getExecutableSHA256() {
	String format = null;
	try {
		Options pl = getOptions(PROGRAM_INFO);
		format = pl.getString(EXECUTABLE_SHA256, (String) null);
	}
	catch (Exception e) {
	}
	return format == null ? UNKNOWN : format;
}
 
Example 12
Source File: ProgramDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String getExecutableMD5() {
	String format = null;
	try {
		Options pl = getOptions(PROGRAM_INFO);
		format = pl.getString(EXECUTABLE_MD5, (String) null);
	}
	catch (Exception e) {
	}
	return format == null ? UNKNOWN : format;
}
 
Example 13
Source File: ProgramDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String getExecutableFormat() {
	String format = null;
	try {
		Options pl = getOptions(PROGRAM_INFO);
		format = pl.getString(EXECUTABLE_FORMAT, (String) null);
	}
	catch (Exception e) {
	}
	return format == null ? UNKNOWN : format;
}
 
Example 14
Source File: VTSessionDB.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public String getDestinationProgramID() {
	Options properties = getOptions(PROGRAM_ID_PROPERTYLIST_NAME);
	return properties.getString(DESTINATION_PROGRAM_ID_PROPERTY_KEY, "");
}
 
Example 15
Source File: BasicCompilerSpec.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private String getPrototypeEvaluationModelChoice(Program program) {
	Options options = program.getOptions(DECOMPILER_PROPERTY_LIST_NAME);
	return options.getString(EVALUATION_MODEL_PROPERTY_NAME, (String) null);
}
 
Example 16
Source File: VTSessionDB.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public String getSourceProgramID() {
	Options properties = getOptions(PROGRAM_ID_PROPERTYLIST_NAME);
	return properties.getString(SOURCE_PROGRAM_ID_PROPERTY_KEY, "");
}
 
Example 17
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 18
Source File: VTControllerTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
   public void testPersistingControllerConfigState() throws Exception {

	// get out the correlator options
	AddressCorrelatorManager correlator = controller.getCorrelator();
	assertNotNull("The controller did not find any correlators", correlator);

	// set some options settings
	Options options = correlator.getOptions(LastResortAddressCorrelator.class);
	String testDefaultValue = "Test Default Value";
	String testOptionKey = "Test Option Name";
	String value = options.getString(testOptionKey, testDefaultValue);
	assertEquals(value, testDefaultValue);

	String firstNewOptionValue = "New Option Value";
	options.setString(testOptionKey, firstNewOptionValue);
	assertEquals(firstNewOptionValue, options.getString(testOptionKey, null));
	correlator.setOptions(LastResortAddressCorrelator.class, options);
	// save the options 
	SaveState saveState = new SaveState();
	controller.writeConfigState(saveState);

	// change the options
	String secondNewValue = "Second New Value";
	options.setString(testOptionKey, secondNewValue);
	correlator.setOptions(LastResortAddressCorrelator.class, options);

	// pull the values again and make sure they are still correct (that writing the config
	// state did not change the cached controller and options) 
	correlator = controller.getCorrelator();
	options = correlator.getOptions(LastResortAddressCorrelator.class);
	assertEquals(secondNewValue, options.getString(testOptionKey, null));

	// restore the options
	controller.readConfigState(saveState);

	// verify the settings
	// (we have to pull the correlator and options again, as changing the config state may 
	// change the cached values in the controller)
	correlator = controller.getCorrelator();
	options = correlator.getOptions(LastResortAddressCorrelator.class);
	assertEquals(firstNewOptionValue, options.getString(testOptionKey, null));
}
 
Example 19
Source File: CondenseFillerBytesAnalyzer.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void optionsChanged(Options options, Program program) {
	fillerValue = options.getString("Filler Value", fillerValue);
	minBytes = options.getInt("Minimum number of sequential bytes", minBytes);
}
 
Example 20
Source File: ElfLoader.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Getter for the {@link #ELF_ORIGINAL_IMAGE_BASE_PROPERTY} property.
 * 
 * @param program Ghidra program that has the property to get
 * @return Long value of the original image base, or null if the property is not present
 */
public static Long getElfOriginalImageBase(Program program) {
	Options props = program.getOptions(Program.PROGRAM_INFO);
	String oibStr = props.getString(ElfLoader.ELF_ORIGINAL_IMAGE_BASE_PROPERTY, null);
	return (oibStr != null) ? NumericUtilities.parseHexLong(oibStr) : null;
}