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

The following examples show how to use ghidra.program.model.symbol.Symbol#getParentNamespace() . 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: NXProgramBuilder.java    From Ghidra-Switch-Loader with ISC License 5 votes vote down vote up
private Symbol checkPrimary(Symbol sym) 
{
    if (sym == null || sym.isPrimary()) 
    {
        return sym;
    }

    String name = sym.getName();
    Address addr = sym.getAddress();

    if (name.indexOf("@") > 0) { // <sym>@<version> or <sym>@@<version>
        return sym; // do not make versioned symbols primary
    }

    // if starts with a $, probably a markup symbol, like $t,$a,$d
    if (name.startsWith("$")) {
        return sym;
    }

    // if sym starts with a non-letter give preference to an existing symbol which does
    if (!Character.isAlphabetic(name.codePointAt(0))) {
        Symbol primarySymbol = program.getSymbolTable().getPrimarySymbol(addr);
        if (primarySymbol != null && primarySymbol.getSource() != SourceType.DEFAULT &&
            Character.isAlphabetic(primarySymbol.getName().codePointAt(0))) {
            return sym;
        }
    }

    SetLabelPrimaryCmd cmd = new SetLabelPrimaryCmd(addr, name, sym.getParentNamespace());
    if (cmd.applyTo(program)) {
        return program.getSymbolTable().getSymbol(name, addr, sym.getParentNamespace());
    }

    Msg.error(this, cmd.getStatusMsg());

    return sym;
}
 
Example 2
Source File: StackEditorProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean inCurrentFunction(DomainObjectChangeRecord record) {
	if (!(record instanceof ProgramChangeRecord)) {
		return false;
	}

	if (function == null) {
		return false; // not sure if this can happen
	}

	ProgramChangeRecord programChangeRecord = (ProgramChangeRecord) record;
	Object affectedValue = programChangeRecord.getObject();
	if (affectedValue instanceof Symbol) {
		Address address = ((Symbol) affectedValue).getAddress();
		if (address.isVariableAddress()) {
			Symbol s = (Symbol) affectedValue;
			return s.getParentNamespace() == function;
		}
	}
	else if (affectedValue instanceof Function) {
		Address changedEntry = ((Function) affectedValue).getEntryPoint();
		if (changedEntry.equals(function.getEntryPoint())) {
			return true;
		}
	}

	return false;
}
 
Example 3
Source File: NamespaceCategoryNode.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean supportsSymbol(Symbol symbol) {
	if (super.supportsSymbol(symbol)) {
		return true;
	}

	// must be in a non-global namespace
	Namespace parentNamespace = symbol.getParentNamespace();
	return parentNamespace != null && parentNamespace != globalNamespace;
}
 
Example 4
Source File: AbstractVTMatchTableModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(GTableCellRenderingData data) {

	Object value = data.getValue();

	DisplayableLabel displayableLabel = (DisplayableLabel) value;
	String labelString = displayableLabel.getDisplayString();

	GTableCellRenderingData renderData = data.copyWithNewValue(labelString);

	JLabel renderer = (JLabel) super.getTableCellRendererComponent(renderData);
	renderer.setToolTipText(null);

	Symbol symbol = displayableLabel.getSymbol();
	if (symbol != null) {
		Namespace parentNamespace = symbol.getParentNamespace();
		if (!parentNamespace.isGlobal()) {
			renderer.setToolTipText(symbol.getName(true));
		}
		if (symbolInspector != null) {
			symbolInspector.setProgram(symbol.getProgram());
			renderer.setForeground(symbolInspector.getColor(symbol));
		}
	}
	else {
		renderer.setForeground(Color.RED);
	}

	renderer.setOpaque(true);
	setBold();

	return renderer;
}
 
Example 5
Source File: AbstractVTMatchTableModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(GTableCellRenderingData data) {

	Object value = data.getValue();

	DisplayableLabel displayableLabel = (DisplayableLabel) value;
	String labelString = displayableLabel.getDisplayString();

	GTableCellRenderingData renderData = data.copyWithNewValue(labelString);

	JLabel renderer = (JLabel) super.getTableCellRendererComponent(renderData);
	renderer.setToolTipText(null);

	Symbol symbol = displayableLabel.getSymbol();
	if (symbol != null) {
		Namespace parentNamespace = symbol.getParentNamespace();
		if (!parentNamespace.isGlobal()) {
			renderer.setToolTipText(symbol.getName(true));
		}
		if (symbolInspector != null) {
			symbolInspector.setProgram(symbol.getProgram());
			renderer.setForeground(symbolInspector.getColor(symbol));
		}
	}
	else {
		renderer.setForeground(Color.RED);
	}

	renderer.setOpaque(true);
	setBold();

	return renderer;
}