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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLoadedProgram(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.voidaddProgramToFixup(Program program) Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()is called.voidaddProgramToFixup(String programPath, Program program) Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()is called.voidclose()voidResolves any unresolved external symbols in each program that has been queued up viaaddProgramToFixup(String, Program).protected ProgramgetLibraryProgram(String libPath) Fetches a program from a cache of Program instances.getOrderedRequiredLibraryNames(Program program) Returns an ordered list of library names, as specified by the logic/rules of the original operating system's loader (eg.static StringgetRequiredLibraryProperty(int libraryIndex) Gets a program property name to represent the ordered required library of the given indexbooleanReturns true if there was an error encountered when trying to open an external library.voidLogs information about the libraries and symbols that were found during the fixup.protected ProgramopenLibraryFile(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
-
getOrderedRequiredLibraryNames
Returns an ordered list of library names, as specified by the logic/rules of the original operating system's loader (eg. Elf / MachO dynamic library loading / symbol resolving rules)- Parameters:
program- TheProgram- Returns:
- list of library names, in original order
-
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-Programto fix
-
addProgramToFixup
Queues a program into this session that will be fixed whenfixUnresolvedExternalSymbols()is called.- Parameters:
programPath- string project path to the programprogram-Programto 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:
closein interfaceAutoCloseable- Specified by:
closein 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
-