Package ghidra.app.util.opinion

# Class BinaryLoader

java.lang.Object
ghidra.app.util.opinion.AbstractProgramLoader
ghidra.app.util.opinion.BinaryLoader

All Implemented Interfaces:
  `Loader`, `ExtensionPoint`, `Comparable<Loader>`

public class BinaryLoader extends AbstractProgramLoader

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `BINARY_NAME`
  `static final String`
  `OPTION_NAME_BASE_ADDR`
  `static final String`
  `OPTION_NAME_BLOCK_NAME`
  `static final String`
  `OPTION_NAME_FILE_OFFSET`
  `static final String`
  `OPTION_NAME_IS_OVERLAY`
  `static final String`
  `OPTION_NAME_LEN`

  ### 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, OPTIONS_PROJECT_SAVE_STATE_KEY`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BinaryLoader()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Collection<LoadSpec>`
  `findSupportedLoadSpecs(ByteProvider provider)`
  If this `Loader` supports loading the given `ByteProvider`, this methods returns a `Collection` of all supported `LoadSpec`s that contain discovered load specification information that this `Loader` will need to load.
  `List<Option>`
  `getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram)`
  Gets the default `Loader` options.
  `String`
  `getName()`
  Gets the `Loader`'s name, which is used both for display purposes, and to identify the `Loader` in the opinion files.
  `LoaderTier`
  `getTier()`
  For ordering purposes; lower tier numbers are more important (and listed first).
  `int`
  `getTierPriority()`
  For ordering purposes; lower numbers are more important (and listed first, within its tier).
  `protected List<Loaded<Program>>`
  `loadProgram(ByteProvider provider, String programName, Project project, String programFolderPath, LoadSpec loadSpec, List<Option> options, MessageLog log, Object consumer, TaskMonitor monitor)`
  Loads bytes in a particular format as a new `Loaded` `Program`.
  `protected void`
  `loadProgramInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, Program prog, TaskMonitor monitor)`
  Loads program bytes into the specified `Program`.
  `boolean`
  `shouldApplyProcessorLabelsByDefault()`
  Returns whether or not processor labels should be applied by default.
  `boolean`
  `supportsLoadIntoProgram()`
  Checks to see if this `Loader` supports loading into an existing `Program`.
  `String`
  `validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program)`
  Validates the `Loader`'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

  `concatenatePaths, createDefaultMemoryBlocks, createProgram, generateBlockName, getLanguageService, load, loadInto, markAsFunction, postLoadCleanup, postLoadProgramFixups, release, setProgramProperties`

  ### 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`

- ## Field Details

  - ### BINARY_NAME

    public static final String BINARY_NAME
    See Also:
      - Constant Field Values

  - ### OPTION_NAME_LEN

    public static final String OPTION_NAME_LEN
    See Also:
      - Constant Field Values

  - ### OPTION_NAME_FILE_OFFSET

    public static final String OPTION_NAME_FILE_OFFSET
    See Also:
      - Constant Field Values

  - ### OPTION_NAME_BASE_ADDR

    public static final String OPTION_NAME_BASE_ADDR
    See Also:
      - Constant Field Values

  - ### OPTION_NAME_BLOCK_NAME

    public static final String OPTION_NAME_BLOCK_NAME
    See Also:
      - Constant Field Values

  - ### OPTION_NAME_IS_OVERLAY

    public static final String OPTION_NAME_IS_OVERLAY
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### BinaryLoader

    public BinaryLoader()

- ## Method Details

  - ### getTier

    public LoaderTier 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

  - ### supportsLoadIntoProgram

    public boolean supportsLoadIntoProgram()
    Description copied from interface: `Loader`
    Checks to see if this `Loader` supports loading into an existing `Program`.

    The default behavior of this method is to return false.

    Returns:
      True if this `Loader` supports loading into an existing `Program`; otherwise, false.

  - ### findSupportedLoadSpecs

    public Collection<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws IOException
    Description copied from interface: `Loader`
    If this `Loader` supports loading the given `ByteProvider`, this methods returns a `Collection` of all supported `LoadSpec`s that contain discovered load specification information that this `Loader` will need to load. If this `Loader` cannot support loading the given `ByteProvider`, an empty `Collection` is returned.
    Parameters:
      `provider` - The bytes being loaded.
    Returns:
      A `Collection` of `LoadSpec`s that this `Loader` supports loading, or an empty `Collection` if this `Loader` doesn't support loading the given `ByteProvider`.
    Throws:
      `IOException` - if there was an IO-related issue finding the `LoadSpec`s.

  - ### validateOptions

    public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program)
    Description copied from interface: `Loader`
    Validates the `Loader`'s options and returns null if all options are valid; otherwise, an error message describing the problem is returned.
    Specified by:
      `validateOptions` in interface `Loader`
    Overrides:
      `validateOptions` in class `AbstractProgramLoader`
    Parameters:
      `provider` - The bytes of the thing being loaded.
      `loadSpec` - The proposed `LoadSpec`.
      `options` - The list of `Option`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.

  - ### loadProgram

    protected List<Loaded<Program>> loadProgram(ByteProvider provider, String programName, Project project, String programFolderPath, LoadSpec loadSpec, List<Option> options, MessageLog log, Object consumer, TaskMonitor monitor) throws IOException, CancelledException
    Description copied from class: `AbstractProgramLoader`
    Loads bytes in a particular format as a new `Loaded` `Program`. Multiple `Program`s may end up getting created, depending on the nature of the format.

    Note that when the load completes, the returned `Loaded` `Program`s are not saved to a project. That is the responsibility of the caller (see `Loaded.save(Project, MessageLog, TaskMonitor)`).

    It is also the responsibility of the caller to release the returned `Loaded` `Program`s with `Loaded.release(Object)` when they are no longer needed.

    Specified by:
      `loadProgram` in class `AbstractProgramLoader`
    Parameters:
      `provider` - The bytes to load.
      `programName` - A suggested name for the primary `Loaded` `Program`. This is just a suggestion, and a `Loader` implementation reserves the right to change it. The `Loaded` `Program`s should be queried for their true names using `Loaded.getName()`.
      `project` - The `Project`. Loaders can use this to take advantage of existing `DomainFolder`s and `DomainFile`s to do custom behaviors such as loading libraries. Could be null if there is no project.
      `programFolderPath` - A suggested project folder path for the `Loaded` `Program`s. This is just a suggestion, and a `Loader` implementation reserves the right to change it for each `Loaded` result. The `Loaded` `Program`s should be queried for their true project folder paths using `Loaded.getProjectFolderPath()`.
      `loadSpec` - The `LoadSpec` to use during load.
      `options` - The load options.
      `log` - The message log.
      `consumer` - A consumer object for generated `Program`s.
      `monitor` - A task monitor.
    Returns:
      A `List` of one or more `Loaded` `Program`s (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 void loadProgramInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, Program prog, TaskMonitor monitor) throws IOException, LoadException, CancelledException
    Description copied from class: `AbstractProgramLoader`
    Loads program bytes into the specified `Program`. This method will not create any new `Program`s. It is only for adding to an existing `Program`.

    NOTE: The loading that occurs in this method will automatically be done in a transaction.

    Specified by:
      `loadProgramInto` in class `AbstractProgramLoader`
    Parameters:
      `provider` - The bytes to load into the `Program`.
      `loadSpec` - The `LoadSpec` to use during load.
      `options` - The load options.
      `log` - The message log.
      `prog` - The `Program` to load into.
      `monitor` - A cancelable task monitor.
    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.

  - ### getDefaultOptions

    public List<Option> getDefaultOptions(ByteProvider provider, LoadSpec loadSpec, DomainObject domainObject, boolean loadIntoProgram)
    Description copied from interface: `Loader`
    Gets the default `Loader` options.
    Specified by:
      `getDefaultOptions` in interface `Loader`
    Overrides:
      `getDefaultOptions` in class `AbstractProgramLoader`
    Parameters:
      `provider` - The bytes of the thing being loaded.
      `loadSpec` - The `LoadSpec`.
      `domainObject` - The `DomainObject` being loaded.
      `loadIntoProgram` - True if the load is adding to an existing `DomainObject`; otherwise, false.
    Returns:
      A list of the `Loader`'s default options.

  - ### getName

    public String getName()
    Description copied from interface: `Loader`
    Gets the `Loader`'s name, which is used both for display purposes, and to identify the `Loader` in the opinion files.
    Returns:
      The `Loader`'s name.

  - ### shouldApplyProcessorLabelsByDefault

    public boolean shouldApplyProcessorLabelsByDefault()
    Description copied from class: `AbstractProgramLoader`
    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.
    Overrides:
      `shouldApplyProcessorLabelsByDefault` in class `AbstractProgramLoader`
    Returns:
      Whether or not processor labels should be applied by default.