Package ghidra.app.util.opinion
Class AbstractLibrarySupportLoader
java.lang.Object
ghidra.app.util.opinion.AbstractProgramLoader
ghidra.app.util.opinion.AbstractLibrarySupportLoader
- All Implemented Interfaces:
Loader
,ExtensionPoint
,Comparable<Loader>
- Direct Known Subclasses:
AbstractOrdinalSupportLoader
,CoffLoader
,ElfLoader
,MachoLoader
,MzLoader
-
Nested Class Summary
Nested classes/interfaces inherited from class ghidra.app.util.opinion.AbstractProgramLoader
AbstractProgramLoader.LoadedProgram
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class ghidra.app.util.opinion.AbstractProgramLoader
ANCHOR_LABELS_OPTION_NAME, APPLY_LABELS_OPTION_NAME
Fields inherited from interface ghidra.app.util.opinion.Loader
COMMAND_LINE_ARG_PREFIX
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteProvider
createLibraryByteProvider
(File libFile, LoadSpec loadSpec, MessageLog log) Creates aByteProvider
for the given library filegetDefaultOptions
(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram) Gets the defaultLoader
options.protected DomainFolder
getLibraryDestinationFolder
(DomainFolder programFolder, List<Option> options) Gets theproject folder
to load the libraries intoprotected int
getLibraryLoadDepth
(List<Option> options) Gets the desired recursive library load depthprotected DomainFolder
getLinkSearchFolder
(DomainFolder programFolder, List<Option> options) Gets theproject folder
to search for existing librariesgetTier()
For ordering purposes; lower tier numbers are more important (and listed first).int
For ordering purposes; lower numbers are more important (and listed first, within its tier).protected boolean
Specifies if the library filenames specified by this loader should be exact case match or case-insensitive.protected boolean
isLinkExistingLibraries
(List<Option> options) Checks to see if existing libraries should be linkedprotected boolean
isLoadLocalLibraries
(List<Option> options) Checks to see if local libraries should be loaded.protected boolean
isLoadSystemLibraries
(List<Option> options) Checks to see if system libraries should be loaded.protected boolean
Specifies if this loader can refer to library filenames without filename extensions.protected abstract void
load
(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program, TaskMonitor monitor, MessageLog log) Loads bytes in a particular format into the givenProgram
.protected List<AbstractProgramLoader.LoadedProgram>
loadProgram
(ByteProvider provider, String programName, DomainFolder programFolder, LoadSpec loadSpec, List<Option> options, MessageLog log, Object consumer, TaskMonitor monitor) Loads program bytes in a particular format as a newProgram
.protected boolean
loadProgramInto
(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, Program program, TaskMonitor monitor) Loads program bytes into the specifiedProgram
.protected LoadSpec
matchSupportedLoadSpec
(LoadSpec desiredLoadSpec, ByteProvider provider) Ensures the givenLoadSpec
matches one supported by the loaderprotected void
postLoadProgramFixups
(List<AbstractProgramLoader.LoadedProgram> loadedPrograms, List<Option> options, MessageLog messageLog, TaskMonitor monitor) This gets called after the given list ofprograms
s is finished loading.protected boolean
processLibrary
(Program library, String libraryName, File libraryFile, ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor) Performs optional follow-on actions after an the given library has been loadedprotected boolean
shouldLoadLibrary
(String libraryName, File libraryFile, ByteProvider provider, LoadSpec desiredLoadSpec, MessageLog log) Checks whether or not the given library should be loaded.protected boolean
shouldSearchAllPaths
(List<Option> options) 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
createDefaultMemoryBlocks, createProgram, generateBlockName, getLanguageService, isOverrideMainProgramName, load, loadInto, markAsFunction, release, setProgramProperties, shouldApplyProcessorLabelsByDefault
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.app.util.opinion.Loader
compareTo, findSupportedLoadSpecs, getName, getPreferredFileName, supportsLoadIntoProgram
-
Field Details
-
LINK_EXISTING_OPTION_NAME
- See Also:
-
LINK_SEARCH_FOLDER_OPTION_NAME
- See Also:
-
LOCAL_LIBRARY_OPTION_NAME
- See Also:
-
SYSTEM_LIBRARY_OPTION_NAME
- See Also:
-
DEPTH_OPTION_NAME
- See Also:
-
LIBRARY_DEST_FOLDER_OPTION_NAME
- See Also:
-
-
Constructor Details
-
AbstractLibrarySupportLoader
public AbstractLibrarySupportLoader()
-
-
Method Details
-
load
protected abstract void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program, TaskMonitor monitor, MessageLog log) throws CancelledException, IOException Loads bytes in a particular format into the givenProgram
.- Parameters:
provider
- The bytes to load.loadSpec
- TheLoadSpec
to use during load.options
- The load options.program
- TheProgram
to load into.monitor
- A cancelable task monitor.log
- The message log.- Throws:
IOException
- if there was an IO-related problem loading.CancelledException
- if the user cancelled the load.
-
loadProgram
protected List<AbstractProgramLoader.LoadedProgram> loadProgram(ByteProvider provider, String programName, DomainFolder programFolder, LoadSpec loadSpec, List<Option> options, MessageLog log, Object consumer, TaskMonitor monitor) throws CancelledException, IOException Description copied from class:AbstractProgramLoader
Loads program bytes in a particular format as a newProgram
. MultipleProgram
s may end up getting created, depending on the nature of the format.- Specified by:
loadProgram
in classAbstractProgramLoader
- Parameters:
provider
- The bytes to load.programName
- The name of theProgram
that's being loaded.programFolder
- TheDomainFolder
where the loaded thing should be saved. Could be null if the thing should not be pre-saved.loadSpec
- TheLoadSpec
to use during load.options
- The load options.log
- The message log.consumer
- A consumer object forProgram
s generated.monitor
- A cancelable task monitor.- Returns:
- A list of
loaded programs
(element 0 corresponds to primary loadedProgram
). - Throws:
CancelledException
- if the user cancelled the load.IOException
- if there was an IO-related problem loading.
-
loadProgramInto
protected boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, Program program, TaskMonitor monitor) throws CancelledException, IOException Description copied from class:AbstractProgramLoader
Loads program bytes into the specifiedProgram
. This method will not create any newProgram
s. 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:
loadProgramInto
in classAbstractProgramLoader
- Parameters:
provider
- The bytes to load into theProgram
.loadSpec
- TheLoadSpec
to use during load.options
- The load options.log
- The message log.program
- TheProgram
to load into.monitor
- A cancelable task monitor.- Returns:
- True if the file was successfully loaded; otherwise, false.
- Throws:
CancelledException
- if the user cancelled the load.IOException
- if there was an IO-related problem loading.
-
postLoadProgramFixups
protected void postLoadProgramFixups(List<AbstractProgramLoader.LoadedProgram> loadedPrograms, List<Option> options, MessageLog messageLog, TaskMonitor monitor) throws CancelledException, IOException Description copied from class:AbstractProgramLoader
This gets called after the given list ofprograms
s is finished loading. It provides subclasses an opportunity to do follow-on actions to the load.- Overrides:
postLoadProgramFixups
in classAbstractProgramLoader
- Parameters:
loadedPrograms
- Theprograms
that got loaded.options
- The load options.messageLog
- The message log.monitor
- A cancelable task monitor.- Throws:
CancelledException
- if the user cancelled the load.IOException
- if there was an IO-related problem loading.
-
getTier
Description copied from interface:Loader
For 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:Loader
For 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) Description copied from interface:Loader
Gets the defaultLoader
options.- Specified by:
getDefaultOptions
in interfaceLoader
- Overrides:
getDefaultOptions
in classAbstractProgramLoader
- Parameters:
provider
- The bytes of the thing being loaded.loadSpec
- TheLoadSpec
.domainObject
- TheDomainObject
being loaded.loadIntoProgram
- True if the load is adding to an existingDomainObject
; 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:Loader
Validates theLoader
's options and returns null if all options are valid; otherwise, an error message describing the problem is returned.- Specified by:
validateOptions
in interfaceLoader
- Overrides:
validateOptions
in classAbstractProgramLoader
- Parameters:
provider
- The bytes of the thing being loaded.loadSpec
- The proposedLoadSpec
.options
- The list ofOption
s 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
Option
s are valid; otherwise, an error message describing the problem is returned.
-
isLinkExistingLibraries
Checks to see if existing libraries should be linked -
getLinkSearchFolder
Gets theproject folder
to search for existing libraries- Parameters:
programFolder
- TheDomainFolder
that the main program is being loaded intooptions
- aList
ofOption
s- Returns:
- The path of the project folder to search for existing libraries, or null if no project folders should be searched
-
isLoadLocalLibraries
Checks to see if local libraries should be loaded. Local libraries are libraries that live in the same directory as the imported program. -
isLoadSystemLibraries
Checks to see if system libraries should be loaded. System libraries are libraries that live in the directories specified in the GUI path list. -
getLibraryLoadDepth
Gets the desired recursive library load depth -
getLibraryDestinationFolder
protected DomainFolder getLibraryDestinationFolder(DomainFolder programFolder, List<Option> options) Gets theproject folder
to load the libraries into- Parameters:
programFolder
- TheDomainFolder
that the main program is being loaded intooptions
- aList
ofOption
s- Returns:
- The path of the project folder to load the libraries into
-
shouldSearchAllPaths
Checks whether or not to search for libraries using all possible search paths, regardless of what options are set -
isCaseInsensitiveLibraryFilenames
protected boolean isCaseInsensitiveLibraryFilenames()Specifies if the library filenames specified by this loader should be exact case match or case-insensitive.Derived loader classes should override this method and specify if the OS that normally handles this type of binary is case-insensitive.
- Returns:
- True if case-insensitive or false if case-sensitive.
-
isOptionalLibraryFilenameExtensions
protected boolean isOptionalLibraryFilenameExtensions()Specifies if this loader can refer to library filenames without filename extensions.Derived loader classes should override this method if library filename extensions are optional. If they are required, there is no need to override this method.
- Returns:
- True if library filename extensions are optional; otherwise, false
-
createLibraryByteProvider
protected ByteProvider createLibraryByteProvider(File libFile, LoadSpec loadSpec, MessageLog log) throws IOException Creates aByteProvider
for the given library file- Parameters:
libFile
- The library file to get aByteProvider
forloadSpec
- An optionalLoadSpec
theByteProvider
should conform tolog
- The log- Returns:
- A
ByteProvider
for the given library file, or null if one could not be created that matches the givenLoadSpec
- Throws:
IOException
- If there was an IO-related issue
-
shouldLoadLibrary
protected boolean shouldLoadLibrary(String libraryName, File libraryFile, ByteProvider provider, LoadSpec desiredLoadSpec, MessageLog log) throws IOException Checks whether or not the given library should be loaded.It may be appropriate to not load a specific library after examining its bytes.
- Parameters:
libraryName
- The name of the librarylibraryFile
- The libraryFile
provider
- The library bytesdesiredLoadSpec
- The desiredLoadSpec
log
- The log- Returns:
- True if the given library should be loaded; otherwise, false
- Throws:
IOException
- If an IO-related error occurred
-
processLibrary
protected boolean processLibrary(Program library, String libraryName, File libraryFile, ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor) throws IOException, CancelledException Performs optional follow-on actions after an the given library has been loaded- Parameters:
library
- The loaded libraryProgram
libraryName
- The name of the librarylibraryFile
- The libraryFile
provider
- The library bytesloadSpec
- TheLoadSpec
used for the loadoptions
- The optionslog
- The logmonitor
- A cancel.able monitor- Returns:
- True if the library should be saved to the project; otherwise, false
- Throws:
IOException
- If an IO-related error occurredCancelledException
- If the user cancelled the action
-
matchSupportedLoadSpec
protected LoadSpec matchSupportedLoadSpec(LoadSpec desiredLoadSpec, ByteProvider provider) throws IOException Ensures the givenLoadSpec
matches one supported by the loader- Parameters:
desiredLoadSpec
- The desiredLoadSpec
provider
- The provider- Returns:
- A supported
LoadSpec
that matches the desired one, or null of none matched - Throws:
IOException
- if there was an IO-related error
-