Package ghidra.program.util
Class ExternalSymbolResolver
java.lang.Object
ghidra.program.util.ExternalSymbolResolver
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.void
addProgramToFixup
(Program program) Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()
is called.void
addProgramToFixup
(String programPath, Program program) Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()
is called.void
close()
void
Resolves any unresolved external symbols in each program that has been queued up viaaddProgramToFixup(String, Program)
.protected Program
getLibraryProgram
(String libPath) Fetches a program from a cache of Program instances.static String
getRequiredLibraryProperty
(int libraryIndex) Gets a program property name to represent the ordered required library of the given indexboolean
Returns true if there was an error encountered when trying to open an external library.void
Logs information about the libraries and symbols that were found during the fixup.protected Program
openLibraryFile
(DomainFile libDf, String libPath) Opens a library binary.
-
Constructor Details
-
ExternalSymbolResolver
-
-
Method Details
-
getRequiredLibraryProperty
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
Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()
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
Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()
is called.- Parameters:
programPath
- string project path to the programprogram
-Program
to fix
-
addLoadedProgram
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 programprogram
-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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
fixUnresolvedExternalSymbols
Resolves any unresolved external symbols in each program that has been queued up viaaddProgramToFixup(String, Program)
.- Throws:
CancelledException
- if cancelled
-
logInfo
Logs information about the libraries and symbols that were found during the fixup.- Parameters:
logger
- consumer that will log a stringshortSummary
- boolean flag, if true individual symbol names will be omitted
-
getLibraryProgram
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
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 filelibPath
- project path for the DomainFile- Returns:
- a opened
Program
- Throws:
CancelledException
- if cancelled
-