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

The following examples show how to use ghidra.framework.options.Options#setInt() . 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: 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 2
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 3
Source File: SearchTextPlugin1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void searchAllForPreview2(String buttonText)
		throws Exception, InterruptedException, InvocationTargetException {
	SearchTextDialog dialog = getDialog();
	JComponent container = dialog.getComponent();
	JTextField tf = findTextField(container);

	selectRadioButton(container, buttonText);
	selectCheckBox(container, "Functions");
	selectCheckBox(container, "Instruction Mnemonics");
	selectCheckBox(container, "Instruction Operands");
	deSelectCheckBox(container, "Comments");

	Options options = tool.getOptions("Tool");
	options.setInt("Search Limit", 50);

	setText(tf, "formatCount");
	searchAll(container);

	TableComponentProvider<?>[] providers = tableServicePlugin.getManagedComponents();
	assertEquals(1, providers.length);
	AddressBasedTableModel<?> model = (AddressBasedTableModel<?>) providers[0].getModel();
	assertTrue(tool.isVisible(providers[0]));
	assertTrue(getPreviewString(model, 0).startsWith("byte Stack[-0xc]:1 formatCount"));
	assertTrue(getPreviewString(model, 1).startsWith("MOV dword ptr [EBP + formatCount]"));
	assertTrue(getPreviewString(model, 2).startsWith("LEA EAX,[EBP + formatCount]"));
}
 
Example 4
Source File: CodeBrowserNavigationTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testXrefNaviagationMoreField() throws Exception {

	Options opt = getTool().getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	opt.setInt("XREFs Field" + Options.DELIMITER + "Maximum Number of XREFs to Display", 2);

	cb.goTo(new XRefFieldLocation(program, addr("1004010"), null, addr("1004030"), 2, 2));
	assertEquals(addr("1004010"), cb.getCurrentAddress());

	click(cb, 2);

	TableComponentProvider<?>[] providers = getProviders();
	assertEquals(1, providers.length);
	GhidraProgramTableModel<?> model = providers[0].getModel();
	waitForTableModel(model);
	assertEquals(3, model.getRowCount());

	runSwing(() -> providers[0].closeComponent());
}
 
Example 5
Source File: MemSearchHexTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testHighlightGroupSize() throws Exception {
	Options opt = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	opt.setInt(BytesFieldFactory.BYTE_GROUP_SIZE_MSG, 3);
	opt.setString(BytesFieldFactory.DELIMITER_MSG, "#@#");

	setValueText("fd ff ff");
	pressSearchAllButton();

	waitForSearch("Search Memory - ", 1);

	Highlight[] h = getByteHighlights(addr(0x10035f8), "b930fd#@#ffff");
	assertEquals(1, h.length);
	assertEquals(4, h[0].getStart());
	assertEquals(12, h[0].getEnd());

}
 
Example 6
Source File: PeLoader.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void processProperties(OptionalHeader optionalHeader, Program prog,
		TaskMonitor monitor) {
	if (monitor.isCancelled()) {
		return;
	}
	Options props = prog.getOptions(Program.PROGRAM_INFO);
	props.setInt("SectionAlignment", optionalHeader.getSectionAlignment());
	props.setBoolean(RelocationTable.RELOCATABLE_PROP_NAME,
		prog.getRelocationTable().getSize() > 0);
}
 
Example 7
Source File: EolCommentFieldFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Set the max number of lines to display for EOL comments.
 */
private void setMaximumLinesToDisplay(int maxLines, Options options) {
	if (maxLines < 1) {
		maxLines = 1;
		options.setInt(MAX_DISPLAY_LINES_MSG, maxLines);
	}
	maxDisplayLines = maxLines;
}
 
Example 8
Source File: OperandFieldHelper.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void setMaximumLinesToDisplay(int maxLines, Options options) {
	if (maxLines < 1) {
		maxLines = 1;
		options.setInt(MAX_DISPLAY_LINES_MSG, maxLines);
	}
	this.maxDisplayLines = maxLines;
}
 
Example 9
Source File: BytesFieldFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void setGroupSize(int n, Options options) {
	if (n < 1) {
		n = 1;
		options.setInt(BYTE_GROUP_SIZE_MSG, 1);
	}
	byteGroupSize = n;
}
 
Example 10
Source File: BytesFieldFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void setDisplayLines(int n, Options options) {
	if (n < 1) {
		n = 1;
		options.setInt(MAX_DISPLAY_LINES_MSG, 1);
	}
	maxDisplayLines = n;
}
 
Example 11
Source File: SearchTextPlugin2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaveState() {
	Options options = tool.getOptions("Search");
	options.setInt("Search Limit", 20);
	env.saveRestoreToolState();
	assertEquals(20, plugin.getResultsLimit());
}
 
Example 12
Source File: SearchTextPlugin3Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaveState() {
	Options options = tool.getOptions("Search");
	options.setInt("Search Limit", 20);
	env.saveRestoreToolState();
	assertEquals(20, plugin.getResultsLimit());
}
 
Example 13
Source File: CodeBrowserOptionsTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testBytesFieldOptions_DisplayStructureAlignmentBytesWithGrouping()
		throws Exception {

	showTool(tool);
	loadProgram();

	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	options.setBoolean("Bytes Field.Display Structure Alignment Bytes", true);
	options.setInt("Bytes Field.Byte Group Size", 2);

	Address addr = addr("0x1001100");
	cb.goTo(new BytesFieldLocation(program, addr, addr, new int[] { 1 }, 0)); // causes structure to open

	cb.goToField(addr("0x1001100"), "Bytes", 1, 0, 0);
	ListingTextField btf = (ListingTextField) cb.getCurrentField();
	assertEquals("0102 0304", btf.getText());
	assertEquals(10, btf.getNumCols(0));
	FieldElement fe = btf.getFieldElement(0, 1);
	assertEquals(BytesFieldFactory.DEFAULT_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 2);
	assertEquals(BytesFieldFactory.ALIGNMENT_BYTES_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 5);
	assertEquals(BytesFieldFactory.ALIGNMENT_BYTES_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 7);
	assertEquals(BytesFieldFactory.ALIGNMENT_BYTES_COLOR, fe.getColor(0));

	cb.goToField(addr("0x1001104"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("0506 0708", btf.getText());
	assertEquals(10, btf.getNumCols(0));
	fe = btf.getFieldElement(0, 1);
	assertEquals(BytesFieldFactory.DEFAULT_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 2);
	assertEquals(BytesFieldFactory.DEFAULT_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 5);
	assertEquals(BytesFieldFactory.DEFAULT_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 7);
	assertEquals(BytesFieldFactory.DEFAULT_COLOR, fe.getColor(0));

	cb.goToField(addr("0x1001108"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("090a 0b0c", btf.getText());
	assertEquals(10, btf.getNumCols(0));
	fe = btf.getFieldElement(0, 1);
	assertEquals(BytesFieldFactory.DEFAULT_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 2);
	assertEquals(BytesFieldFactory.ALIGNMENT_BYTES_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 5);
	assertEquals(BytesFieldFactory.ALIGNMENT_BYTES_COLOR, fe.getColor(0));
	fe = btf.getFieldElement(0, 7);
	assertEquals(BytesFieldFactory.ALIGNMENT_BYTES_COLOR, fe.getColor(0));
}
 
Example 14
Source File: JavaAnalyzer.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void recordJavaVersionInfo(Program program, ClassFileJava classFile) {
	Options programInfo = program.getOptions(Program.PROGRAM_INFO);
	programInfo.setInt("Major Version", classFile.getMajorVersion());
	programInfo.setInt("Minor Version", classFile.getMinorVersion());
	String javaVersion;
	switch (classFile.getMajorVersion()) {
		case 45:
			javaVersion = "1.1";
			break;
		case 46:
			javaVersion = "1.2";
			break;
		case 47:
			javaVersion = "1.3";
			break;
		case 48:
			javaVersion = "1.4";
			break;
		case 49:
			javaVersion = "1.5";
			break;
		case 50:
			javaVersion = "1.6";
			break;
		case 51:
			javaVersion = "1.7";
			break;
		case 52:
			javaVersion = "1.8";
			break;
		case 53:
			javaVersion = "9";
			break;
		case 54:
			javaVersion = "10";
			break;
		case 55:
			javaVersion = "11";
			break;
		case 56:
			javaVersion = "12";
			break;
		case 57:
			javaVersion = "13";
			break;
		default:
			javaVersion = "Unknown";
			break;
	}
	programInfo.setString("Java Version", javaVersion);
}
 
Example 15
Source File: CodeBrowserOptionsTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testBytesFieldOptions() throws Exception {

	showTool(tool);
	loadProgram();
	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	List<String> names = getOptionNames(options, "Bytes Field");
	assertEquals("Different number of byte options than expected:\n" + names + "\n\n", 6,
		names.size());
	assertEquals("Bytes Field.Byte Group Size", names.get(0));
	assertEquals("Bytes Field.Delimiter", names.get(1));
	assertEquals("Bytes Field.Display Structure Alignment Bytes", names.get(2));
	assertEquals("Bytes Field.Display in Upper Case", names.get(3));
	assertEquals("Bytes Field.Maximum Lines To Display", names.get(4));
	assertEquals("Bytes Field.Reverse Instruction Byte Ordering", names.get(5));

	// option 0 - Byte Group Size
	options.setInt(names.get(0), 2);
	cb.updateNow();
	cb.goToField(addr("0x1001000"), "Bytes", 0, 0);
	ListingTextField btf = (ListingTextField) cb.getCurrentField();
	assertEquals("0102 0304", btf.getText());

	// option 1 - Delimiter
	options.setString(names.get(1), "-");
	cb.updateNow();
	cb.goToField(addr("0x1001000"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("0102-0304", btf.getText());

	// option 2 - Display Structure Alignment Bytes
	//   see separate tests

	// option 3 - Display in Upper Case
	cb.goToField(addr("0x1001100"), "Bytes", 2, 0);
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("0102-0304-0506-0708-090a-0b0c", btf.getText());

	options.setBoolean(names.get(3), true);
	cb.updateNow();
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("0102-0304-0506-0708-090A-0B0C", btf.getText());

	// option 4 - Maximum Lines To Display
	cb.goToField(addr("0x100aef8"), "Bytes", 0, 0);
	cb.updateNow();
	StructureDataType struct = new StructureDataType("fred", 50);
	CreateDataCmd cmd = new CreateDataCmd(addr("0x100aef8"), struct);
	tool.execute(cmd, program);

	options.setInt(names.get(4), 3);
	cb.updateNow();
	cb.goToField(addr("0x100aef8"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals(3, getNumberOfLines(btf));

	// option 5 - Reverse Instruction Byte Ordering
	cb.goToField(addr("0x10038b1"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();

	assertEquals("85C0", btf.getText());

	options.setBoolean(names.get(5), true);
	cb.updateNow();
	cb.goToField(addr("0x10038b1"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();

	assertEquals("C085", btf.getText());

	options.setBoolean(names.get(5), false);
	cb.updateNow();
	cb.goToField(addr("0x10038b1"), "Bytes", 0, 0);
	btf = (ListingTextField) cb.getCurrentField();

	assertEquals("85C0", btf.getText());

}
 
Example 16
Source File: CommentsPluginTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testEolFieldToolInteraction() throws Exception {

	openX86ProgramInTool();

	PluginTool tool2 = env.launchAnotherDefaultTool();
	configureTool(tool2);

	env.connectTools(tool, tool2);
	env.connectTools(tool2, tool);
	env.open(program); // do this again now that the tools are in-sync

	Address addr = addr(0x01006420);
	sendProgramLocation(addr, CodeUnit.EOL_COMMENT);

	String comment = "Drag and Drop is a direct manipulation gesture\n" +
		"found in many Graphical User Interface\n" +
		"systems that provides a mechanism to transfer information\n" +
		"between two entities logically associated with\n" +
		"presentation elements in the GUI.\n";

	setAt(addr, CodeUnit.EOL_COMMENT, comment, "OK");

	setFieldWidth(browser, EolCommentFieldFactory.FIELD_NAME, 100);

	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	options.setBoolean(EolCommentFieldFactory.ENABLE_WORD_WRAP_MSG, true);
	options.setInt(EolCommentFieldFactory.MAX_DISPLAY_LINES_MSG, 100);

	runSwing(() -> tool.getToolFrame().setSize(800, 800));

	CodeBrowserPlugin browser2 = getPlugin(tool2, CodeBrowserPlugin.class);
	setFieldWidth(browser2, EolCommentFieldFactory.FIELD_NAME, 400);

	runSwing(() -> tool2.getToolFrame().setSize(1200, 800));

	browser.goToField(addr, EolCommentFieldFactory.FIELD_NAME, 17, 4);

	assertEquals(17, browser.getCurrentFieldLoction().getRow());
	assertEquals(4, browser.getCurrentFieldLoction().getCol());

	assertEquals(3, browser2.getCurrentFieldLoction().getRow());
	assertEquals(46, browser2.getCurrentFieldLoction().getCol());
}
 
Example 17
Source File: SearchTextPlugin2Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void closeToolDuringSearch2(String buttonText) throws Exception {
	SearchTextDialog tempDialog = getDialog();
	JComponent tempContainer = tempDialog.getComponent();
	JTextField tf = findTextField(tempContainer);
	selectRadioButton(tempContainer, buttonText);

	JCheckBox cb = (JCheckBox) findButton(tempContainer, "Functions");
	setSelected(cb);

	cb = (JCheckBox) findButton(tempContainer, "Labels");
	setSelected(cb);

	cb = (JCheckBox) findButton(tempContainer, "Instruction Mnemonics");
	setSelected(cb);

	cb = (JCheckBox) findButton(tempContainer, "Instruction Operands");
	setSelected(cb);

	cb = (JCheckBox) findButton(tempContainer, "Defined Data Mnemonics");
	setSelected(cb);

	cb = (JCheckBox) findButton(tempContainer, "Defined Data Values");
	setSelected(cb);

	goToService.goTo(new ProgramLocation(program, getAddr(0x01002c92)));

	Options options = tool.getOptions(ToolConstants.TOOL_OPTIONS);
	options.setInt("Search Limit", 20);

	setTextAndPressEnter(tf, "eax");

	waitForSearchTasks(tempDialog);

	ProgramManager pm = tool.getService(ProgramManager.class);
	runSwing(() -> pm.closeProgram(), true);
	env.restartTool();

	waitForSearchTasks(tempDialog);
	waitForSwing();
	assertFalse(tempDialog.isVisible());
	assertFalse(isEnabled(searchAction));
}
 
Example 18
Source File: SearchTextPlugin1Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void searchAllForPreview(String buttonText)
		throws Exception, InterruptedException, InvocationTargetException {
	SearchTextDialog dialog = getDialog();
	JComponent container = dialog.getComponent();
	JTextField tf = findTextField(container);

	selectRadioButton(container, buttonText);
	selectCheckBox(container, "Functions");
	selectCheckBox(container, "Instruction Mnemonics");
	selectCheckBox(container, "Instruction Operands");
	deSelectCheckBox(container, "Comments");

	Options options = tool.getOptions(ToolConstants.TOOL_OPTIONS);
	options.setInt("Search Limit", 50);

	setText(tf, "sscanf");
	searchAll(container);

	TableComponentProvider<?>[] providers = tableServicePlugin.getManagedComponents();
	assertEquals(1, providers.length);
	AddressBasedTableModel<?> model = (AddressBasedTableModel<?>) providers[0].getModel();
	assertTrue(tool.isVisible(providers[0]));

	String expectedString = "undefined sscanf";
	String previewString = getPreviewString(model, 0);
	boolean containsString = previewString.contains(expectedString);
	if (!containsString) {
		printDebug(model);
	}
	assertTrue("Did not find expected preview string in table.  Expected to contain \"" +
		expectedString + "\", but found: " + previewString, containsString);

	expectedString = "CALL sscanf";
	previewString = getPreviewString(model, 1);
	containsString = previewString.contains(expectedString);
	if (!containsString) {
		printDebug(model);
	}
	assertTrue("Did not find expected preview string in table.  Expected to contain \"" +
		expectedString + "\", but found: " + previewString, containsString);
}
 
Example 19
Source File: CodeBrowserOptionsTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testXrefFieldOptions() throws Exception {

	showTool(tool);
	loadProgram();
	Options options = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_FIELDS);
	List<String> names = getOptionNames(options, "XREFs Field");
	assertEquals("XREFs Field.Delimiter", names.get(0));
	assertEquals("XREFs Field.Display Local Block", names.get(1));
	assertEquals("XREFs Field.Display Namespace", names.get(2));
	assertEquals("XREFs Field.Display Reference Type", names.get(3));
	assertEquals("XREFs Field.Maximum Number of XREFs to Display", names.get(4));

	assertTrue(cb.goToField(addr("0x1003d9f"), "XRef", 0, 0));

	// test Delimiter
	options.setString(names.get(0), "/");
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x1003d9f"), "XRef", 0, 0));
	ListingTextField btf = (ListingTextField) cb.getCurrentField();
	assertTrue(btf.getText().indexOf("/") > 0);

	options.setString(names.get(0), ",");
	cb.updateNow();

	// test show function name
	assertTrue(cb.goToField(addr("0x10048b6"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("010048ae(j) ", btf.getFieldElement(0, 0).getText());

	// namespace options
	// -Display non-local
	// -Display local
	// -Use local namespace override
	NamespaceWrappedOption newCustomOption = new NamespaceWrappedOption();

	// show local namespace
	newCustomOption.setShowNonLocalNamespace(false);
	newCustomOption.setShowLocalNamespace(true);
	newCustomOption.setUseLocalPrefixOverride(false);
	options.setCustomOption(names.get(2), newCustomOption);
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x10048b6"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("doStuff:010048ae(j) ", btf.getFieldElement(0, 0).getText());

	// don't show local namespace
	newCustomOption.setShowLocalNamespace(false);
	options.setCustomOption(names.get(2), newCustomOption);
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x10048b6"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("010048ae(j) ", btf.getFieldElement(0, 0).getText());

	// local namespace override
	newCustomOption.setShowLocalNamespace(true);
	newCustomOption.setUseLocalPrefixOverride(true);
	String overrideName = "overrideMe";
	newCustomOption.setLocalPrefixText(overrideName);
	options.setCustomOption(names.get(2), newCustomOption);
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x10048b6"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals(overrideName + "010048ae(j) ", btf.getFieldElement(0, 0).getText());

	// test show block name
	options.setBoolean(names.get(1), false);
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x1008094"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals("01004990(R),", btf.getFieldElement(0, 0).getText());

	options.setBoolean(names.get(1), true);
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x1008094"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals(".text:01004990(R),", btf.getFieldElement(0, 0).getText());

	// test max Xrefs to display
	assertTrue(cb.goToField(addr("0x1003d9f"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals(9, btf.getNumRows());

	options.setInt(names.get(4), 3);
	cb.updateNow();
	assertTrue(cb.goToField(addr("0x1003d9f"), "XRef", 0, 0));
	btf = (ListingTextField) cb.getCurrentField();
	assertEquals(3, btf.getNumRows());
	assertTrue(btf.getText().endsWith("[more]"));
}
 
Example 20
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;
}