Program Model
TheProgram 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: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)
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:- Multiple executable contexts (RTOS tasks)
- Paged memory architectures
- Bank-switched memory
- Alternate code paths
Address Spaces
Ghidra supports multiple address spaces within a single program.Address Interface
AddressSpace Types
Fromghidra/program/model/address/AddressSpace.java:28-89
Address Arithmetic
Listing
The listing provides access to code units, instructions, and data:Code Units
Code units are the atomic elements of the listing:- 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
FUNCTION- Function entry pointLABEL- Address labelNAMESPACE- Namespace containerCLASS- Class namespacePARAMETER- Function parameterLOCAL_VAR- Local variableGLOBAL_VAR- Global variable
Namespaces
Function Manager
Manages functions and their properties:Functions
Reference Manager
Tracks all memory references and cross-references:READ- Data readWRITE- Data writeUNCONDITIONAL_JUMP- Direct jumpCONDITIONAL_JUMP- Conditional branchUNCONDITIONAL_CALL- Function callFALL_THROUGH- Sequential flowEXTERNAL_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: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:Program Events
Programs generate events for changes:MEMORY_BLOCK_ADDED/REMOVEDCODE_ADDED/REMOVEDFUNCTION_ADDED/REMOVEDSYMBOL_ADDED/RENAMED/REMOVEDDATA_TYPE_ADDED/CHANGED
Best Practices
Memory Management
Memory Management
- Create memory blocks before analysis
- Use meaningful block names
- Set proper permissions (R/W/X)
- Consider using overlays for alternate contexts
Symbol Management
Symbol Management
- Use descriptive symbol names
- Organize with namespaces
- Mark important symbols as primary
- Document symbol sources
Data Types
Data Types
- Define structures for complex data
- Share data types via archives
- Apply types consistently
- Use categories to organize types
Transactions
Transactions
- 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
