Class ExternalSymbolResolver

java.lang.Object
ghidra.program.util.ExternalSymbolResolver
All Implemented Interfaces:
Closeable, AutoCloseable

public class ExternalSymbolResolver extends Object implements Closeable
Moves dangling external function symbols found in the EXTERNAL/UNKNOWN namespace into the namespace of the external library that publishes a matching symbol.

This uses an ordered list of external library names that was attached to the program during import by the Elf or Macho loader (see REQUIRED_LIBRARY_PROPERTY_PREFIX).

  • Constructor Details

  • Method Details

    • getRequiredLibraryProperty

      public static String getRequiredLibraryProperty(int libraryIndex)
      Gets a program property name to represent the ordered required library of the given index
      Parameters:
      libraryIndex - The index of the required library
      Returns:
      A program property name to represent the ordered required library of the given index
    • addProgramToFixup

      public void addProgramToFixup(Program program)
      Queues a program into this session that will be fixed when fixUnresolvedExternalSymbols() is called.

      The program should be fully persisted to the project if using this method, otherwise use addProgramToFixup(String, Program) and specify the pathname the program will be saved to.

      Parameters:
      program - Program to fix
    • addProgramToFixup

      public void addProgramToFixup(String programPath, Program program)
      Queues a program into this session that will be fixed when fixUnresolvedExternalSymbols() is called.
      Parameters:
      programPath - string project path to the program
      program - Program to fix
    • addLoadedProgram

      public void addLoadedProgram(String programPath, Program program)
      Adds an already opened program to this session, allowing it to be used as an external library without needing to look it up in the current project.
      Parameters:
      programPath - project path to already opened program
      program - Program
    • hasProblemLibraries

      public boolean hasProblemLibraries()
      Returns true if there was an error encountered when trying to open an external library.
      Returns:
      boolean flag, true if there was a problem opening an external library
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • fixUnresolvedExternalSymbols

      public void fixUnresolvedExternalSymbols() throws CancelledException
      Resolves any unresolved external symbols in each program that has been queued up via addProgramToFixup(String, Program).
      Throws:
      CancelledException - if cancelled
    • logInfo

      public void logInfo(Consumer<String> logger, boolean shortSummary)
      Logs information about the libraries and symbols that were found during the fixup.
      Parameters:
      logger - consumer that will log a string
      shortSummary - boolean flag, if true individual symbol names will be omitted
    • getLibraryProgram

      protected Program getLibraryProgram(String libPath) throws CancelledException
      Fetches a program from a cache of Program instances. If the requested program isn't currently in the cache, it will be opened (if possible).

      This cache of programs are pinned by registering a consumer on the program, and will be released during close() of this ExternalSymbolServer instance.

      This cache is shared between all ProgramSymbolResolver instances (that were created by calling addProgramToFixup(String, Program)).

      Parameters:
      libPath - project path to a library program
      Returns:
      Program, or null if not found or other error during opening
      Throws:
      CancelledException - if cancelled
    • openLibraryFile

      protected Program openLibraryFile(DomainFile libDf, String libPath) throws CancelledException
      Opens a library binary.
      Parameters:
      libDf - optional, reference to a the DomainFile that was found in a project. If null (meaning a lookup in the project failed to find a matching file), libPath will be used when creating error strings that reference the problematic file
      libPath - project path for the DomainFile
      Returns:
      a opened Program
      Throws:
      CancelledException - if cancelled