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

The following examples show how to use ghidra.program.model.symbol.Symbol#isExternal() . 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: EditLabelAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean isEnabledForContext(ListingActionContext context) {
	Symbol symbol = plugin.getSymbol(context);
	if (symbol != null) {
		if (symbol.isExternal()) {
			return false;
		}
		getPopupMenuData().setMenuItemName(EDIT_LABEL);
		return true;
	}
	if (LabelMgrPlugin.getComponent(context) != null) {
		getPopupMenuData().setMenuItemName(EDIT_FIELDNAME);
		return true;
	}
	return false;
}
 
Example 2
Source File: PinSymbolAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void actionPerformed(ProgramSymbolActionContext context) {
	Program program = context.getProgram();
	int transactionID = program.startTransaction("Pin Symbol(s)");
	try {
		for (Symbol symbol : context.getSymbols()) {
			if ((symbol instanceof CodeSymbol || symbol instanceof FunctionSymbol) &&
				!symbol.isExternal() && !symbol.isPinned()) {
				symbol.setPinned(true);
			}
		}
	}
	finally {
		program.endTransaction(transactionID, true);
	}
}
 
Example 3
Source File: SymbolTreeRootNode.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private GTreeNode findFunctionSymbolNode(SymbolNode key, boolean loadChildren,
		TaskMonitor monitor) {

	Symbol searchSymbol = key.getSymbol();
	if (searchSymbol.isExternal()) {
		// assumption: externals will always be in the Externals category
		return searchCategory(getExternalsNode(), key, loadChildren, monitor);
	}

	//@formatter:off
	List<SymbolCategoryNode> categories = Arrays.asList(
		getFunctionsNode(),
		getClassesNode(),
		getNamespacesNode()
	);
	//@formatter:on
	GTreeNode node = searchCategories(categories, key, loadChildren, monitor);
	return node;
}
 
Example 4
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 5
Source File: PinSymbolAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isEnabledForContext(ProgramSymbolActionContext context) {
	for (Symbol symbol : context.getSymbols()) {
		if ((symbol instanceof CodeSymbol || symbol instanceof FunctionSymbol) &&
			!symbol.isExternal() && !symbol.isPinned()) {
			return true;
		}
	}
	return false;
}
 
Example 6
Source File: SelectionAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isEnabledForContext(SymbolTreeActionContext context) {
	for (Symbol s : context.getSymbols()) {
		if (!s.isExternal()) {
			return true;
		}
	}
	return false;
}
 
Example 7
Source File: SelectionAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(SymbolTreeActionContext context) {
	AddressSet set = new AddressSet();
	for (Symbol symbol : context.getSymbols()) {
		if (symbol.isExternal()) {
			continue;
		}
		Object symbolObject = symbol.getObject();
		if (symbolObject instanceof Namespace) {
			Namespace namespace = (Namespace) symbolObject;
			set.add(namespace.getBody());
		}
		else if (symbolObject instanceof Variable) {
			ProgramLocation loc = symbol.getProgramLocation();
			set.addRange(loc.getAddress(), loc.getAddress());
		}
		else if (symbolObject instanceof CodeUnit) {
			CodeUnit cu = (CodeUnit) symbolObject;
			set.addRange(cu.getMinAddress(), cu.getMaxAddress());
		}
	}

	if (!set.isEmpty()) {
		plugin.firePluginEvent(new ProgramSelectionPluginEvent(plugin.getName(),
			new ProgramSelection(set), context.getProgram()));
	}
}
 
Example 8
Source File: ImportsCategoryNode.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean supportsSymbol(Symbol symbol) {
	return symbol.isExternal();
}