Java Code Examples for ghidra.app.util.Option#getValue()

The following examples show how to use ghidra.app.util.Option#getValue() . 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: PeLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean shouldParseCliHeaders(List<Option> options) {
	if (options != null) {
		for (Option option : options) {
			String optName = option.getName();
			if (optName.equals(PARSE_CLI_HEADERS_OPTION_NAME)) {
				return (Boolean) option.getValue();
			}
		}
	}
	return PARSE_CLI_HEADERS_OPTION_DEFAULT;
}
 
Example 2
Source File: IntelHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program) {
	Address baseAddr = null;

	for (Option option : options) {
		String optName = option.getName();
		try {
			if (optName.equals(OPTION_NAME_BASE_ADDRESS)) {
				baseAddr = (Address) option.getValue();
				if (baseAddr == null) {
					return "Invalid base address";
				}
			}
			else if (optName.equals(OPTION_NAME_BLOCK_NAME)) {
				if (!String.class.isAssignableFrom(option.getValueClass())) {
					return OPTION_NAME_BLOCK_NAME + " must be a String";
				}
			}
			else if (optName.equals(OPTION_NAME_IS_OVERLAY)) {
				if (!Boolean.class.isAssignableFrom(option.getValueClass())) {
					return OPTION_NAME_IS_OVERLAY + " must be a boolean";
				}
			}
			else {
				return "Unknown option: " + optName;
			}
		}
		catch (ClassCastException e) {
			return "Invalid type for option: " + optName + " - " + e.getMessage();
		}
	}
	return null;
}
 
Example 3
Source File: IntelHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Address getBaseAddr(List<Option> options) {
	Address baseAddr = null;
	for (Option option : options) {
		String optName = option.getName();
		if (optName.equals(OPTION_NAME_BASE_ADDRESS)) {
			baseAddr = (Address) option.getValue();
		}
	}
	return baseAddr;
}
 
Example 4
Source File: IntelHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private String getBlockName(List<Option> options) {
	String blockName = "";
	for (Option option : options) {
		String optName = option.getName();
		if (optName.equals(OPTION_NAME_BLOCK_NAME)) {
			blockName = (String) option.getValue();
		}
	}
	return blockName;
}
 
Example 5
Source File: MotorolaHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
		Program program) {
	Address baseAddr = null;

	for (Option option : options) {
		String optName = option.getName();
		try {
			if (optName.equals(OPTION_NAME_BASE_ADDRESS)) {
				baseAddr = (Address) option.getValue();
				if (baseAddr == null) {
					return "Invalid base address";
				}
			}
			else if (optName.equals(OPTION_NAME_BLOCK_NAME)) {
				if (!String.class.isAssignableFrom(option.getValueClass())) {
					return OPTION_NAME_BLOCK_NAME + " must be a String";
				}
			}
			else if (optName.equals(OPTION_NAME_IS_OVERLAY)) {
				if (!Boolean.class.isAssignableFrom(option.getValueClass())) {
					return OPTION_NAME_IS_OVERLAY + " must be a boolean";
				}
			}
			else {
				return "Unknown option: " + optName;
			}
		}
		catch (ClassCastException e) {
			return "Invalid type for option: " + optName + " - " + e.getMessage();
		}
	}
	return null;
}
 
Example 6
Source File: MotorolaHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Address getBaseAddr(List<Option> options) {
	Address baseAddr = null;
	for (Option option : options) {
		String optName = option.getName();
		if (optName.equals(OPTION_NAME_BASE_ADDRESS)) {
			baseAddr = (Address) option.getValue();
		}
	}
	return baseAddr;
}
 
Example 7
Source File: MotorolaHexLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private String getBlockName(List<Option> options) {
	String blockName = "";
	for (Option option : options) {
		String optName = option.getName();
		if (optName.equals(OPTION_NAME_BLOCK_NAME)) {
			blockName = (String) option.getValue();
		}
	}
	return blockName;
}
 
Example 8
Source File: LoaderArgsOptionChooser.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public List<Option> choose(List<Option> optionChoices, AddressFactory addressFactory) {
	if (loaderArgs != null) {
		for (Pair<String, String> pair : loaderArgs) {
			String arg = pair.first, val = pair.second;
			boolean foundIt = false;
			for (Option option : optionChoices) {
				if (option.getArg() != null && arg.equalsIgnoreCase(option.getArg())) {
					Object oldVal = option.getValue();
					if (option.parseAndSetValueByType(val, addressFactory)) {
						Msg.info(AutoImporter.class, String.format(
							"Successfully applied \"%s\" to \"%s\" (old: \"%s\", new: \"%s\")",
								arg, option.getName(), oldVal, val));
					}
					else {
						Msg.error(AutoImporter.class, String.format(
							"Failed to apply \"%s\" to \"%s\" (old: \"%s\", bad: \"%s\")", arg,
							option.getName(), oldVal, val));
						return null;
					}
					foundIt = true;
					break;
				}
			}
			if (!foundIt) {
				Msg.error(AutoImporter.class, "Loader does not support " + arg + " argument");
				return null;
			}
		}
	}
	return optionChoices;
}
 
Example 9
Source File: XmlProgramOptions.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the options. This method is not for defining the options, but
 * rather for setting the values of options. If invalid options
 * are passed in, then OptionException should be thrown.
 * @param options the option values for XML
 * @throws OptionException if invalid options are passed in
 */
public void setOptions(List<Option> options) throws OptionException {
	for (Option option : options) {
		String optName = option.getName();
		Object optValue = option.getValue();

		if (!(optValue instanceof Boolean)) {
			throw new OptionException("Invalid type for option: " + optName);
		}

		boolean val = ((Boolean) optValue).booleanValue();

		if (optName.equals("Memory Blocks")) {
			setMemoryBlocks(val);
		}
		else if (optName.equals("Memory Contents")) {
			setMemoryContents(val);
		}
		else if (optName.equals("Overwrite Memory Conflicts")) {
			setOverwriteMemoryConflicts(val);
		}
		else if (optName.equals("Instructions")) {
			setInstructions(val);
		}
		else if (optName.equals("Data")) {
			setData(val);
		}
		else if (optName.equals("Overwrite Data Conflicts")) {
			setOverwriteDataConflicts(val);
		}
		else if (optName.equals("Symbols")) {
			setSymbols(val);
		}
		else if (optName.equals("Overwrite Symbol Conflicts")) {
			setOverwriteSymbolConflicts(val);
		}
		else if (optName.equals("Equates")) {
			setEquates(val);
		}
		else if (optName.equals("Comments")) {
			setComments(val);
		}
		else if (optName.equals("Properties")) {
			setProperties(val);
		}
		else if (optName.equals("Overwrite Property Conflicts")) {
			setOverwritePropertyConflicts(val);
		}
		else if (optName.equals("Bookmarks")) {
			setBookmarks(val);
		}
		else if (optName.equals("Overwrite Bookmark Conflicts")) {
			setOverwriteBookmarkConflicts(val);
		}
		else if (optName.equals("Trees")) {
			setTrees(val);
		}
		else if (optName.equals("References")) {
			setReferences(val);
		}
		else if (optName.equals("Overwrite Reference Conflicts")) {
			setOverwriteReferenceConflicts(val);
		}
		else if (optName.equals("Functions")) {
			setFunctions(val);
		}
		else if (optName.equals("Registers")) {
			setRegisters(val);
		}
		else if (optName.equals("Relocation Table")) {
			setRelocationTable(val);
		}
		else if (optName.equals("Entry Points")) {
			setEntryPoints(val);
		}
		else if (optName.equals("External Libraries")) {
			setExternalLibraries(val);
		}
		else {
			throw new OptionException("Unknown option: " + optName);
		}
	}
}