Skip to main content

What is a Loader?

Loaders enable Ghidra to import and parse binary file formats. They:
  • Identify supported file formats
  • Parse file headers and structures
  • Create memory blocks and segments
  • Define entry points and exports
  • Apply relocations and imports
  • Set up initial program metadata

Loader Interface

All loaders must implement the Loader interface:
Critical: Loader class names must end with Loader for automatic discovery.

Loader Base Classes

Ghidra provides several base classes:

AbstractProgramLoader

For format-specific loaders:

AbstractProgramWrapperLoader

For wrapper formats (compression, containers):

AbstractLibrarySupportLoader

For formats with library/import support:

Creating a Basic Loader

Format Detection

Magic Bytes

Creating Memory Blocks

Setting Entry Point

Adding Relocations

Import/Export Tables

Loader Options

Binary Parsing Utilities

Ghidra provides utilities for reading binary structures:

Real-World Example: ELF Loader

Based on Ghidra’s ElfLoader:

Testing Loaders

From Ghidra GUI

  1. Launch Ghidra with your loader extension
  2. File → Import File…
  3. Select test binary
  4. Verify your loader appears in format list
  5. Select loader and configure options
  6. Click OK and verify results

Headless Testing

Complete Example

Best Practices

Do:
  • Validate file format thoroughly
  • Use transactions for all modifications
  • Log meaningful progress messages
  • Handle errors gracefully
  • Provide useful loader options
  • Document file format structure
  • Create appropriate memory block permissions
Don’t:
  • Assume file structure is valid
  • Create overlapping memory blocks
  • Forget to set entry points
  • Hardcode addresses (use options)
  • Ignore endianness

Resources

  • Loader examples: Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/
  • Skeleton template: GhidraBuild/Skeleton/src/main/java/skeleton/SkeletonLoader.java
  • Binary utilities: Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/
  • API docs: Loader

Next Steps

Analyzer Development

Build custom analyzers for your format

Sleigh Language

Define processor instruction sets