Class AbstractLibrarySupportLoader
- All Implemented Interfaces:
Loader,ExtensionPoint,Comparable<Loader>
- Direct Known Subclasses:
AbstractOrdinalSupportLoader,CoffLoader,ElfLoader,MachoLoader,MzLoader
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordA library search pathprotected static final recordA library that has not been processed by the loader yetNested classes/interfaces inherited from interface ghidra.app.util.opinion.Loader
Loader.ImporterSettings -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringHow many levels of libraries to loadstatic final StringPath of aDomainFolderto save libraries to.static final StringA dummy option used to produce a custom renderer to select library search paths.static final Stringstatic final StringPath of aDomainFolderto search for librariesstatic final StringWhether or not to search for libraries on disk (or in aGFileSystem)static final StringA hidden option used by theImporterPlugin's "Load Libraries" action to inform thisLoaderthat theProgramto import has already been saved to the project and is currently open, and that only libraries should be loaded.static final StringFields inherited from class ghidra.app.util.opinion.AbstractProgramLoader
ANCHOR_LABELS_OPTION_NAME, APPLY_LABELS_OPTION_NAMEFields inherited from interface ghidra.app.util.opinion.Loader
COMMAND_LINE_ARG_PREFIX, loggingDisabled, OPTIONS_PROJECT_SAVE_STATE_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteProvidercreateLibraryByteProvider(FSRL libFsrl, LoadSpec loadSpec, MessageLog log, TaskMonitor monitor) Creates aByteProviderfor the given libraryFSRLfindLibraryInLoadedList(List<Loaded<Program>> loadedPrograms, String library) protected DomainFilefindLibraryInProject(String library, DomainFolder folder, List<AbstractLibrarySupportLoader.LibrarySearchPath> searchPaths, Loader.ImporterSettings settings) Find the library within the specifiedDomainFolder.getCustomLibrarySearchPaths(ByteProvider provider, List<Option> options, MessageLog log, TaskMonitor monitor) Gets aListof priority-ordered customAbstractLibrarySupportLoader.LibrarySearchPaths used to search for libraries.getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram, boolean mirrorFsLayout) Gets the defaultLoaderoptions.protected StringGets the project folder path to load the libraries into.protected DomainFoldergetLibraryDestinationSearchFolder(String libraryDestinationFolderPath, Loader.ImporterSettings settings) Gets theproject folderthat libraries are loaded into, to search for existing libraries.protected intgetLibraryLoadDepth(Loader.ImporterSettings settings) Gets the desired recursive library load depthprotected Comparator<String> Returns aComparatorfor comparing library names.protected List<DomainFolder> getLibrarySearchFolders(List<Loaded<Program>> loadedPrograms, Loader.ImporterSettings settings) getLibrarySearchPaths(Program program, Loader.ImporterSettings settings) Gets aListof priority-orderedAbstractLibrarySupportLoader.LibrarySearchPaths used to search for librariesprotected DomainFoldergetLinkSearchFolder(Program program, Loader.ImporterSettings settings) Gets theproject folderto search for existing librariesgetTier()For ordering purposes; lower tier numbers are more important (and listed first).intFor ordering purposes; lower numbers are more important (and listed first, within its tier).protected booleanChecks to see if existing libraries should be linkedprotected booleanisLoadLibraries(Loader.ImporterSettings settings) Checks to see if libraries from disk should be loadedprotected booleanisMirroredLayout(Loader.ImporterSettings settings) Checks to see if library organization mirrors filesystem layoutprotected booleanisValidSearchPath(FSRL fsrl, Loader.ImporterSettings settings) Checks to make sure the given search pathFSRLis valid before processing it.protected abstract voidload(Program program, Loader.ImporterSettings settings) Loads bytes in a particular format into the givenProgram.loadProgram(Loader.ImporterSettings settings) protected voidloadProgramInto(Program program, Loader.ImporterSettings settings) Loads program bytes into the specifiedProgram.protected DomainFilelookupLibraryInFolder(String libraryName, DomainFolder folder) Looks in the givenDomainFolderfor the given name using the loader'slibrary name comparatorprotected GFilelookupLibraryInFs(String library, GFileSystem fs) Looks in the givenGFileSystemfor the given library using the loader'slibrary name comparatorprotected LoadSpecmatchSupportedLoadSpec(LoadSpec desiredLoadSpec, ByteProvider provider) Ensures the givenLoadSpecmatches one supported by the loaderprotected voidpostLoadProgramFixups(List<Loaded<Program>> loadedPrograms, Loader.ImporterSettings settings) This gets called after the given list ofloaded programss is finished loading.protected voidprocessLibrary(Program library, String libraryName, FSRL libraryFsrl, Queue<AbstractLibrarySupportLoader.UnprocessedLibrary> unprocessed, int depth, Loader.ImporterSettings settings) Performs optional follow-on actions after an the given library has been loadedprotected booleanChecks to see if only libraries should be loaded (i.e., not the main program)protected booleanshouldSearchAllPaths(Program program, Loader.ImporterSettings settings) Checks whether or not to search for libraries using all possible search paths, regardless of what options are setvalidateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program) Validates theLoader's options and returns null if all options are valid; otherwise, an error message describing the problem is returned.Methods inherited from class ghidra.app.util.opinion.AbstractProgramLoader
addExternalBlock, createDefaultMemoryBlocks, createProgram, createProgram, generateBlockName, getLanguageService, load, loadInto, markAsFunction, postLoadCleanup, setProgramProperties, shouldApplyProcessorLabelsByDefaultMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ghidra.app.util.opinion.Loader
compareTo, findSupportedLoadSpecs, getName, getPreferredFileName, loadsIntoNewFolder, supportsLoadIntoProgram, supportsLoadIntoProgram
-
Field Details
-
LINK_EXISTING_OPTION_NAME
Option to attempt to fix up theLoadedProgram's external programs with libraries discovered in the project. This alone does not cause new library programs to be loaded.- See Also:
-
LINK_SEARCH_FOLDER_OPTION_NAME
Path of aDomainFolderto search for libraries- See Also:
-
LOAD_LIBRARY_OPTION_NAME
Whether or not to search for libraries on disk (or in aGFileSystem)- See Also:
-
LIBRARY_SEARCH_PATH_DUMMY_OPTION_NAME
A dummy option used to produce a custom renderer to select library search paths.- See Also:
-
DEPTH_OPTION_NAME
How many levels of libraries to load- See Also:
-
LIBRARY_DEST_FOLDER_OPTION_NAME
Path of aDomainFolderto save libraries to. This location will also be used as a location tosearch for already-loaded libraries.- See Also:
-
MIRROR_LAYOUT_OPTION_NAME
- See Also:
-
LOAD_ONLY_LIBRARIES_OPTION_NAME
A hidden option used by theImporterPlugin's "Load Libraries" action to inform thisLoaderthat theProgramto import has already been saved to the project and is currently open, and that only libraries should be loaded.- See Also:
-
-
Constructor Details
-
AbstractLibrarySupportLoader
public AbstractLibrarySupportLoader()
-
-
Method Details
-
load
protected abstract void load(Program program, Loader.ImporterSettings settings) throws CancelledException, IOException Loads bytes in a particular format into the givenProgram.- Parameters:
program- TheProgramto load into.settings- TheLoader.ImporterSettings- Throws:
IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.
-
loadProgram
protected List<Loaded<Program>> loadProgram(Loader.ImporterSettings settings) throws CancelledException, IOException Loads bytes in a particular format as a newLoadedProgram. MultiplePrograms may end up getting created, depending on the nature of the format.Note that when the load completes, the returned
LoadedPrograms are not saved to a project. That is the responsibility of the caller (seeLoaded.save(TaskMonitor)).It is also the responsibility of the caller to close the returned
LoadedPrograms withLoaded.close()when they are no longer needed.In addition to loading the given program bytes, this implementation will attempt to locate the libraries that the program links to from the
project library search folder, thelibrary destination folderand thelibraries found on disk. All of these locations are controlled by loader options.If the hidden
LOAD_ONLY_LIBRARIES_OPTION_NAMEoption is set and the given project is notnull, it is assumed that aDomainFileexists atprojectFolderPath/loadedName, is open, and the provider corresponds to its contents. If this is the case, the primary (first)LoadedProgramin the returned list will NOT be affected by aLoadResults.save(TaskMonitor)operation. It will be the responsibility of the user to save this open program if desired.- Specified by:
loadProgramin classAbstractProgramLoader- Parameters:
settings- TheLoader.ImporterSettings.- Returns:
- A
Listof one or moreLoadedPrograms (created but not saved). The first element in theListwill the primary program, with the remaining elements being any newly loaded libraries. - Throws:
LoadException- if the load failed in an unexpected way. If theLOAD_ONLY_LIBRARIES_OPTION_NAMEoption is set, this exception will be thrown if theDomainFileatprojectFolderPath/loadedNamedoes not correspond to an openProgram.CancelledException- if the user cancelled the load.IOException- if there was an IO-related problem loading.
-
loadProgramInto
protected void loadProgramInto(Program program, Loader.ImporterSettings settings) throws CancelledException, LoadException, IOException Description copied from class:AbstractProgramLoaderLoads program bytes into the specifiedProgram. This method will not create any newPrograms. It is only for adding to an existingProgram.NOTE: The loading that occurs in this method will automatically be done in a transaction.
- Specified by:
loadProgramIntoin classAbstractProgramLoader- Parameters:
program- TheProgramto load into.settings- TheLoader.ImporterSettings.- Throws:
CancelledException- if the user cancelled the load.LoadException- if the load failed in an expected way.IOException- if there was an IO-related problem loading.
-
postLoadProgramFixups
protected void postLoadProgramFixups(List<Loaded<Program>> loadedPrograms, Loader.ImporterSettings settings) throws CancelledException, IOException This gets called after the given list ofloaded programss is finished loading. It provides subclasses an opportunity to do follow-on actions to the load.Fix up program's external library entries so that they point to a path in the project.
- Overrides:
postLoadProgramFixupsin classAbstractProgramLoader- Parameters:
loadedPrograms- Theloaded programsto be fixed up.settings- TheLoader.ImporterSettings.- Throws:
CancelledException- if the user cancelled the load.IOException- if there was an IO-related problem loading.
-
getTier
Description copied from interface:LoaderFor ordering purposes; lower tier numbers are more important (and listed first).- Returns:
- the tier of the loader
-
getTierPriority
public int getTierPriority()Description copied from interface:LoaderFor ordering purposes; lower numbers are more important (and listed first, within its tier).- Returns:
- the ordering of the loader within its tier
-
getDefaultOptions
public List<Option> getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram, boolean mirrorFsLayout) Description copied from interface:LoaderGets the defaultLoaderoptions.- Specified by:
getDefaultOptionsin interfaceLoader- Overrides:
getDefaultOptionsin classAbstractProgramLoader- Parameters:
provider- The bytes of the thing being loaded.loadSpec- TheLoadSpec.domainObject- TheDomainObjectbeing loaded.loadIntoProgram- True if the load is adding to an existingDomainObject; otherwise, false.mirrorFsLayout- True if the filesystem layout should be mirrored when loading; otherwise, false- Returns:
- A list of the
Loader's default options.
-
validateOptions
public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program) Description copied from interface:LoaderValidates theLoader's options and returns null if all options are valid; otherwise, an error message describing the problem is returned.- Specified by:
validateOptionsin interfaceLoader- Overrides:
validateOptionsin classAbstractProgramLoader- Parameters:
provider- The bytes of the thing being loaded.loadSpec- The proposedLoadSpec.options- The list ofOptions to validate.program- existing program if the loader is adding to an existing program. If it is a fresh import, then this will be null.- Returns:
- null if all
Options are valid; otherwise, an error message describing the problem is returned.
-
isLinkExistingLibraries
Checks to see if existing libraries should be linked- Parameters:
settings- TheLoader.ImporterSettings- Returns:
- True if existing libraries should be linked; otherwise, false
-
getLinkSearchFolder
Gets theproject folderto search for existing libraries- Parameters:
program- TheProgrambeing loadedsettings- TheLoader.ImporterSettings- Returns:
- The path of the project folder to search for existing libraries, or null if no project folders can be or should be searched
-
isLoadLibraries
Checks to see if libraries from disk should be loaded- Parameters:
settings- TheLoader.ImporterSettings- Returns:
- True if libraries from disk should be loaded; otherwise, false
-
isMirroredLayout
Checks to see if library organization mirrors filesystem layout- Parameters:
settings- TheLoader.ImporterSettings- Returns:
- True if library organization mirrors filesystem layout; false if flat layout
-
shouldLoadOnlyLibraries
Checks to see if only libraries should be loaded (i.e., not the main program)- Parameters:
settings- TheLoader.ImporterSettings- Returns:
- True if only libraries should be loaded; otherwise, false
-
getLibraryLoadDepth
Gets the desired recursive library load depth- Parameters:
settings- TheLoader.ImporterSettings- Returns:
- The desired recursive library load depth
-
getLibraryDestinationFolderPath
Gets the project folder path to load the libraries into. It does not have to exist in the project yet.- Parameters:
settings- TheLoader.ImporterSettings- Returns:
- The path of the project folder to load the libraries into. Could be null if the specified project is null or a destination folder path could not be determined.
-
getLibraryDestinationSearchFolder
protected DomainFolder getLibraryDestinationSearchFolder(String libraryDestinationFolderPath, Loader.ImporterSettings settings) Gets theproject folderthat libraries are loaded into, to search for existing libraries. It will only be returned if the options to load new libraries into the project are set.- Parameters:
libraryDestinationFolderPath- The path of the project folder to load the libraries into. Could be null (@see #getLibraryDestinationFolderPath(Project, String, List)).settings- TheLoader.ImporterSettings- Returns:
- The path of the destination project folder to search for existing libraries, or null if the destination folder is not being used or should not be searched
-
getLibrarySearchFolders
protected List<DomainFolder> getLibrarySearchFolders(List<Loaded<Program>> loadedPrograms, Loader.ImporterSettings settings) - Parameters:
loadedPrograms- the list ofLoadedProgramssettings- TheLoader.ImporterSettings- Returns:
- A
Listof library searchfoldersbased on the current options
-
shouldSearchAllPaths
Checks whether or not to search for libraries using all possible search paths, regardless of what options are set- Parameters:
program- TheProgrambeing loadedsettings- TheLoader.ImporterSettings- Returns:
- True if all possible search paths should be used, regardless of what options are set
-
createLibraryByteProvider
protected ByteProvider createLibraryByteProvider(FSRL libFsrl, LoadSpec loadSpec, MessageLog log, TaskMonitor monitor) throws IOException, CancelledException Creates aByteProviderfor the given libraryFSRL- Parameters:
libFsrl- The libraryFSRLto get aByteProviderforloadSpec- An optionalLoadSpectheByteProvidershould conform tolog- The logmonitor- A cancellable monitor- Returns:
- A
ByteProviderfor the given libraryFSRL, or null if one could not be created that matches the givenLoadSpec - Throws:
IOException- If there was an IO-related issueCancelledException- If the user cancelled the operation
-
processLibrary
protected void processLibrary(Program library, String libraryName, FSRL libraryFsrl, Queue<AbstractLibrarySupportLoader.UnprocessedLibrary> unprocessed, int depth, Loader.ImporterSettings settings) throws IOException, CancelledException Performs optional follow-on actions after an the given library has been loaded- Parameters:
library- The loaded libraryProgramlibraryName- The name of the librarylibraryFsrl- The libraryFSRLunprocessed- TheQueueofunprocessed librariesdepth- The load depth of the library to loadsettings- TheLoader.ImporterSettings- Throws:
IOException- If an IO-related error occurredCancelledException- If the user cancelled the action
-
findLibraryInProject
protected DomainFile findLibraryInProject(String library, DomainFolder folder, List<AbstractLibrarySupportLoader.LibrarySearchPath> searchPaths, Loader.ImporterSettings settings) throws CancelledException Find the library within the specifiedDomainFolder.If the library path is a simple name without any path separators, only the given folder will be searched.
If the library path has a path, it will be treated as a relative path under given folder and if found that
DomainFilewill be returned.If the library path has a path and it wasn't found under the given folder, the filename part of library path will be used to search the given folder for matches.
- Parameters:
library- The library to find. Depending on the type of library, this could be a simple filename or an absolute path.folder-root folderwithin which imported libraries will be searched. If null this method will return null.searchPaths- AListofAbstractLibrarySupportLoader.LibrarySearchPaths that will be searchedsettings- TheLoader.ImporterSettings- Returns:
- The found
DomainFileor null if not found - Throws:
CancelledException- if the user cancelled the load
-
lookupLibraryInFolder
Looks in the givenDomainFolderfor the given name using the loader'slibrary name comparator- Parameters:
libraryName- The library name to search for (no path included)folder- TheDomainFolderto search in- Returns:
- A matching library
DomainFile, ornullif one was not found
-
getCustomLibrarySearchPaths
protected List<AbstractLibrarySupportLoader.LibrarySearchPath> getCustomLibrarySearchPaths(ByteProvider provider, List<Option> options, MessageLog log, TaskMonitor monitor) throws CancelledException Gets aListof priority-ordered customAbstractLibrarySupportLoader.LibrarySearchPaths used to search for libraries. The default implementation of this method returns an emptyList. Subclasses can override it as needed.- Parameters:
provider- TheByteProviderof the program being loadedoptions- The optionslog- The logmonitor- A cancelable task monitor- Returns:
- A
Listof priority-ordered customAbstractLibrarySupportLoader.LibrarySearchPaths used to search for libraries - Throws:
CancelledException- if the user cancelled the load
-
isValidSearchPath
protected boolean isValidSearchPath(FSRL fsrl, Loader.ImporterSettings settings) throws CancelledException Checks to make sure the given search pathFSRLis valid before processing it. Subclasses can override it as needed.- Parameters:
fsrl- The search pathFSRLsettings- TheLoader.ImporterSettings- Returns:
- True is the search path is valid; otherwise, false
- Throws:
CancelledException- if the user cancelled the load
-
getLibrarySearchPaths
protected List<AbstractLibrarySupportLoader.LibrarySearchPath> getLibrarySearchPaths(Program program, Loader.ImporterSettings settings) throws CancelledException Gets aListof priority-orderedAbstractLibrarySupportLoader.LibrarySearchPaths used to search for libraries- Parameters:
program- TheProgrambeing loadedsettings- TheLoader.ImporterSettings- Returns:
- A
Listof priority-orderedAbstractLibrarySupportLoader.LibrarySearchPaths used to search for libraries - Throws:
CancelledException- if the user cancelled the load
-
findLibraryInLoadedList
-
matchSupportedLoadSpec
protected LoadSpec matchSupportedLoadSpec(LoadSpec desiredLoadSpec, ByteProvider provider) throws IOException Ensures the givenLoadSpecmatches one supported by the loader- Parameters:
desiredLoadSpec- The desiredLoadSpecprovider- The provider- Returns:
- A supported
LoadSpecthat matches the desired one, or null of none matched - Throws:
IOException- if there was an IO-related error
-
lookupLibraryInFs
Looks in the givenGFileSystemfor the given library using the loader'slibrary name comparator- Parameters:
library- The library. Depending on the type of library, this could be a simple filename or an absolute path.fs- Thefile systemto look in in- Returns:
- A matching library
GFile, ornullif one was not found - Throws:
IOException- If an IO-related problem occurred
-
getLibraryNameComparator
Returns aComparatorfor comparing library names.No assumptions should be made about whether the library name includes path information or not.
- Returns:
- a
Comparatorfor comparing library names
-