Skip to content

The Ghidra project

Every name recovered from the firmware ends up in one Ghidra project. A finding that stays in a note gets found again from zero, and one written into the project shows up in the next disassembly dump.

Where things are

Project firmware/iPodClassic.gpr, main program osos-dec.dfu
Scripts firmware/ghidra_scripts_project/
ASM dump firmware/claudedump/asm_current/

The dump has one file per function, such as asm_current/220cfc74.s, and an INDEX.txt that maps each file to its function's name. It annotates string arguments (PARAM -> s_Foo) and branch targets (-> FUN_xxxx), so a grep by string or by callee works on the disassembly. Ghidra ships prebuilt decompiler natives for Apple silicon, so nothing needs building.

The project holds far more than the OS. The forty bootloader modules, the boot ROM, the recovery stage, the updater, Apple's disk mode and the diagnostics image each sit in it as a program of their own. Check what is already there before importing anything.

Refresh the dump first

The dump is a snapshot, and a stale one is missing names the project already has. So it gets refreshed at the start of a session, before anything is read.

cd firmware && <ghidra>/support/analyzeHeadless . iPodClassic \
    -process osos-dec.dfu -noanalysis -scriptPath ghidra_scripts_project \
    -postScript DumpAllFunctionsAsm claudedump/asm_current

Today it carries about four thousand named functions out of nearly twenty thousand. Script output arrives on stderr, prefixed INFO <Script>.java>.

Why the project reads assembly

There is no bulk C dump. The decompilation reads like an answer without being one, and on this image it hid a lot:

  • nineteen separate *Hilited handlers inlined into one switch, with the jump table swallowed
  • tail calls rendered as ninety-line bodies
  • adjustor thunks that resolve to "no function" until the branch is decoded
  • a divisor dropped out of a scale
  • a set of colours that exist only as stack byte stores and never appear in the C

Indirect calls are the worst case. The decompiler shows them as plain calls, so the C looks settled exactly where the real question is:

  • a display function's panel write is ldr ip,[r0,#0xc] ; blx ip, through a descriptor slot
  • a gate dispatches through two vtable slots
  • a frame count comes from TABLE + 4 rather than header + 4, because r1 is reloaded midway

One function's C, on demand

For a shape that is slow to read in ARM, such as a forty-case property getter, one function's C is still worth having:

cd firmware && <ghidra>/support/analyzeHeadless . iPodClassic -process osos-dec.dfu -noanalysis \
    -scriptPath ghidra_scripts_project -postScript DumpOneFunctionC 0x221ddf74

Anything it says about a number, a call target or a value derived from a register gets checked in the .s before it reaches code.

Findings go back in through a script

An Apply*Findings.java script applies what was learned, then the dump is refreshed so the next read sees the new names. This happens as soon as a finding holds, while the thread is still open.

Before disassembling anything that looks like infrastructure, search what is already known. chikuma/tools/recall.py <term> searches the project's symbols and every other place a recovery lives here in one go.

Traps in this particular image

A method reached only through a vtable may have no function

It is missing from the dump and reads as unreachable code. Dump the vtable first, the object's vptr and then the slot. If the target has no function, create it with an Apply*Findings script and re-dump.

Creating one can land a zero-length body when the bytes were never disassembled. The order that works is remove, clear, disassemble, create.

A name can land on the wrong function

getFunctionContaining returns an unrelated function when no function is defined at the address you want. Check getFunctionAt first.

Semihosting calls go nowhere

RetailOS instruments roughly 131 call sites with SVC 0x123456, ARM semihosting. The retail handler is a stub (mov r0,#0 ; bx lr) that discards all of it. Replacement firmware that implements the handler inherits the convention, and OpenOCD semihosting with it, on day one.