Skip to main content

What is an Analyzer?

Analyzers perform automatic program analysis when a binary is loaded or when specific events occur. They can:
  • Disassemble code and identify functions
  • Parse binary format structures (ELF, PE, Mach-O)
  • Detect and apply calling conventions
  • Identify library functions
  • Create data types and structures
  • Apply markup and comments

Analyzer Interface

All analyzers must implement the Analyzer interface and follow naming conventions:
Critical: Analyzer class names must end with Analyzer for automatic discovery.

Creating an Analyzer

Extend AbstractAnalyzer

Most analyzers extend AbstractAnalyzer for common functionality:

Analyzer Types

Defined in AnalyzerType:
  • BYTE_ANALYZER - Analyzes bytes (default)
  • INSTRUCTION_ANALYZER - Analyzes instructions
  • FUNCTION_ANALYZER - Analyzes functions
  • FUNCTION_MODIFIERS_ANALYZER - Modifies function properties
  • FUNCTION_SIGNATURES_ANALYZER - Analyzes function signatures
  • DATA_ANALYZER - Analyzes data

Analysis Priorities

Defined in AnalysisPriority:
Set priority in constructor:

Analysis Workflow

Basic Analysis

Using Program APIs

Register Options

Provide user-configurable options:

Binary Format Analyzer

For format-specific analysis (ELF, PE, etc.):

Real-World Example: ELF Analyzer

Based on Ghidra’s ElfAnalyzer:
The command implementation:

One-Time Analysis

Allow manual analyzer invocation:
Users can then:
  1. Select addresses/functions
  2. Right-click → Auto Analyze…
  3. Select specific analyzers to run

Conditional Enablement

Enable analyzer based on program properties:

Working with Memory

Function Analysis

Progress Reporting

Error Handling

Cleanup

Testing Analyzers

From Eclipse

  1. Launch Ghidra in debug mode
  2. Import a test binary
  3. Analysis → Auto Analyze…
  4. Enable your analyzer
  5. Click Analyze
  6. Check results and debug as needed

Headless Testing

Complete Example

Best Practices

Do:
  • Always use transactions for modifications
  • Check monitor.checkCancelled() frequently
  • Provide meaningful progress updates
  • Log errors to MessageLog
  • Make analyzers configurable with options
  • Document what your analyzer does
Don’t:
  • Modify program without transactions
  • Ignore cancellation requests
  • Assume memory is always accessible
  • Hardcode thresholds (use options)
  • Forget to clean up resources

Resources

  • Analyzer examples: Ghidra/Features/Base/src/main/java/ghidra/app/analyzers/
  • Skeleton template: GhidraBuild/Skeleton/src/main/java/skeleton/SkeletonAnalyzer.java
  • API docs: Analyzer

Next Steps

Loader Development

Add support for new binary formats

Sleigh Language

Define processor instruction sets