Skip to content

The eApp format

A game binary is an eApp image: a header, a linked list of interface records, and a vector of entry points. It is neither ELF nor Mach-O. The eapp magic appears nowhere in the firmware but the loader, so every field below comes from the code that reads it.

The header

+0x00  u32   'eapp'  0x70706165        rejected with -2 otherwise
+0x04  u32   version, must be <= 0x10001000
+0x08  u32   nentry, must be <= 5
+0x0c  u32   not read by the loader
+0x10  ptr   the FIRST interface record, or 0
+0x14  u32   entry[nentry]

0x10001000 reads as a packed 16.16 version ceiling.

Code Refusal
-2 bad magic, or a record that fails validation
-3 the named interface is not provided by this OS
-0x3E9 version or count out of range

No relocation

The pointer at +0x10 is absolute. The loader bounds-checks it against [base, base+size) and then uses it directly, without adding the base. It relocates nothing at all, and patching imports is the whole of its work.

An eApp image is therefore linked at the fixed address of the launcher's game arena, and anything built to run there has to live with that.

The entry vector

The five words are copied into the app object, and entry[4] must be non-zero or the launch fails. Measured at the call sites:

entry[0]   called immediately after the load succeeds
entry[1]   called on teardown, before the state goes to 3
entry[2]   not seen called
entry[3]   not seen called
entry[4]   THE ENTRY: called on the game thread, once per frame, as f(A, B)

entry[4] runs every frame. The runner calls it in a loop and checks its own stop condition after each call.

Interface records

The image carries a singly-linked list of the interfaces it wants:

+0x00  char  name[0x20]     NUL-terminated, matched against the host's
+0x20  u8    guid[0x10]     the interface VERSION identity, compared byte for byte
+0x30  u32   nfunc          must equal the host's count for that interface
+0x34  ptr   next, or 0     absolute, bounds-checked like +0x10
+0x38        nfunc import stubs, then a sentinel word

The list ends with a record whose name is

$$$$ a^n + b^n = c^n | n>2 $$$$

That is Fermat's last theorem, 31 characters and a NUL, exactly 0x20, and a name nothing else is likely to collide with. Reaching it is what makes the load succeed.

How imports are bound

The stub area holds ldr pc,[pc,#imm] veneers followed by their literal pool, and the loader fills the pool. For each run it reads the first stub and takes the low 12 bits as the immediate. Then it computes n = imm/4 + 2, which is exactly the number of words from an ldr pc,[pc,#imm] to its literal when the literals follow n stubs. It copies n host function pointers into the slots and moves on.

Compiled game code calls bl stub, and the stub loads the patched literal into pc. Nothing else in the image is touched.

graph TD
    H["<b>header</b><br/>'eapp' · version · nentry · entry[5]"]
    R1["<b>interface record</b><br/>name · guid · nfunc · next"]
    S1["<b>import stubs</b><br/>ldr pc,[pc,#imm] × n"]
    P1["<b>literal pool</b><br/>n empty words"]
    R2["interface record ..."]
    F["<b>terminator record</b><br/>$$$$ a^n + b^n = c^n &#124; n&gt;2 $$$$"]
    HOST["the OS interface list<br/>name · nfunc · function pointers · guids"]
    H -- "+0x10, absolute, bounds-checked" --> R1
    R1 --> S1 --> P1
    R1 -- "next" --> R2 -- "next" --> F
    HOST -- "matched by name + guid + count,<br/>then COPIED into the pool" --> P1

A game bakes in no firmware address

The loader matches names and version guids and checks counts. Every call into the OS goes through a slot it fills at load time. A game imports by slot index, so the order of an interface is the contract, and the names only serve the reader.

A mismatch fails the load. A wrong guid or a wrong function count returns its own code, and the firmware has a screen for each failure.

The host side

The OS publishes its interfaces as a walkable list at a fixed address. Each descriptor carries a name, a function count, the pointers themselves, and one version record per accepted guid.

That table is the third-party SDK's surface: eleven interfaces, 486 functions, versioned. One of them is called miscTBD, and the whole thing reads like somebody's internal header. See the games API for what is in it.

The layout also predicts where the next descriptor starts, so a truncated capture shows itself. A dump that parses to nine interfaces, with Audio too short for its own declared count, is missing two. The complete image has eleven, and Audio parses.

Reproducing it

chikuma/tools/eapp_format.py asserts every constant above against the image and fails if any of them moves. Chikuma's own loader is in chikuma/drivers/games/.

A generated registry

The loader refuses a game whose record does not match the host's name, guid and function count exactly, so the registry is generated, never typed. A tool walks the firmware's own list and emits all eleven interfaces with their 486 slots.

The slots themselves are NULL in the output. An address in Apple's image means nothing here, and what a game needs is Chikuma's implementation. The set, the order and the counts are what have to be right.

Generated imports

The import side is generated too. An image assembled from the generator, with header, chained records, trampolines and their pool, loads through Chikuma's loader with 486 of 486 imports bound. So do the shipped games.

The trampoline encoding follows from the geometry. For a run of N imports, every veneer encodes the same displacement, N*4 - 8. Each shipped interface shows one immediate throughout:

Imports in the run Veneer
17 ldr pc,[pc,#60]
1 ldr pc,[pc,#-4], the negative case the loader's sign test is there for

Negative controls

The negative controls are bytes changed in a real image:

  • corrupt the magic
  • raise the version past the ceiling
  • flip one guid byte
  • move the function count

Each one has to come back with the original's own refusal code.