Package ghidra.app.util.opinion
Class AbstractProgramLoader
- java.lang.Object
-
- ghidra.app.util.opinion.AbstractProgramLoader
-
- All Implemented Interfaces:
Loader
,ExtensionPoint
,java.lang.Comparable<Loader>
- Direct Known Subclasses:
AbstractLibrarySupportLoader
,BinaryLoader
,IntelHexLoader
,MotorolaHexLoader
,XmlLoader
public abstract class AbstractProgramLoader extends java.lang.Object implements Loader
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ghidra.util.classfinder.ExtensionPoint
ExtensionPoint.Exclude, ExtensionPoint.Util
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANCHOR_LABELS_OPTION_NAME
static java.lang.String
APPLY_LABELS_OPTION_NAME
-
Fields inherited from interface ghidra.app.util.opinion.Loader
COMMAND_LINE_ARG_PREFIX
-
-
Constructor Summary
Constructors Constructor Description AbstractProgramLoader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
createDefaultMemoryBlocks(Program program, Language language, MessageLog log)
Creates default memory blocks for the givenProgram
.protected Program
createProgram(ByteProvider provider, java.lang.String programName, Address imageBase, java.lang.String executableFormatName, Language language, CompilerSpec compilerSpec, java.lang.Object consumer)
Creates aProgram
with the specified attributes.protected java.lang.String
generateBlockName(Program program, boolean isOverlay, AddressSpace space)
Generates a block name.java.util.List<Option>
getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean isLoadIntoProgram)
Gets the defaultLoader
options.protected LanguageService
getLanguageService()
Gets theLoader
's language service.java.util.List<DomainObject>
load(ByteProvider provider, java.lang.String name, DomainFolder folder, LoadSpec loadSpec, java.util.List<Option> options, MessageLog messageLog, java.lang.Object consumer, TaskMonitor monitor)
Loads bytes in a particular format as a newDomainObject
.boolean
loadInto(ByteProvider provider, LoadSpec loadSpec, java.util.List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor)
Loads bytes into the specifiedProgram
.protected abstract java.util.List<Program>
loadProgram(ByteProvider provider, java.lang.String programName, DomainFolder programFolder, LoadSpec loadSpec, java.util.List<Option> options, MessageLog log, java.lang.Object consumer, TaskMonitor monitor)
Loads program bytes in a particular format as a newProgram
.protected abstract boolean
loadProgramInto(ByteProvider provider, LoadSpec loadSpec, java.util.List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor)
Loads program bytes into the specifiedProgram
.protected void
postLoadProgramFixups(java.util.List<Program> loadedPrograms, DomainFolder folder, java.util.List<Option> options, MessageLog messageLog, TaskMonitor monitor)
This gets called after the given list of s is finished loading.protected void
release(java.util.List<? extends DomainObject> domainObjects, java.lang.Object consumer)
Releases the given consumer from each of the providedDomainObject
s.protected boolean
shouldApplyProcessorLabelsByDefault()
Returns whether or not processor labels should be applied by default.java.lang.String
validateOptions(ByteProvider provider, LoadSpec loadSpec, java.util.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, wait
-
Methods inherited from interface ghidra.app.util.opinion.Loader
compareTo, findSupportedLoadSpecs, getName, getPreferredFileName, getTier, getTierPriority, supportsLoadIntoProgram
-
-
-
-
Field Detail
-
APPLY_LABELS_OPTION_NAME
public static final java.lang.String APPLY_LABELS_OPTION_NAME
- See Also:
- Constant Field Values
-
ANCHOR_LABELS_OPTION_NAME
public static final java.lang.String ANCHOR_LABELS_OPTION_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
loadProgram
protected abstract java.util.List<Program> loadProgram(ByteProvider provider, java.lang.String programName, DomainFolder programFolder, LoadSpec loadSpec, java.util.List<Option> options, MessageLog log, java.lang.Object consumer, TaskMonitor monitor) throws java.io.IOException, CancelledException
Loads program bytes in a particular format as a newProgram
. MultipleProgram
s may end up getting created, depending on the nature of the format.- 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
Program
s (element 0 corresponds to primary loadedProgram
). - Throws:
java.io.IOException
- if there was an IO-related problem loading.CancelledException
- if the user cancelled the load.
-
loadProgramInto
protected abstract boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec, java.util.List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor) throws java.io.IOException, CancelledException
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.
- Parameters:
provider
- The bytes to load into theProgram
.loadSpec
- TheLoadSpec
to use during load.options
- The load options.messageLog
- The message log.program
- TheProgram
to load into.monitor
- A cancelable task monitor.- Returns:
- True if the file was successfully loaded; otherwise, false.
- Throws:
java.io.IOException
- if there was an IO-related problem loading.CancelledException
- if the user cancelled the load.
-
load
public final java.util.List<DomainObject> load(ByteProvider provider, java.lang.String name, DomainFolder folder, LoadSpec loadSpec, java.util.List<Option> options, MessageLog messageLog, java.lang.Object consumer, TaskMonitor monitor) throws java.io.IOException, CancelledException, InvalidNameException, DuplicateNameException, VersionException
Description copied from interface:Loader
Loads bytes in a particular format as a newDomainObject
. MultipleDomainObject
s may end up getting created, depending on the nature of the format.- Specified by:
load
in interfaceLoader
- Parameters:
provider
- The bytes to load.name
- The name of the thing that's being loaded.folder
- 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.messageLog
- The message log.consumer
- A consumer object forDomainObject
generated.monitor
- A cancelable task monitor.- Returns:
- A list of loaded
DomainObject
s (element 0 corresponds to primary loaded object). - Throws:
java.io.IOException
- if there was an IO-related problem loading.CancelledException
- if the user cancelled the load.InvalidNameException
- if an invalidDomainObject
name was used during load.DuplicateNameException
- if the load resulted in a naming conflict with theDomainObject
.VersionException
- if there was an issue with database versions, probably due to a failed language upgrade.
-
loadInto
public final boolean loadInto(ByteProvider provider, LoadSpec loadSpec, java.util.List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor) throws java.io.IOException, CancelledException
Description copied from interface:Loader
Loads bytes into the specifiedProgram
. This method will not create any newProgram
s. It is only for adding to an existingProgram
.- Specified by:
loadInto
in interfaceLoader
- Parameters:
provider
- The bytes to load into theProgram
.loadSpec
- TheLoadSpec
to use during load.options
- The load options.messageLog
- The message log.program
- TheProgram
to load into.monitor
- A cancelable task monitor.- Returns:
- True if the file was successfully loaded; otherwise, false.
- Throws:
java.io.IOException
- if there was an IO-related problem loading.CancelledException
- if the user cancelled the load.
-
getDefaultOptions
public java.util.List<Option> getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean isLoadIntoProgram)
Description copied from interface:Loader
Gets the defaultLoader
options.- Specified by:
getDefaultOptions
in interfaceLoader
- Parameters:
provider
- The bytes of the thing being loaded.loadSpec
- TheLoadSpec
.domainObject
- TheDomainObject
being loaded.isLoadIntoProgram
- True if the load is adding to an existingDomainObject
; otherwise, false.- Returns:
- A list of the
Loader
's default options.
-
validateOptions
public java.lang.String validateOptions(ByteProvider provider, LoadSpec loadSpec, java.util.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
- 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.
-
postLoadProgramFixups
protected void postLoadProgramFixups(java.util.List<Program> loadedPrograms, DomainFolder folder, java.util.List<Option> options, MessageLog messageLog, TaskMonitor monitor) throws CancelledException, java.io.IOException
This gets called after the given list of s is finished loading. It provides subclasses an opportunity to do follow-on actions to the load.- Parameters:
loadedPrograms
- TheProgram
s that got loaded.folder
- The folder the programs were loaded to.options
- The load options.messageLog
- The message log.monitor
- A cancelable task monitor.- Throws:
java.io.IOException
- if there was an IO-related problem loading.CancelledException
- if the user cancelled the load.
-
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
protected java.lang.String generateBlockName(Program program, boolean isOverlay, AddressSpace space)
Generates a block name.- Parameters:
program
- TheProgram
for the block.isOverlay
- true if the block is an overlay; use "ov" in the name.space
- TheAddressSpace
for the block.- Returns:
- The generated block name.
-
createProgram
protected Program createProgram(ByteProvider provider, java.lang.String programName, Address imageBase, java.lang.String executableFormatName, Language language, CompilerSpec compilerSpec, java.lang.Object consumer) throws java.io.IOException
Creates aProgram
with the specified attributes.- Parameters:
provider
- The bytes that will make up theProgram
.programName
- The name of theProgram
.imageBase
- The image base address of theProgram
.executableFormatName
- The file format name of theProgram
. Typically this will be theLoader
name.language
- TheLanguage
of theProgram
.compilerSpec
- TheCompilerSpec
of theProgram
.consumer
- A consumer object for theProgram
generated.- Returns:
- The newly created
Program
. - Throws:
java.io.IOException
- if there was an IO-related problem with creating theProgram
.
-
createDefaultMemoryBlocks
protected void createDefaultMemoryBlocks(Program program, Language language, MessageLog log)
Creates default memory blocks for the givenProgram
.
-
getLanguageService
protected LanguageService getLanguageService()
Gets theLoader
's language service.The default behavior of this method is to return the
DefaultLanguageService
.- Returns:
- The
Loader
's language service.
-
release
protected final void release(java.util.List<? extends DomainObject> domainObjects, java.lang.Object consumer)
Releases the given consumer from each of the providedDomainObject
s.- Parameters:
domainObjects
- A list ofDomainObject
s which are no longer being used.consumer
- The consumer that was marking theDomainObject
s as being used.
-
-