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

The following examples show how to use ghidra.program.model.symbol.Symbol#isDynamic() . 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: ProgramProviderContext.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public DataTypeComponent getDataTypeComponent(int offset) {
	Data data = getData(offset);
	if (data == null) {
		return null;
	}

	DataType dt = data.getDataType();
	int length = data.getLength();
	String label = null;
	Symbol symbol = data.getPrimarySymbol();
	if (symbol != null && !symbol.isDynamic()) {
		label = symbol.getName();
	}
	String comment = data.getComment(CodeUnit.EOL_COMMENT);
	return new DataTypeComponentImpl(dt, null, length, 0, offset, label, comment);

}
 
Example 2
Source File: LabelCodeUnitFormat.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected String getOffcutLabelStringForInstruction(Address offcutAddress,
		Instruction instruction) {
	Program program = instruction.getProgram();
	Symbol offsym = program.getSymbolTable().getPrimarySymbol(offcutAddress);
	Address instructionAddress = instruction.getMinAddress();
	long diff = offcutAddress.subtract(instructionAddress);
	if (!offsym.isDynamic()) {
		return getDefaultOffcutString(offsym, instruction, diff, true);
	}

	Symbol containingSymbol = program.getSymbolTable().getPrimarySymbol(instructionAddress);
	if (containingSymbol != null) {
		return containingSymbol.getName() + PLUS + diff;
	}
	return getDefaultOffcutString(offsym, instruction, diff, true);
}
 
Example 3
Source File: LabelCodeUnitFormat.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected String getOffcutDataString(Address offcutAddress, Data data) {
	Program program = data.getProgram();
	Symbol offcutSymbol = program.getSymbolTable().getPrimarySymbol(offcutAddress);
	Address dataAddress = data.getMinAddress();
	int diff = (int) offcutAddress.subtract(dataAddress);
	if (!offcutSymbol.isDynamic()) {
		return getDefaultOffcutString(offcutSymbol, data, diff, true);
	}

	DataType dt = data.getBaseDataType();
	String prefix = getPrefixForStringData(data, dataAddress, diff, dt);
	if (prefix != null) {
		String addressString = SymbolUtilities.getAddressString(dataAddress);
		return addOffcutInformation(prefix, addressString, diff, true);
	}

	return getDefaultOffcutString(offcutSymbol, data, diff, true);
}
 
Example 4
Source File: ProgramDnDTree.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a fragment name; if there is a symbol at the start
 * of the fragment, and if it is user defined, then use the label 
 * as the fragment name; otherwise, just use the address as the name.
 * @param addr first address of fragment
 * 
 * @return String name of fragment
 */
private String generateFragmentName(Address addr) {

	Symbol symbol = program.getSymbolTable().getPrimarySymbol(addr);
	if (symbol == null || symbol.isDynamic()) {
		return addr.toString();
	}
	return symbol.getName();
}
 
Example 5
Source File: SubsToFuncsScript.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	BlockModelService blockModelService = state.getTool().getService(BlockModelService.class);
	Listing listing = currentProgram.getListing();
	StringBuffer errorBuf = new StringBuffer();
	CodeBlockModel cbm = blockModelService.getActiveSubroutineModel();
	AddressSetView addrset =
		currentSelection == null ? (AddressSetView) currentProgram.getMemory()
				: currentSelection;
	CodeBlockIterator cbIter = cbm.getCodeBlocksContaining(addrset, monitor);
	while (cbIter.hasNext()) {
		CodeBlock block = cbIter.next();
		FunctionIterator fIter = listing.getFunctions(block, true);
		if (!fIter.hasNext()) {
			try {
				String name = "DEAD_" + block.getFirstStartAddress();
				Symbol symbol = getSymbolAt(block.getFirstStartAddress());
				if (symbol != null && !symbol.isDynamic()) {
					name = symbol.getName();
				}
				listing.createFunction(name, block.getFirstStartAddress(), block,
					SourceType.USER_DEFINED);
			}
			catch (Exception e) {
				errorBuf.append(e.toString() + "\n");
			}
		}
	}
	if (errorBuf.length() > 0) {
		println(errorBuf.toString());
	}
}
 
Example 6
Source File: LabelMarkupUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public static void removeDefaultLabels( Program destinationProgram, Address address ) {
    SymbolTable symbolTable = destinationProgram.getSymbolTable();
    Symbol[] symbols = symbolTable.getSymbols( address );
    for ( Symbol symbol : symbols ) {
        if ( symbol instanceof FunctionSymbol ) {
            continue;
        }
        
        if ( !symbol.isDynamic() ) {
            continue;
        }
        
        symbolTable.removeSymbolSpecial( symbol );
    }
}
 
Example 7
Source File: RemoveLabelAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
boolean isOnSymbol(ListingActionContext context) {
	Symbol s = plugin.getSymbol(context);
	return ((s instanceof CodeSymbol) && !s.isDynamic()) ||
		((s instanceof FunctionSymbol) && s.getSource() != SourceType.DEFAULT);
}