Class MachoLoader
- All Implemented Interfaces:
Loader
,ExtensionPoint
,Comparable<Loader>
Loader
for Mach-O files.-
Nested Class Summary
Nested classes/interfaces inherited from class ghidra.app.util.opinion.AbstractLibrarySupportLoader
AbstractLibrarySupportLoader.LibrarySearchPath, AbstractLibrarySupportLoader.UnprocessedLibrary
-
Field Summary
FieldsFields inherited from class ghidra.app.util.opinion.AbstractLibrarySupportLoader
DEPTH_OPTION_NAME, LIBRARY_DEST_FOLDER_OPTION_NAME, LIBRARY_SEARCH_PATH_DUMMY_OPTION_NAME, LINK_EXISTING_OPTION_NAME, LINK_SEARCH_FOLDER_OPTION_NAME, LOAD_LIBRARY_OPTION_NAME, LOAD_ONLY_LIBRARIES_OPTION_NAME
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, loggingDisabled, OPTIONS_PROJECT_SAVE_STATE_KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteProvider
createLibraryByteProvider
(FSRL libFsrl, LoadSpec loadSpec, MessageLog log, TaskMonitor monitor) Overrides the default implementation to account for Universal Binary (UBI) files.findSupportedLoadSpecs
(ByteProvider provider) If thisLoader
supports loading the givenByteProvider
, this methods returns aCollection
of all supportedLoadSpec
s that contain discovered load specification information that thisLoader
will need to load.getDefaultOptions
(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram) Gets the defaultLoader
options.getName()
protected boolean
isValidSearchPath
(FSRL fsrl, LoadSpec loadSpec, TaskMonitor monitor) Checks to make sure the given search pathFSRL
is valid before processing it.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 void
postLoadProgramFixups
(List<Loaded<Program>> loadedPrograms, Project project, LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor) This gets called after the given list ofloaded programs
s is finished loading.protected void
processLibrary
(Program lib, String libName, FSRL libFsrl, ByteProvider provider, Queue<AbstractLibrarySupportLoader.UnprocessedLibrary> unprocessed, int depth, LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor) Performs optional follow-on actions after an the given library has been loadedprotected FSRL
resolveLibraryFile
(GFileSystem fs, String library) Special Mach-O library file resolver to account for a "Versions" subdirectory being inserted in the library lookup path.protected boolean
shouldSearchAllPaths
(Program program, List<Option> options, MessageLog log) 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.AbstractLibrarySupportLoader
findLibraryInLoadedList, findLibraryInProject, getCustomLibrarySearchPaths, getLibraryDestinationFolderPath, getLibraryDestinationSearchFolder, getLibraryLoadDepth, getLibrarySearchFolders, getLibrarySearchPaths, getLinkSearchFolder, getTier, getTierPriority, isCaseInsensitiveLibraryFilenames, isLinkExistingLibraries, isLoadLibraries, isOptionalLibraryFilenameExtensions, loadProgram, loadProgramInto, matchSupportedLoadSpec, shouldLoadOnlyLibraries
Methods inherited from class ghidra.app.util.opinion.AbstractProgramLoader
createDefaultMemoryBlocks, createProgram, generateBlockName, getLanguageService, joinPaths, load, loadInto, markAsFunction, postLoadCleanup, 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, getPreferredFileName, loadsIntoNewFolder, supportsLoadIntoProgram, supportsLoadIntoProgram
-
Field Details
-
MACH_O_NAME
- See Also:
-
REEXPORT_OPTION_NAME
- See Also:
-
-
Constructor Details
-
MachoLoader
public MachoLoader()
-
-
Method Details
-
findSupportedLoadSpecs
Description copied from interface:Loader
If thisLoader
supports loading the givenByteProvider
, this methods returns aCollection
of all supportedLoadSpec
s that contain discovered load specification information that thisLoader
will need to load. If thisLoader
cannot support loading the givenByteProvider
, an emptyCollection
is returned.- Parameters:
provider
- The bytes being loaded.- Returns:
- A
Collection
ofLoadSpec
s that thisLoader
supports loading, or an emptyCollection
if thisLoader
doesn't support loading the givenByteProvider
. - Throws:
IOException
- if there was an IO-related issue finding theLoadSpec
s.
-
load
public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program, TaskMonitor monitor, MessageLog log) throws IOException Description copied from class:AbstractLibrarySupportLoader
Loads bytes in a particular format into the givenProgram
.- Specified by:
load
in classAbstractLibrarySupportLoader
- 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.
-
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 classAbstractLibrarySupportLoader
- 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 classAbstractLibrarySupportLoader
- 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.
-
getName
Description copied from interface:Loader
Gets theLoader
's name, which is used both for display purposes, and to identify theLoader
in the opinion files.- Returns:
- The
Loader
's name.
-
isValidSearchPath
protected boolean isValidSearchPath(FSRL fsrl, LoadSpec loadSpec, TaskMonitor monitor) throws CancelledException Description copied from class:AbstractLibrarySupportLoader
Checks to make sure the given search pathFSRL
is valid before processing it. Subclasses can override it as needed.- Overrides:
isValidSearchPath
in classAbstractLibrarySupportLoader
- Parameters:
fsrl
- The search pathFSRL
loadSpec
- TheLoadSpec
to use during load.monitor
- A cancelable task monitor- Returns:
- True is the search path is valid; otherwise, false
- Throws:
CancelledException
- if the user cancelled the load
-
createLibraryByteProvider
protected ByteProvider createLibraryByteProvider(FSRL libFsrl, LoadSpec loadSpec, MessageLog log, TaskMonitor monitor) throws IOException, CancelledException Overrides the default implementation to account for Universal Binary (UBI) files. These must be specially parsed to find the internal file matching the current architecture.FatHeader
is used to parse the file to determine if it is a UBI. If so, each file within the archive is run through the import process until one is found that is successful (meaning it matches the correct architecture). Only one file in the UBI will ever be imported. If the provided file is NOT a UBI, default import method will be invoked.
Creates aByteProvider
for the given libraryFSRL
- Overrides:
createLibraryByteProvider
in classAbstractLibrarySupportLoader
- Parameters:
libFsrl
- The libraryFSRL
to get aByteProvider
forloadSpec
- An optionalLoadSpec
theByteProvider
should conform tolog
- The logmonitor
- A cancellable monitor- Returns:
- A
ByteProvider
for 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
-
resolveLibraryFile
Special Mach-O library file resolver to account for a "Versions" subdirectory being inserted in the library lookup path. For example, a reference to:/System/Library/Frameworks/Foundation.framework/Foundation
might be found at:
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
Resolves the given library path to an existingFSRL
. SomeLoader
s have relaxed requirements on what counts as a valid library filename match. For example, case-insensitive lookup may be allowed, and filename extensions may be optional.- Overrides:
resolveLibraryFile
in classAbstractLibrarySupportLoader
- Parameters:
fs
- Thefile system
to resolve inlibrary
- The library. This will be either an absolute path, a relative path, or just a filename.- Returns:
- The library resolved to an existing
FSRL
, or null if it did not resolve - Throws:
IOException
- If an IO-related problem occurred
-
shouldSearchAllPaths
Checks whether or not to search for libraries using all possible search paths, regardless of what options are setIf we aren't loading libraries, we still want to search all paths if the reexport option is set and the Mach-O actually has
LC_REEXPORT_DYLIB
entries.- Overrides:
shouldSearchAllPaths
in classAbstractLibrarySupportLoader
- Parameters:
program
- TheProgram
being loadedoptions
- aList
ofOption
slog
- The log- Returns:
- True if all possible search paths should be used, regardless of what options are set
-
processLibrary
protected void processLibrary(Program lib, String libName, FSRL libFsrl, ByteProvider provider, Queue<AbstractLibrarySupportLoader.UnprocessedLibrary> unprocessed, int depth, LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor) throws IOException, CancelledException Performs optional follow-on actions after an the given library has been loadedThe goal here is to add each reexported library to the
unprocessed
list at the currentdepth
to be sure they get loaded. However, if the current depth is 1, we need to marked them as "discard" so we know not to save them in the end (since their actual depth would have prevented their save as a normal library)- Overrides:
processLibrary
in classAbstractLibrarySupportLoader
- Parameters:
lib
- The loaded libraryProgram
libName
- The name of the librarylibFsrl
- The libraryFSRL
provider
- The library bytesunprocessed
- TheQueue
ofunprocessed libraries
depth
- The load depth of the library to loadloadSpec
- TheLoadSpec
used for the loadoptions
- The optionslog
- The logmonitor
- A cancelable monitor- Throws:
IOException
- If an IO-related error occurredCancelledException
- If the user cancelled the action
-
postLoadProgramFixups
protected void postLoadProgramFixups(List<Loaded<Program>> loadedPrograms, Project project, LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor) throws CancelledException, IOException This gets called after the given list ofloaded programs
s 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:
postLoadProgramFixups
in classAbstractLibrarySupportLoader
- Parameters:
loadedPrograms
- Theloaded programs
to be fixed up.project
- TheProject
to load into. Could be null if there is no project.loadSpec
- TheLoadSpec
to use during load.options
- The load options.log
- 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.
-