boricj / ghidra-delinker-extension

Ghidra extension for exporting relocatable object files
Apache License 2.0
346 stars 13 forks source link
delinking ghidra ghidra-extension reverse-engineering

Object file exporter extension for Ghidra

This Ghidra extension enables exporting parts of a program as object files. These object files have valid metadata (symbols, relocation tables…) and as such can be reused directly by a toolchain for further processing.

Use-cases include:

Matrix of supported instruction set architectures and object files:

x86 MIPS
COFF
ELF

Building (CLI)

The Ghidra extension archive will be created inside the dist/ directory.

Installation

Usage

  1. Select a set of addresses in the Listing view ;
  2. Run the Relocation table synthesizer analyzer (available in one-shot mode) ;
  3. Invoke a relocatable object file exporter with File > Export Program…

The reconstructed relocations can be viewed with Window > Relocation table (synthesized).

How does it work?

Object files are made of three parts:

When a linker is invoked to generate an executable from a bunch of object files, it will:

Normally the relocation table is discarded after this process, as well as the symbol table if debugging symbols aren't kept, leaving only the un-relocatable section bytes. However, through careful analysis this data can be recreated, which allows us to then effectively delink the program back into object files.