Class AbstractProgramLoader
- All Implemented Interfaces:
Loader,ExtensionPoint,Comparable<Loader>
- Direct Known Subclasses:
AbstractLibrarySupportLoader,AbstractProgramWrapperLoader,BinaryLoader,DecompileDebugXmlLoader,IntelHexLoader,MotorolaHexLoader,XmlLoader
-
Nested Class Summary
Nested classes/interfaces inherited from interface ghidra.app.util.opinion.Loader
Loader.ImporterSettings -
Field Summary
FieldsFields 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 TypeMethodDescriptionstatic AddressaddExternalBlock(Program program, long size, MessageLog log) Adds theEXERNAL blockto memory, or adds to an existing oneprotected voidcreateDefaultMemoryBlocks(Program program, Loader.ImporterSettings settings) Creates default memory blocks for the givenProgram.protected ProgramcreateProgram(Loader.ImporterSettings settings) protected ProgramcreateProgram(Address imageBase, Loader.ImporterSettings settings) Creates aProgramwith the specified attributes.protected StringgenerateBlockName(Program program, boolean isOverlay, AddressSpace space) Generates a block name.getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram, boolean mirrorFsLayout) Gets the defaultLoaderoptions.protected LanguageServiceGets theLoader's language service.final LoadResults<? extends DomainObject> load(Loader.ImporterSettings settings) Loads bytes in a particular format as a newLoadedDomainObject.final voidloadInto(Program program, Loader.ImporterSettings settings) Loads bytes into the specifiedProgram.loadProgram(Loader.ImporterSettings settings) protected abstract voidloadProgramInto(Program program, Loader.ImporterSettings settings) Loads program bytes into the specifiedProgram.static voidmarkAsFunction(Program program, String name, Address funcStart) Mark this address as a function by creating a one byte function.protected voidpostLoadCleanup(boolean success) This gets called as the final step of the load process.protected voidpostLoadProgramFixups(List<Loaded<Program>> loadedPrograms, Loader.ImporterSettings settings) This gets called after the given list ofloaded programss is finished loading.static voidsetProgramProperties(Program prog, ByteProvider provider, String executableFormatName) Sets a program's Executable Path, Executable Format, MD5, SHA256, and FSRL properties.protected booleanReturns whether or not processor labels should be applied by default.validateOptions(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 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, getTier, getTierPriority, loadsIntoNewFolder, supportsLoadIntoProgram, supportsLoadIntoProgram
-
Field Details
-
APPLY_LABELS_OPTION_NAME
- See Also:
-
ANCHOR_LABELS_OPTION_NAME
- See Also:
-
-
Constructor Details
-
AbstractProgramLoader
public AbstractProgramLoader()
-
-
Method Details
-
loadProgram
protected abstract List<Loaded<Program>> loadProgram(Loader.ImporterSettings settings) throws IOException, LoadException, CancelledException 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.- Parameters:
settings- TheLoader.ImporterSettings.- Returns:
- A
Listof one or moreLoadedPrograms (created but not saved). - Throws:
LoadException- if the load failed in an expected way.IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.
-
loadProgramInto
protected abstract void loadProgramInto(Program program, Loader.ImporterSettings settings) throws IOException, LoadException, CancelledException Loads 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.
- Parameters:
program- TheProgramto load into.settings- TheLoader.ImporterSettings.- Throws:
LoadException- if the load failed in an expected way.IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.
-
load
public final LoadResults<? extends DomainObject> load(Loader.ImporterSettings settings) throws IOException, CancelledException, VersionException, LoadException Description copied from interface:LoaderLoads bytes in a particular format as a newLoadedDomainObject. MultipleDomainObjects may end up getting created, depending on the nature of the format. TheLoadedDomainObjects are bundled together in aLoadResultsobject which provides convenience methods to operate on the entire group ofLoadedDomainObjects.Note that when the load completes, the returned
LoadedDomainObjects are not saved to a project. That is the responsibility of the caller (seeLoadResults.save(TaskMonitor)).It is also the responsibility of the caller to close the returned
LoadedDomainObjects withLoadResults.close()when they are no longer needed.- Specified by:
loadin interfaceLoader- Parameters:
settings- TheLoader.ImporterSettings.- Returns:
- The
LoadResultswhich contains one or moreLoadedDomainObjects (created but not saved). - Throws:
IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.VersionException- if the load process tried to open an existingDomainFilewhich was created with a newer or unsupported version of GhidraLoadException- if the load failed in an expected way
-
loadInto
public final void loadInto(Program program, Loader.ImporterSettings settings) throws IOException, LoadException, CancelledException Description copied from interface:LoaderLoads bytes into the specifiedProgram. This method will not create any newPrograms. It is only for adding to an existingProgram.- Specified by:
loadIntoin interfaceLoader- Parameters:
program- TheProgramto load into.settings- TheLoader.ImporterSettings.- Throws:
IOException- if there was an IO-related problem loading.LoadException- if the load failed in an expected way.CancelledException- if the user cancelled the load.
-
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- 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- 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.
-
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.- Parameters:
loadedPrograms- Theloaded programsto be fixed up.settings- TheLoader.ImporterSettings.- Throws:
IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.
-
postLoadCleanup
protected void postLoadCleanup(boolean success) This gets called as the final step of the load process. Subclasses may override it to ensure any resources they created can be cleaned up after the load finishes.NOTE: Subclasses should not use this method to release any
Programs they created when failure occurs. That should be done by the subclass as soon as it detects failure has occurred.- Parameters:
success- True if the load completed successfully; otherwise, false
-
shouldApplyProcessorLabelsByDefault
protected boolean shouldApplyProcessorLabelsByDefault()Returns whether or not processor labels should be applied by default. Most loaders will not need to override this method because they will not want the labels applied by default.- Returns:
- Whether or not processor labels should be applied by default.
-
generateBlockName
Generates a block name.- Parameters:
program- TheProgramfor the block.isOverlay- true if the block is an overlay; use "ov" in the name.space- TheAddressSpacefor the block.- Returns:
- The generated block name.
-
createProgram
protected Program createProgram(Address imageBase, Loader.ImporterSettings settings) throws IOException Creates aProgramwith the specified attributes.- Parameters:
imageBase- The image base address of theProgram.settings- TheLoader.ImporterSettings.- Returns:
- The newly created
Program. - Throws:
IOException- if there was an IO-related problem with creating theProgram.
-
createProgram
- Parameters:
settings- TheLoader.ImporterSettings.- Returns:
- The newly created
Program. - Throws:
IOException- if there was an IO-related problem with creating theProgram.
-
setProgramProperties
public static void setProgramProperties(Program prog, ByteProvider provider, String executableFormatName) throws IOException Sets a program's Executable Path, Executable Format, MD5, SHA256, and FSRL properties.- Parameters:
prog-Program(with active transaction)provider-ByteProviderthat the program was created fromexecutableFormatName- executable format string- Throws:
IOException- if error reading from ByteProvider
-
createDefaultMemoryBlocks
Creates default memory blocks for the givenProgram.- Parameters:
program- TheProgramto create default memory blocks for.settings- TheLoader.ImporterSettings.
-
markAsFunction
Mark this address as a function by creating a one byte function. The single byte body function is picked up by the function analyzer, disassembled, and the body fixed. Marking the function this way keeps disassembly and follow on analysis out of the loaders.- Parameters:
program- the programname- name of function, null if name not knownfuncStart- starting address of the function
-
addExternalBlock
Adds theEXERNAL blockto memory, or adds to an existing one- Parameters:
program- TheProgramsize- The desired size of the new EXTERNAL blocklog- TheMessageLog- Returns:
- The
Addressof the new (or new piece) of EXTERNAL block - Throws:
Exception- if there was an issue creating or adding to the EXTERNAL block
-
getLanguageService
Gets theLoader's language service.The default behavior of this method is to return the
DefaultLanguageService.- Returns:
- The
Loader's language service.
-