Java Code Examples for ghidra.program.database.ProgramDB#getFunctionManager()

The following examples show how to use ghidra.program.database.ProgramDB#getFunctionManager() . 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: ChangeFunctionTagCmd.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj) {
	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManagerDB = (FunctionManagerDB) program.getFunctionManager();
	FunctionTagManager functionTagManager = functionManagerDB.getFunctionTagManager();
	FunctionTag tag = functionTagManager.getFunctionTag(tagName);

	if (tag == null) {
		errorMsg = "Function Tag not found: " + tagName;
		return false;
	}

	if (field == TAG_NAME_CHANGED) {
		tag.setName(newVal);
	}
	else {
		tag.setComment(newVal);
	}

	return true;
}
 
Example 2
Source File: ExternalManagerDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * @see ghidra.program.database.ManagerDB#setProgram(ghidra.program.database.ProgramDB)
 */
@Override
public void setProgram(ProgramDB program) {
	this.program = program;
	symbolMgr = (SymbolManager) program.getSymbolTable();
	functionMgr = (FunctionManagerDB) program.getFunctionManager();
	scopeMgr = program.getNamespaceManager();
}
 
Example 3
Source File: DeleteFunctionTagCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj, TaskMonitor monitor) {

	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManager = (FunctionManagerDB) program.getFunctionManager();
	FunctionTag tag = functionManager.getFunctionTagManager().getFunctionTag(tagName);

	if (tag != null) {
		tag.delete();
	}

	return true;
}
 
Example 4
Source File: RemoveFunctionTagCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj) {
	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManagerDB = (FunctionManagerDB) program.getFunctionManager();
	Function function = functionManagerDB.getFunctionAt(entryPoint);
	function.removeTag(tagName);

	// The remove function does not return a success/fail statutus, so just return 
	// and move on.
	return true;
}
 
Example 5
Source File: AddFunctionTagCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj) {
	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManagerDB = (FunctionManagerDB) program.getFunctionManager();
	Function function = functionManagerDB.getFunctionAt(entryPoint);

	if (function == null) {
		errorMsg = "Function not found at: " + entryPoint.toString();
		return false;
	}

	return function.addTag(tagName);
}
 
Example 6
Source File: CreateFunctionTagCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj) {
	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManagerDB = (FunctionManagerDB) program.getFunctionManager();
	FunctionTagManager functionTagManager = functionManagerDB.getFunctionTagManager();
	functionTagManager.createFunctionTag(name, comment);
	return true;
}
 
Example 7
Source File: CallTreePluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void ensureFunction(long from) throws Exception {
	ProgramDB p = builder.getProgram();
	FunctionManager fm = p.getFunctionManager();
	Function f = fm.getFunctionAt(addr(from));
	if (f != null) {
		return;
	}

	String a = Long.toHexString(from);
	builder.createEmptyFunction("Function_" + a, "0x" + a, 50, DataType.DEFAULT);
}
 
Example 8
Source File: GoToPluginTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private Program buildProgram_X86(String name) throws Exception {

		ClassicSampleX86ProgramBuilder builder =
			new ClassicSampleX86ProgramBuilder(name, false, this);

		//
		// Labels
		//
		builder.createLabel("0x010012f0", "comdlg32.dll_PageSetupDlgW");
		builder.createLabel("0x0100def8", "rsrc_String_3_3fe");
		builder.createLabel("0x0100e2f8", "rsrc_String_1_24a");
		builder.createLabel("0x0100eb90", "rsrc_String_4_5c8");

		//
		// String data
		//
		// "fSavePageSettings"
		builder.setBytes("0x10015a4", "66 00 53 00 61 00 76 00 65 00 50 00 61 00 67 00 65 00 " +
			"53 00 65 00 74 00 74 00 69 00 6e 00 67 00 73 00");
		// "GDI32.dll"
		builder.setBytes("0x010070bc", "47 44 49 33 32 2e 64 6c 6c 00");

		// create an arbitrary reference in order to create a default label
		builder.applyDataType("0x010070bc", new TerminatedStringDataType(), 1);
		builder.createMemoryReadReference("0x01006420", "0x010070bc");
		builder.setBytes("0x1002000", "01 02 03 04 05 06 07 08");
		builder.applyDataType("0x1002000", new PointerDataType());
		builder.createExternalReference("0x1002000", "extlib", "rand", 0);
		//
		// Local variable for testing go to
		//

		ProgramDB p = builder.getProgram();
		int txID = p.startTransaction("All Local Variable");
		try {
			FunctionManager fm = p.getFunctionManager();
			Function f = fm.getFunctionAt(builder.addr("0x01006420"));
			ByteDataType dt = new ByteDataType();
			Variable var = new LocalVariableImpl("bob.local", 0, dt, builder.addr("0x01006421"), p);
			f.addLocalVariable(var, SourceType.USER_DEFINED);

		}
		finally {
			p.endTransaction(txID, true);
		}

		return p;
	}