Java Code Examples for ghidra.program.model.symbol.Symbol#getSymbolType()

The following examples show how to use ghidra.program.model.symbol.Symbol#getSymbolType() . 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: EditThunkFunctionAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isEnabledForContext(ProgramActionContext context) {

	Program program = context.getProgram();
	if (program == null) {
		return false;
	}

	FunctionManager functionMgr = program.getFunctionManager();
	Function func;
	if (context instanceof ListingActionContext) {
		ListingActionContext listingContext = (ListingActionContext) context;
		func = functionMgr.getFunctionAt(listingContext.getAddress());
	}
	else if (context instanceof ProgramSymbolActionContext) {
		ProgramSymbolActionContext symbolContext = (ProgramSymbolActionContext) context;
		if (symbolContext.getSymbolCount() != 1) {
			return false;
		}
		Symbol s = symbolContext.getFirstSymbol();
		if (s == null || s.isExternal() || s.getSymbolType() != SymbolType.FUNCTION) {
			return false;
		}
		func = (Function) s.getObject();
	}
	else {
		return false;
	}
	return func != null;
}
 
Example 2
Source File: RevertThunkFunctionAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isEnabledForContext(ProgramActionContext context) {

	Program program = context.getProgram();
	if (program == null) {
		return false;
	}

	FunctionManager functionMgr = program.getFunctionManager();
	Function func;
	if (context instanceof ListingActionContext) {
		ListingActionContext listingContext = (ListingActionContext) context;
		func = functionMgr.getFunctionAt(listingContext.getAddress());
	}
	else if (context instanceof ProgramSymbolActionContext) {
		ProgramSymbolActionContext symbolContext = (ProgramSymbolActionContext) context;
		if (symbolContext.getSymbolCount() != 1) {
			return false;
		}
		Symbol s = symbolContext.getFirstSymbol();
		if (s == null || s.getSymbolType() != SymbolType.FUNCTION) {
			return false;
		}
		func = (Function) s.getObject();
	}
	else {
		return false;
	}
	return func != null && func.isThunk();
}
 
Example 3
Source File: SymbolTreeRootNode.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public GTreeNode findSymbolTreeNode(SymbolNode key, boolean loadChildren, TaskMonitor monitor) {

	//
	// The finding of nodes starts here, at the root.  Optimize searching by using the 
	// implicit knowledge of how the tree builds/stores symbols by their type:
	// -Function - search only the function nodes, no recursive searching		
	// -External function - search only the imports node, no recursive searching
	// -Params/Locals - find the function node, then search that node
	// -Classes - search the classes node, need recursive searching
	// -Namespaces - search the namespaces node, need recursive searching
	//

	Symbol searchSymbol = key.getSymbol();
	SymbolType type = searchSymbol.getSymbolType();
	if (type == FUNCTION) {
		return findFunctionSymbolNode(key, loadChildren, monitor);
	}
	else if (type == PARAMETER || type == LOCAL_VAR) {
		return findVariableSymbolNode(key, loadChildren, monitor);
	}
	else if (type == CLASS) {
		return findClassSymbol(key, loadChildren, monitor);
	}
	else if (type == LIBRARY || type == NAMESPACE) {
		return findNamespaceSymbol(key, loadChildren, monitor);
	}
	else if (type == LABEL) {
		return findCodeSymbol(key, loadChildren, monitor);
	}
	//else { GLOBAL, GLOBAL_VAR } // not sure where these end up

	return super.findSymbolTreeNode(key, loadChildren, monitor);
}
 
Example 4
Source File: ProgramManagerPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean gotoProgramRef(Program program, String ref) {
	if (ref == null) {
		return false;
	}

	String trimmedRef = ref.trim();
	if (trimmedRef.length() == 0) {
		return false;
	}
	List<Symbol> symbols = NamespaceUtils.getSymbols(trimmedRef, program);
	Symbol sym = symbols.isEmpty() ? null : symbols.get(0);

	ProgramLocation loc = null;
	if (sym != null) {
		SymbolType type = sym.getSymbolType();
		if (type == SymbolType.FUNCTION) {
			loc = new FunctionSignatureFieldLocation(sym.getProgram(), sym.getAddress());
		}
		else if (type == SymbolType.LABEL) {
			loc = new LabelFieldLocation(sym);
		}
	}
	else {
		Address addr = program.getAddressFactory().getAddress(trimmedRef);
		if (addr != null && addr.isMemoryAddress()) {
			loc = new CodeUnitLocation(program, addr, 0, 0, 0);
		}
	}
	if (loc == null) {
		Msg.showError(this, null, "Navigation Failed",
			"Referenced label/function not found: " + trimmedRef);
		return false;
	}

	firePluginEvent(new ProgramLocationPluginEvent(getName(), loc, program));

	return true;
}