Package ghidra.app.util.opinion
Class AbstractProgramLoader
java.lang.Object
ghidra.app.util.opinion.AbstractProgramLoader
- All Implemented Interfaces:
Loader,ExtensionPoint,Comparable<Loader>
- Direct Known Subclasses:
AbstractLibrarySupportLoader,AbstractProgramWrapperLoader,BinaryLoader,IntelHexLoader,MotorolaHexLoader,XmlLoader
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAProgramwith its associateddestination folder -
Field Summary
FieldsFields inherited from interface ghidra.app.util.opinion.Loader
COMMAND_LINE_ARG_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcreateDefaultMemoryBlocks(Program program, Language language, MessageLog log) Creates default memory blocks for the givenProgram.protected ProgramcreateProgram(ByteProvider provider, String domainFileName, Address imageBase, String executableFormatName, Language language, CompilerSpec compilerSpec, Object consumer) 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 isLoadIntoProgram) Gets the defaultLoaderoptions.protected LanguageServiceGets theLoader's language service.protected booleanSome loaders can return more than one program.final List<DomainObject>load(ByteProvider provider, String name, DomainFolder folder, LoadSpec loadSpec, List<Option> options, MessageLog messageLog, Object consumer, TaskMonitor monitor) Loads bytes in a particular format as a newDomainObject.final booleanloadInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor) Loads bytes into the specifiedProgram.protected abstract 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 abstract booleanloadProgramInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor) 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 voidpostLoadProgramFixups(List<AbstractProgramLoader.LoadedProgram> loadedPrograms, List<Option> options, MessageLog messageLog, TaskMonitor monitor) This gets called after the given list ofprogramss is finished loading.protected final voidrelease(List<AbstractProgramLoader.LoadedProgram> loadedPrograms, Object consumer) Releases the given consumer from each of the providedAbstractProgramLoader.LoadedPrograms.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, 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<AbstractProgramLoader.LoadedProgram> loadProgram(ByteProvider provider, String programName, DomainFolder programFolder, LoadSpec loadSpec, List<Option> options, MessageLog log, Object consumer, TaskMonitor monitor) throws IOException, CancelledException Loads program bytes in a particular format as a newProgram. MultiplePrograms may end up getting created, depending on the nature of the format.- Parameters:
provider- The bytes to load.programName- The name of theProgramthat's being loaded.programFolder- TheDomainFolderwhere the loaded thing should be saved. Could be null if the thing should not be pre-saved.loadSpec- TheLoadSpecto use during load.options- The load options.log- The message log.consumer- A consumer object forPrograms generated.monitor- A cancelable task monitor.- Returns:
- A list of
loaded programs(element 0 corresponds to primary loadedProgram). - Throws:
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, List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor) throws IOException, 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:
provider- The bytes to load into theProgram.loadSpec- TheLoadSpecto use during load.options- The load options.messageLog- The message log.program- TheProgramto load into.monitor- A cancelable task monitor.- Returns:
- True if the file was successfully loaded; otherwise, false.
- Throws:
IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.
-
load
public final List<DomainObject> load(ByteProvider provider, String name, DomainFolder folder, LoadSpec loadSpec, List<Option> options, MessageLog messageLog, Object consumer, TaskMonitor monitor) throws IOException, CancelledException, InvalidNameException, DuplicateNameException, VersionException Description copied from interface:LoaderLoads bytes in a particular format as a newDomainObject. MultipleDomainObjects may end up getting created, depending on the nature of the format.- Specified by:
loadin interfaceLoader- Parameters:
provider- The bytes to load.name- The name of the thing that's being loaded.folder- TheDomainFolderwhere the loaded thing should be saved. Could be null if the thing should not be pre-saved.loadSpec- TheLoadSpecto use during load.options- The load options.messageLog- The message log.consumer- A consumer object forDomainObjectgenerated.monitor- A cancelable task monitor.- Returns:
- A list of loaded
DomainObjects (element 0 corresponds to primary loaded object). - Throws:
IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.InvalidNameException- if an invalidDomainObjectname 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.
-
isOverrideMainProgramName
protected boolean isOverrideMainProgramName()Some loaders can return more than one program. This method indicates whether the first (or main) program's name should be overridden and changed to the imported file name.- Returns:
- true if first program name should be changed
-
loadInto
public final boolean loadInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor) throws IOException, 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:
provider- The bytes to load into theProgram.loadSpec- TheLoadSpecto use during load.options- The load options.messageLog- The message log.program- TheProgramto load into.monitor- A cancelable task monitor.- Returns:
- True if the file was successfully loaded; otherwise, false.
- Throws:
IOException- if there was an IO-related problem loading.CancelledException- if the user cancelled the load.
-
getDefaultOptions
public List<Option> getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean isLoadIntoProgram) 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.isLoadIntoProgram- 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: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<AbstractProgramLoader.LoadedProgram> loadedPrograms, List<Option> options, MessageLog messageLog, TaskMonitor monitor) throws CancelledException, IOException This gets called after the given list ofprogramss is finished loading. It provides subclasses an opportunity to do follow-on actions to the load.- Parameters:
loadedPrograms- Theprogramsthat got loaded.options- The load options.messageLog- The message log.monitor- A cancelable task monitor.- Throws:
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
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(ByteProvider provider, String domainFileName, Address imageBase, String executableFormatName, Language language, CompilerSpec compilerSpec, Object consumer) throws IOException Creates aProgramwith the specified attributes.- Parameters:
provider- The bytes that will make up theProgram.domainFileName- The name for the DomainFile that will store theProgram.imageBase- The image base address of theProgram.executableFormatName- The file format name of theProgram. Typically this will be theLoadername.language- TheLanguageof theProgram.compilerSpec- TheCompilerSpecof theProgram.consumer- A consumer object for theProgramgenerated.- 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. -
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
-
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(List<AbstractProgramLoader.LoadedProgram> loadedPrograms, Object consumer) Releases the given consumer from each of the providedAbstractProgramLoader.LoadedPrograms.- Parameters:
loadedPrograms- A list ofAbstractProgramLoader.LoadedPrograms which are no longer being used.consumer- The consumer that was marking theDomainObjects as being used.
-