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

The following examples show how to use ghidra.program.model.symbol.Symbol#getProgram() . 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: VariableLocation.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private Address getVariableAddress(Variable var) {
	Symbol sym = var.getSymbol();
	if (sym == null) {
		return Address.NO_ADDRESS; // auto-params have no symbol
	}
	if (sym.getProgram() != program) {
		// Attempt to locate corresponding variable symbol within the current program
		// to allow for use in Diff operations
		Symbol otherSym = SimpleDiffUtility.getVariableSymbol(sym, program);
		if (otherSym != null) {
			return otherSym.getAddress();
		}
		return Address.NO_ADDRESS;
	}
	return sym.getAddress();
}
 
Example 2
Source File: ShowSymbolReferencesAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private ProgramLocation getProgramLocation(SymbolNode symbolNode) {
	Symbol symbol = symbolNode.getSymbol();
	if (symbol instanceof FunctionSymbol) {
		return new FunctionSignatureFieldLocation(symbol.getProgram(), symbol.getAddress());
	}
	return symbol.getProgramLocation();
}
 
Example 3
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;
}