Java Code Examples for ghidra.program.model.symbol.Symbol#getSource()
The following examples show how to use
ghidra.program.model.symbol.Symbol#getSource() .
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: FindUndefinedFunctionsScript.java From ghidra with Apache License 2.0 | 6 votes |
boolean isMatch(Address undefinedAddress) throws MemoryAccessException { byte[] actualBytes = new byte[expectedBytes.length]; currentProgram.getMemory().getBytes(undefinedAddress, actualBytes); if (equals(expectedBytes, actualBytes)) { if (requiresEntyPoint) { // return currentProgram.getSymbolTable().isExternalEntryPoint(undefinedAddress); Symbol primarySymbol = currentProgram.getSymbolTable().getPrimarySymbol(undefinedAddress); return (primarySymbol != null) && (primarySymbol.getSource() == SourceType.IMPORTED); } return true; } return false; }
Example 2
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 5 votes |
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 3
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 5 votes |
public boolean hasImportedSymbol(Address addr) { for (Symbol sym : program.getSymbolTable().getSymbols(addr)) { if (sym.getSource() == SourceType.IMPORTED) return true; } return false; }
Example 4
Source File: IPCAnalyzer.java From Ghidra-Switch-Loader with ISC License | 5 votes |
public boolean hasImportedSymbol(Program program, Address addr) { for (Symbol sym : program.getSymbolTable().getSymbols(addr)) { if (sym.getSource() == SourceType.IMPORTED) return true; } return false; }
Example 5
Source File: NXProgramBuilder.java From Ghidra-Switch-Loader with ISC License | 4 votes |
private void evaluateElfSymbol(ElfSymbol elfSymbol, Address address, boolean isFakeExternal) { try { if (elfSymbol.isSection()) { // Do not add section symbols to program symbol table return; } String name = elfSymbol.getNameAsString(); if (name == null || name.isEmpty()) { return; } boolean isPrimary = (elfSymbol.getType() == ElfSymbol.STT_FUNC) || (elfSymbol.getType() == ElfSymbol.STT_OBJECT) || (elfSymbol.getSize() != 0); // don't displace existing primary unless symbol is a function or object symbol if (name.contains("@")) { isPrimary = false; // do not make version symbol primary } else if (!isPrimary && (elfSymbol.isGlobal() || elfSymbol.isWeak())) { Symbol existingSym = program.getSymbolTable().getPrimarySymbol(address); isPrimary = (existingSym == null); } this.createSymbol(address, name, isPrimary, elfSymbol.isAbsolute(), null); // NOTE: treat weak symbols as global so that other programs may link to them. // In the future, we may want additional symbol flags to denote the distinction if ((elfSymbol.isGlobal() || elfSymbol.isWeak()) && !isFakeExternal) { program.getSymbolTable().addExternalEntryPoint(address); } if (elfSymbol.getType() == ElfSymbol.STT_FUNC) { Function existingFunction = program.getFunctionManager().getFunctionAt(address); if (existingFunction == null) { Function f = createOneByteFunction(null, address, false); if (f != null) { if (isFakeExternal && !f.isThunk()) { ExternalLocation extLoc = program.getExternalManager().addExtFunction(Library.UNKNOWN, name, null, SourceType.IMPORTED); f.setThunkedFunction(extLoc.getFunction()); // revert thunk function symbol to default source Symbol s = f.getSymbol(); if (s.getSource() != SourceType.DEFAULT) { program.getSymbolTable().removeSymbolSpecial(f.getSymbol()); } } } } } } catch (DuplicateNameException | InvalidInputException e) { e.printStackTrace(); } }
Example 6
Source File: RemoveLabelAction.java From ghidra with Apache License 2.0 | 4 votes |
boolean isOnSymbol(ListingActionContext context) { Symbol s = plugin.getSymbol(context); return ((s instanceof CodeSymbol) && !s.isDynamic()) || ((s instanceof FunctionSymbol) && s.getSource() != SourceType.DEFAULT); }