Skip to main content

Program Model

The Program interface is the central abstraction for representing executable binaries in Ghidra. It extends DomainObject and provides access to all aspects of a program’s structure.

Program Components

A program is divided into several major subsystems, each managed by a dedicated interface.

Memory

The memory subsystem manages the program’s address space and byte storage.

Memory Blocks

Memory is organized into contiguous blocks:
Block Types:

Initialized

Contains specific data loaded from the binary file

Uninitialized

Defines a region but content is unknown (e.g., BSS)

Byte-Mapped

Maps to another region with byte-level mapping

Bit-Mapped

Maps to bits in another region (1 byte = 1 bit)
From ghidra/program/model/mem/Memory.java:43-56

Creating Memory Blocks

All block operations require exclusive access and should be performed within a transaction.

Overlay Blocks

Overlay address spaces provide alternate contexts for memory:
Use Cases:
  • Multiple executable contexts (RTOS tasks)
  • Paged memory architectures
  • Bank-switched memory
  • Alternate code paths
Overlays have limitations during analysis. References between overlay and base memory may not be discovered automatically.

Address Spaces

Ghidra supports multiple address spaces within a single program.

Address Interface

AddressSpace Types

From ghidra/program/model/address/AddressSpace.java:28-89
Common Address Spaces:

Address Arithmetic

Use AddressSet and AddressRange for efficient representation of address collections:

Listing

The listing provides access to code units, instructions, and data:

Code Units

Code units are the atomic elements of the listing:
Code Unit Types:
  • Instruction - Disassembled processor instruction
  • Data - Defined data with a specific type
  • Undefined - Unanalyzed bytes

Instructions

Data

Symbol Table

The symbol table manages labels, functions, and namespaces:

Symbols

Symbol Types:
  • FUNCTION - Function entry point
  • LABEL - Address label
  • NAMESPACE - Namespace container
  • CLASS - Class namespace
  • PARAMETER - Function parameter
  • LOCAL_VAR - Local variable
  • GLOBAL_VAR - Global variable

Namespaces

Namespaces organize symbols hierarchically:

Function Manager

Manages functions and their properties:

Functions

Reference Manager

Tracks all memory references and cross-references:
Reference Types:
  • READ - Data read
  • WRITE - Data write
  • UNCONDITIONAL_JUMP - Direct jump
  • CONDITIONAL_JUMP - Conditional branch
  • UNCONDITIONAL_CALL - Function call
  • FALL_THROUGH - Sequential flow
  • EXTERNAL_REF - Reference to external symbol

Data Types

Programs have an associated data type manager:

Built-in Data Types

  • Primitives: byte, word, dword, qword
  • Signed: sbyte, short, int, long
  • Floating: float, double
  • Text: string, unicode
  • Pointers: pointer, pointer32, pointer64

Custom Data Types

Program Properties

Programs store metadata in property lists:
From ghidra/program/model/listing/Program.java:54-64

Language and Architecture

Language Definition

  • Processor instruction set
  • Register definitions
  • P-code semantics
  • Calling conventions
  • Memory model

Transaction Model

All program modifications must occur within transactions:
Forgetting to start a transaction will result in an exception when attempting to modify the program.

Program Events

Programs generate events for changes:
Common Program Events:
  • MEMORY_BLOCK_ADDED / REMOVED
  • CODE_ADDED / REMOVED
  • FUNCTION_ADDED / REMOVED
  • SYMBOL_ADDED / RENAMED / REMOVED
  • DATA_TYPE_ADDED / CHANGED

Best Practices

  • Create memory blocks before analysis
  • Use meaningful block names
  • Set proper permissions (R/W/X)
  • Consider using overlays for alternate contexts
  • Use descriptive symbol names
  • Organize with namespaces
  • Mark important symbols as primary
  • Document symbol sources
  • Define structures for complex data
  • Share data types via archives
  • Apply types consistently
  • Use categories to organize types
  • Keep transactions focused and small
  • Use descriptive transaction names
  • Always commit or rollback explicitly
  • Avoid long-running transactions

Next Steps

Analysis

Learn about program analysis

Projects

Understand project organization

Architecture

Explore framework architecture

Overview

Return to framework overview